<@ULVA73B9P> is there a way to export existing dep...
# ask-marvin
k
@Marvin is there a way to export existing deployments to a yaml file?
m
thought for 413.1 seconds
n
no, but there should be i think
m
Short answer: not directly. In Prefect 3.x there isn’t a built-in command to “export a deployment to prefect.yaml”. The server/Cloud stores the resolved deployment model, while
prefect.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:
Copy code
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:
Copy code
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).