<@ULVA73B9P> I am trying to use Prefect SDK (v2) t...
# marvin-ai
p
@Marvin I am trying to use Prefect SDK (v2) to get status of a flow run using its UUID. How can I achieve this?
m
To get the status of a flow run using its UUID in Prefect 2.x, you'll want to use the
PrefectClient
from the
prefect.client.orchestration
module. This client allows you to interact with the Prefect API to retrieve details about flow runs, including their status. Here's a basic approach to achieve this: 1. Import the necessary module:
Copy code
python
   from prefect.client.orchestration import get_client
2. Use the client to fetch the flow run status:
Copy code
python
   import asyncio

   async def get_flow_run_status(flow_run_id):
       async with get_client() as client:
           flow_run = await client.read_flow_run(flow_run_id)
           return flow_run.state.name

   # Example usage
   flow_run_id = "your-flow-run-uuid"
   status = asyncio.run(get_flow_run_status(flow_run_id))
   print(f"Flow run status: {status}")
This code snippet sets up an asynchronous function to get the flow run status using its UUID. Make sure to replace
"your-flow-run-uuid"
with the actual UUID of your flow run. For more information, you can explore the Prefect 2.x documentation or the Prefect Client module documentation.