<@ULVA73B9P> is there a way to group deployments b...
# ask-marvin
r
@Marvin is there a way to group deployments by common name? i have a parent child setup wherin there is a parent deployment which can call n different child deployments
m
thought for 403.1 seconds
Short answer: yes—use deployment tags and/or a naming convention. Options in Prefect 3.x: - Tags (recommended): Assign a common tag to all “child” deployments (e.g.,
children
or
group:alpha
). The UI can filter by tags, and you can query by tag from a parent flow before calling them. - Naming convention: Use a prefix or namespace in deployment names, e.g.
etl/child-foo
,
etl/child-bar
. Handy for humans and for pattern-based selection when deploying from
prefect.yaml
, but API lookups by tag are cleaner. How to tag deployments - Code-based deploy:
Copy code
from prefect import flow

@flow
def child_a(): ...
@flow
def child_b(): ...

child_a.deploy(name="etl/child-a", work_pool_name="...", tags=["children", "group:etl"])
child_b.deploy(name="etl/child-b", work_pool_name="...", tags=["children", "group:etl"])
- YAML-based deploy (excerpt):
Copy code
deployments:
  - name: etl/child-a
    entrypoint: child_a.py:child_a
    tags: ["children", "group:etl"]
  - name: etl/child-b
    entrypoint: child_b.py:child_b
    tags: ["children", "group:etl"]
Triggering N children from a parent - Query deployments by tag, then call each with
run_deployment
. Example (async parent for simplicity):
Copy code
from prefect import flow
from prefect.deployments import run_deployment
from prefect.client.orchestration import get_client
from prefect.client.schemas.filters import DeploymentFilter, DeploymentFilterTags

@flow
async def parent():
    async with get_client() as client:
        deployments = await client.read_deployments(
            deployment_filter=DeploymentFilter(
                tags=DeploymentFilterTags(any_=["children"])
            )
        )

    for d in deployments:
        # full name is "<flow_name>/<deployment_name>"
        await run_deployment(
            name=f"{d.flow_name}/{d.name}",
            parameters={"foo": "bar"},
            as_subflow=True,         # keeps lineage to the parent
            tags=["launched-by-parent"]  # tags on the created flow runs
        )
Notes and niceties: - CLI:
prefect deployment ls
can filter by
--flow-name
but not by tag. For tags, use the UI or the Python client. -
prefect deploy --name
accepts patterns to select which deployments from
prefect.yaml
to deploy (e.g.,
--name "etl/*"
). - If you really prefer names over tags, you can fetch deployments and filter
d.name.startswith("child-")
in Python, but tags are what they were invented for. Docs, in case you like proof: - Deployments concepts: Docs – Deployments -
prefect.yaml
guide: Docs – prefect.yaml If you tell me whether you care more about UI grouping or programmatic selection, I can tailor the example further. Either way, your parent can easily wrangle its unruly children—lucky it.