https://prefect.io logo
j

James Zhang

12/22/2022, 10:14 AM
hi everyone, just a quick question, how can i get the current flow run name programmatically using python during the run? couldn’t find the doc atm…
1
j

Justin Trautmann

12/22/2022, 2:11 PM
hey James, maybe
Copy code
from prefect.context import get_run_context
get_run_context().flow_run.name
could help
j

James Zhang

12/22/2022, 2:50 PM
thanks for the reply! just tried it, it seems
get_run_context()
just gives me a Task Context because I called it under a Task… can I get the Flow Run name inside of a Task?
j

Justin Trautmann

12/22/2022, 3:33 PM
take a look into the get_run_context implementation. it returns the FlowRunContext or TaskRunContext depending on from where it is called. i'm not sure if the flow run context is available from within a task but you could try getting it directly via
FlowRunContext.get()
wit FlowRunContext imported from prefect.context
ahh. see the docstring of FlowRunContext:
Data in this context is only available from within a flow run function.
This sounds to me like this is only available directly inside the flow function. what about getting the name in the flow and passing it on to the tasks?
j

James Zhang

12/22/2022, 3:40 PM
hmm.. yeah seems to be the only way! thx