Skip to main content
The 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:
Generate an SDK for specific deployments:
Combine multiple filters:

Run deployments with the generated SDK

The generated SDK provides a deployments.from_name() method that returns a typed deployment object:

Configure run options

Use with_options() to set tags, scheduling, and other run configuration:
Available options:
  • tags: Tags to apply to the flow run
  • idempotency_key: Unique key to prevent duplicate runs
  • work_queue_name: Override the work queue
  • as_subflow: Run as a subflow of the current flow
  • scheduled_time: Schedule the run for a future time
  • flow_run_name: Custom name for the flow run

Override job variables

Use with_infra() to override work pool job variables:
The available job variables depend on your work pool type. The generated SDK provides type hints for the options available on each deployment’s work pool.

Async usage

In an async context, use run_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
The generate command overwrites the existing file:
Add SDK regeneration to your CI/CD pipeline to keep it in sync with your deployments.

Further reading