Skip to main content
Question

Retrieving the YAML code for knowledge models using Pycelonis in MLWB

  • June 17, 2026
  • 1 reply
  • 223 views

Pratheeksha
Level 4
Forum|alt.badge.img

Hey Everyone, 

I can connect to a knowledge model and pull the data within into the MLWB using pycelonis. 

But can we retrieve the knowledge model YAML code and store it in MLWB? 

Please help me with this concern if there is a way. 

1 reply

Harshit Jain
Celonaut
Forum|alt.badge.img

Hi Pratheeksha,

Yes we can retrieve the YAML Code in MLWB

Use this code:

# ── Retrieve a Knowledge Model's YAML and save it in MLWB ──────────────
from pycelonis import get_celonis

celonis = get_celonis()          # uses MLWB env vars automatically

PACKAGE_KEY = "<your_package_key>"   # the Studio package holding the KM

# 1. List the nodes (assets) in the package via the package-manager API
resp = celonis.client.get(
    f"{celonis.url}/package-manager/api/packages/{PACKAGE_KEY}/nodes"
)

# 2. Inspect the structure once so you know the field names
print(resp)

# 3. Pull the KM node's serialized YAML body and write it to disk
for node in resp:
    if node.get("assetType") == "KNOWLEDGE_MODEL":   # adjust if type differs
        yaml_text = node.get("serializedContent", "")
        fname = f"{node.get('key', 'knowledge_model')}.yml"
        with open(fname, "w") as f:
            f.write(yaml_text)
        print(f"Saved: {fname}")


Let me know if you need more support.

Regards
Harshit Jain​​​​​​​