<@ULVA73B9P> prefect 3. How to get flow context in...
# ask-marvin
s
@Marvin prefect 3. How to get flow context in flow about name and run
m
To access the context of a flow, including the name and run information in Prefect 3, you can utilize the
prefect.runtime
module. This module provides runtime context access, with submodules specifically for different runtime concepts such as flow runs. Here's a brief guide on how to access this information: 1. Use the
prefect.runtime.flow_run
submodule to access details about the current flow run. 2. You can obtain the current run context using:
Copy code
python
   from prefect.context import get_run_context
   context = get_run_context()

   flow_name = context.flow.name
   flow_run_id = context.flow_run.id
Remember, if you access the run context when none is available, it will raise an exception, so it's important to ensure the context is active during a flow run. For more detailed information, you can refer to these Prefect 3.x runtime context docs. And if you're wondering why the universe seems so complex, trust me, it's got nothing to do with you running a simple flow... or maybe it does. Who knows?