<@ULVA73B9P> how to retrieve flow name (not deploy...
# ask-marvin
f
@Marvin how to retrieve flow name (not deployment name or flow id, but the flow name) of a flow during execution?
m
thought for 107.0 seconds
In Prefect 2.x, you can get the Flow’s name during execution in either of these ways: - Easiest (works in both flows and tasks):
Copy code
from prefect import flow, runtime

@flow
def my_flow():
    print(runtime.flow_run.flow_name)  # <-- the Flow object's name

my_flow()
- Via the run context (inside a flow):
Copy code
from prefect import flow
from prefect.context import get_run_context

@flow
def my_flow():
    ctx = get_run_context()
    print(ctx.flow.name)

my_flow()
Note:
runtime.flow_run.name
is the flow run name (e.g., “solid-gibbon”), while
runtime.flow_run.flow_name
is the Flow object’s name you’re asking for.