<@ULVA73B9P> Is there a function that is the oppos...
# ask-marvin
j
@Marvin Is there a function that is the opposite of
prefect deploy
so instead of turning a prefect.yaml file into a deployment, it connects to prefect and outputs a deployment config as yaml ?
m
thought for 278.4 seconds
n
there is not although there's very likely an open issue for this
definitely heard this ask before
j
Thanks!
m
Short answer: Not exactly. There isn’t a built-in “reverse” of
prefect 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
Copy code
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.
n
there wasn't one exactly