Stefan
08/01/2025, 7:56 AMMarvin
08/01/2025, 7:56 AMMarvin
08/01/2025, 7:56 AMpython
from prefect import flow, get_client
@flow
async def my_flow():
# Get the current client
client = get_client()
# Get the current flow run ID from the context
from prefect.context import get_flow_run_context
context = get_flow_run_context()
flow_run_id = context.flow_run.id
# Update the flow run name
await client.update_flow_run(
flow_run_id=flow_run_id,
name="New Flow Run Name"
)
If you're using synchronous flows, you can use the synchronous version:
python
from prefect import flow, get_client
@flow
def my_flow():
client = get_client()
context = get_flow_run_context()
flow_run_id = context.flow_run.id
client.update_flow_run(
flow_run_id=flow_run_id,
name="New Flow Run Name"
)
A few important notes:
1. The name update will be reflected in the UI and any subsequent queries for the flow run
2. You can make the new name dynamic based on any runtime information or parameters
3. The change is permanent and will be stored in Prefect's database
You can also set a dynamic name when creating the flow using the flow_run_name
parameter, which might be more appropriate depending on your use case:
python
@flow(flow_run_name=lambda parameters: f"my-flow-{parameters['value']}")
def my_flow(value: str):
pass
This approach sets the name at the start of the flow run based on input parameters, which might be preferable to updating it during execution.