<@ULVA73B9P> How to change flow instance names ?
# ask-marvin
r
@Marvin How to change flow instance names ?
m
thought for 265.7 seconds
Do you mean changing the name of a Prefect flow run (the “instance” of a flow)? If so, here are the main ways in Prefect 3.x: - At decoration time (template or callable) - Per-call override - When triggering a deployment - During/after the run via API - Manually in the UI Quick examples: 1) Set a name template on the flow (uses your flow parameters)
Copy code
from 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
Copy code
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
Copy code
custom_etl = etl.with_options(flow_run_name="adhoc-{table}")

custom_etl("events")  # name -> adhoc-events
4) When running a deployment - CLI:
Copy code
prefect deployment run "my-flow/my-deployment" --flow-run-name "backfill-2025-12-01"
- Python API:
Copy code
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:
Copy code
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:
Copy code
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.