Janet Carson
12/11/2025, 11:08 PMprefect deploy so instead of turning a prefect.yaml file into a deployment, it connects to prefect and outputs a deployment config as yaml ?Marvin
12/11/2025, 11:08 PMNate
12/11/2025, 11:09 PMNate
12/11/2025, 11:09 PMJanet Carson
12/11/2025, 11:09 PMMarvin
12/11/2025, 11:13 PMprefect deploy that exports an existing server-side deployment back into a prefect.yaml. In Prefect 3.x, prefect.yaml is a project/deploy recipe, while a deployment on the server is the resulting state—those aren’t perfectly reversible.
What you can do:
- Inspect what’s on the server: prefect deployment inspect "flow-name/deployment-name" (prints a detailed representation you can redirect to a file).
- Programmatically fetch and serialize a deployment to YAML/JSON for auditing or replication.
Example: export a deployment to YAML via the API
import asyncio
import yaml
from prefect.client.orchestration import get_client
async def export_deployment_to_yaml(name: str, outfile: str):
async with get_client() as client:
dep = await client.read_deployment_by_name(name)
data = dep.model_dump(mode="json", exclude_none=True)
with open(outfile, "w") as f:
yaml.safe_dump(data, f, sort_keys=False)
# Usage
# asyncio.run(export_deployment_to_yaml("my-flow/my-deployment", "deployment.yaml"))
Notes:
- The YAML you get this way represents the server-side deployment state, not a prefect.yaml project recipe. It won’t include project-level build/push/pull steps or other scaffolding that lives only in your repo config.
- If your goal is to scaffold a new project file, use prefect init to generate a new prefect.yaml, then fill in fields using details from inspect or the API dump.Nate
12/11/2025, 11:16 PMNate
12/11/2025, 11:16 PM