prefect sdk generate command creates a typed Python file from your deployments. This gives you IDE autocomplete and static type checking when triggering deployment runs programmatically.
This feature is in beta. APIs may change in future releases.
Prerequisites
- An active Prefect API connection (Prefect Cloud or self-hosted server)
- At least one deployment in your workspace
Generate an SDK from the CLI
Generate a typed SDK for all deployments in your workspace:Filter to specific flows or deployments
Generate an SDK for specific flows:Run deployments with the generated SDK
The generated SDK provides adeployments.from_name() method that returns a typed deployment object:
Configure run options
Usewith_options() to set tags, scheduling, and other run configuration:
tags: Tags to apply to the flow runidempotency_key: Unique key to prevent duplicate runswork_queue_name: Override the work queueas_subflow: Run as a subflow of the current flowscheduled_time: Schedule the run for a future timeflow_run_name: Custom name for the flow run
Override job variables
Usewith_infra() to override work pool job variables:
Async usage
In an async context, userun_async():
Chain methods together
Regenerate the SDK after changes
The SDK is generated from server-side metadata. Regenerate it when:- Deployments are added, removed, or renamed
- Flow parameter schemas change
- Work pool job variable schemas change
generate command overwrites the existing file: