Robert Szomolanyi
12/02/2025, 2:23 PMMarvin
12/02/2025, 2:23 PMMarvin
12/02/2025, 2:28 PMfrom prefect import flow
@flow(flow_run_name="etl-{table}-{run_date}")
def etl(table: str, run_date: str):
...
etl("users", "2025-12-01") # name -> etl-users-2025-12-01
- The template can reference your flow’s parameters by name, e.g. {param} or with format specs like {run_date:%Y-%m-%d} if the param is a datetime.
2) Use a callable for dynamic names
from datetime import datetime, timezone
from prefect import flow
def make_name():
return f"daily-run-{datetime.now(timezone.utc):%Y%m%d}"
@flow(flow_run_name=make_name)
def my_flow():
...
- Callable takes no args and must return a string.
3) Override per call with with_options
custom_etl = etl.with_options(flow_run_name="adhoc-{table}")
custom_etl("events") # name -> adhoc-events
4) When running a deployment
- CLI:
prefect deployment run "my-flow/my-deployment" --flow-run-name "backfill-2025-12-01"
- Python API:
from prefect.deployments.flow_runs import run_deployment
run_deployment(
"my-flow/my-deployment",
flow_run_name="backfill-2025-12-01",
parameters={"date": "2025-12-01"}
)
5) Change the name during/after the run (API)
- Async flow:
from prefect import flow
from prefect.client.orchestration import get_client
from prefect.runtime import flow_run
@flow
async def rename_me():
async with get_client() as client:
await client.set_flow_run_name(flow_run.id, "renamed-mid-run")
- Sync flow:
from prefect import flow
from prefect.client.orchestration import SyncPrefectClient
from prefect.runtime import flow_run
@flow
def rename_sync():
with SyncPrefectClient() as client:
client.set_flow_run_name(flow_run.id, "renamed-mid-run")
6) UI
- Open the run in the Prefect UI and click the name to edit it.
Notes and limitations
- The flow_run_name kwarg on @flow is supported in Prefect 3.x.
- Name templates only have access to flow function parameters.
- Callable flow_run_name must be zero-arg and return a string.
- If you set flow_run_name on the decorator, it’s applied when the run starts (the server may show a temporary name until the flow begins).
Docs
- Flow decorator (params & flow_run_name): prefect.flow
- Runtime info (flow_run.id/name): prefect.runtime.flow_run
- Update name via client: PrefectClient.set_flow_run_name
- Trigger a deployment programmatically: run_deployment
- CLI: prefect deployment run
If you meant something else by “instance name” (e.g., deployment name or flow function name), let me know and I’ll tailor the steps.