Kevin Hu
08/25/2025, 4:45 PMMarvin
08/25/2025, 4:45 PMNate
08/25/2025, 4:45 PMMarvin
08/25/2025, 4:52 PMprefect.yaml
is a project-side config you author and version-control.
Options you can use today:
- Snapshot details via CLI and convert to YAML
- prefect deployment inspect
will print the deployment model as a Python dict. You can pipe it through a tiny Python one-liner to turn it into YAML:
prefect deployment inspect "flow-name/deployment-name" | python - <<'PY'
import sys, ast, yaml
print(yaml.safe_dump(ast.literal_eval(sys.stdin.read()), sort_keys=False))
PY
Note: this gives you the server’s deployment fields, not a ready-to-run prefect.yaml
.
- Programmatically export with the Prefect client
- This is a clean way to dump one or many deployments to YAML:
import asyncio, yaml
from prefect.client.orchestration import get_client
async def export_deployment(name: str, out_path: str):
async with get_client() as client:
dep = await client.read_deployment_by_name(name) # "flow/deployment"
data = dep.model_dump() # pydantic model -> dict
with open(out_path, "w") as f:
yaml.safe_dump(data, f, sort_keys=False)
asyncio.run(export_deployment("flow-name/deployment-name", "deployment.yaml"))
You can iterate client.read_deployments()
similarly if you want to dump them all.
Important caveat
- The exported YAML above reflects the deployment object stored in Prefect, which is not the same schema as a prefect.yaml
. If your end goal is “manage deployments as code,” you’ll want to author a prefect.yaml
and use prefect deploy
. See the guide: prefect.yaml in Prefect 3.x.
If you share your goal (e.g., backup vs. generating a prefect.yaml
for a repo), I can help map the fields or draft a prefect.yaml
that mirrors your current deployment(s).