https://prefect.io logo
m

Malavika S Menon

09/27/2022, 7:26 AM
How do I access the attributes of the class Flow inside the actual code for the flow I have created? For example,
Copy code
@flow
def random_flow():
   id = Flow.flow_id
   return 1
How do I access any member say flow_id inside the flow, when it is being run?
1
j

jpuris

09/27/2022, 8:50 AM
I believe you are looking for flow’s context.
Copy code
from prefect import flow, context

@flow(name="my_flow")
def my_flow() -> None:
    flow_context = context.get_run_context()
    print(flow_context.flow_run.id)

my_flow()
Copy code
10:48:57.418 | INFO    | prefect.engine - Created flow run 'tomato-walrus' for flow 'my_flow'
5f6decca-37d4-47c5-82a2-efddec52f630
10:48:58.819 | INFO    | Flow run 'tomato-walrus' - Finished in state Completed()
m

Malavika S Menon

09/27/2022, 9:37 AM
Yup thank you!