Philipp
11/17/2025, 3:14 PMMarvin
11/17/2025, 3:14 PMMarvin
11/17/2025, 3:21 PMfrom prefect import flow, get_run_logger
@flow
def child(x: int) -> int:
log = get_run_logger()
<http://log.info|log.info>(f"Child got {x}")
return x * 2
@flow
def parent():
result = child(21) # tracked as a subflow in the UI
return result
if __name__ == "__main__":
parent()
2) Trigger a deployed flow as a subflow (separate infrastructure)
- The child runs as its own flow run on a worker (can use different resources/pools)
- By default, it’s linked as a child run in the UI (as_subflow=True)
- You pass parameters via a dict
from prefect import flow
from prefect.deployments.flow_runs import run_deployment
@flow
def parent():
# Assumes you've created a deployment for the child flow, e.g. "child-flow/prod"
child_run = run_deployment(
name="child-flow/prod",
parameters={"x": 21},
as_subflow=True, # keep parent/child linkage in the UI
flow_run_name="child-subrun",
)
# child_run contains details including the final state
return child_run.state
Notes
- Direct calls (option 1) use the parent’s task runner and run in the same process.
- Deployment-based subflows (option 2) run on worker infrastructure; you can control concurrency via deployment settings and concurrency limits.
- Both approaches show the parent/child relationship in the UI when as_subflow=True (default for run_deployment).
Docs to dig deeper:
- Run deployments (run_deployment)
- Deployments concept
- Workflow design patterns (overview and when to use each pattern)
Quick check: Do you want the subflow to run in the same process (simpler) or on separate infrastructure via a deployment (more isolation/scalability)?