Learn how to use the Python SDK to deploy flows to run in work pools.
prefect.yaml
file, you can use the Python SDK to create deployments with dynamic infrastructure.
This can be more flexible if you have to programmatically gather configuration at deployment time.
flow.deploy
instead of flow.serve
flow.serve
method is one simple way to create a deployment with the Python SDK. It’s ideal when you have readily available, static infrastructure for your flow runs and you don’t need the dynamic dispatch of infrastructure per flow run offered by work pools.
However, you might want to consider using flow.deploy
to associate your flow with a work pool that enables dynamic dispatch of infrastructure per flow run for the following reasons:
flow.deploy
, ensure you have the following:
prefect server start
. To use Prefect Cloud, sign up for an account at app.prefect.cloud
and follow the Connect to Prefect Cloud guide.
flow.deploy
.
flow.deploy
flow.deploy
and Docker, follow these steps:
Write a flow
Add deployment configuration
flow.deploy
to tell Prefect how to deploy your flow.Deploy!
push=False
to skip pushing the image to a registry. This is useful for local development, and you can push your image to a registry such as Docker Hub in a production environment.
dockerfile
parameter to flow.deploy
.interval
Defines the interval at which the flow should run. Accepts an integer or float value representing the number of seconds between runs or a datetime.timedelta
object.
cron
Defines when a flow should run using a cron string.
rrule
Defines a complex schedule using an rrule
string.
schedules
Defines multiple schedules for a deployment. This option provides flexibility for:
flow.from_source
to first load your flow code from a remote location.
Here’s an example of loading a flow from a Git repository and deploying it:
source
parameter can accept a variety of remote storage options including:
s3://
scheme)gs://
scheme)az://
scheme)entrypoint
parameter is the path to the flow function within your repository combined with the name of the flow function.
Learn more about remote code storage here.
parameters
keyword argument in flow.deploy
.
job_variables
keyword argument in flow.deploy
.
The job variables provided will override the values set on the work pool.
deploy
function.