<@ULVA73B9P> In the Python SDK, how do I run deplo...
# ask-marvin
n
@Marvin In the Python SDK, how do I run deploy on multiple flows at the same time to Prefect Cloud?
m
thought for 213.3 seconds
Yes—use the Prefect 3 Python SDK’s batch deploy helper. You can pass multiple RunnerDeployment objects to
prefect.deployments.deploy(...)
and it will create/update all of them in your Prefect Cloud workspace in one call. Example:
Copy code
from prefect.deployments import deploy
from prefect.deployments.runner import RunnerDeployment

deploy(
    # First flow
    RunnerDeployment(
        name="etl",
        entrypoint="flows/etl.py:etl",
        tags=["prod"],
        parameters={"days_back": 1},
    ),
    # Second flow
    RunnerDeployment(
        name="reporting",
        entrypoint="flows/reporting.py:reporting",
        tags=["prod"],
    ),
    # Defaults applied to all unless overridden on a RunnerDeployment
    work_pool_name="kubernetes-pool",
    image="<http://ghcr.io/my-org/my-image:latest|ghcr.io/my-org/my-image:latest>",
    build=True,   # build the image
    push=True,    # push the image
)
Notes: - Each
RunnerDeployment
can override settings like
work_pool_name
,
parameters
,
tags
, and
schedules
. - The top-level
work_pool_name
,
image
,
build
, and
push
apply to all deployments unless overridden. - Make sure your environment is authenticated to Prefect Cloud (e.g., via
prefect cloud login
or environment variables) before running this. Docs: - Deploy via Python (multiple deployments) - Create deployments with the SDK If you prefer using flows directly, you can also do:
Copy code
from prefect import flow

flow_a = flow.from_source("<https://github.com/my-org/my-repo>", "flows/a.py:flow_a")
flow_b = flow.from_source("<https://github.com/my-org/my-repo>", "flows/b.py:flow_b")

flow_a.deploy("flow-a", work_pool_name="kubernetes-pool")
flow_b.deploy("flow-b", work_pool_name="kubernetes-pool")
…but the batch helper above is the simplest way to “do them all at once.”