Adri
10/25/2024, 10:05 AMMarvin
10/25/2024, 10:05 AMAdri
10/25/2024, 10:05 AMMarvin
10/25/2024, 10:05 AMprefect.context
module. Here's how you can access the flow run context and print the flow ID:
python
from prefect import flow
from prefect.context import FlowRunContext
@flow
def my_flow():
# Access the flow run context
flow_run_context = FlowRunContext.get()
# Get the flow ID from the context
flow_id = flow_run_context.flow_run.id
# Print the flow ID
print(f"The Flow ID is: {flow_id}")
if __name__ == "__main__":
my_flow()
In this example, the FlowRunContext.get()
method is used to retrieve the current flow run context, from which you can then access the flow_run.id
to print the flow ID.
For more details on using Prefect's runtime context, you can refer to the Prefect 3.x documentation on runtime context.