Hey there, was wondering if there is a REST API me...
# ask-community
r
Hey there, was wondering if there is a REST API method in Prefect 2 to retrieve a flow's tasks names by flow name? either from a flow's Deployment or Flow objects (not from flow run)?
n
hey @Ron Levi - yes! this sounds like POST /task_runs/filter, providing a deployment or flow run filter to narrow down the query
there’s a client method read_task_runs you can use for this, @Marvin can you show a sample use of the read_task_runs method?
m
You can use the
read_task_runs
method from the
Prefect
client to fetch details about task runs. Below is an example that demonstrates how to use this method:
Copy code
from prefect.client import OrionClient

async def get_task_runs():
    async with OrionClient() as client:
        task_runs = await client.read_task_runs()
        for task_run in task_runs:
            print(task_run)
            
# Make sure to run this in an async environment.
import asyncio
asyncio.run(get_task_runs())
This script sets up an async function
get_task_runs
that establishes a connection to the Prefect Orion API client and fetches task runs using the
read_task_runs
method. The details of each task run are then printed to the console. For more detailed examples of Prefect tasks, check out this sample code: Prefect Code Example
n
if you swap OrionClient for get_client then that’s right but it’ll give all of them, you’ll want to pass a filter something like this
🙌 1