<@ULVA73B9P> can you show me how to query the pref...
# ask-marvin
s
@Marvin can you show me how to query the prefect API to return all flows that are currently running. For example, using get_client().read_flow_runs()
m
It seems the example provided didn't specifically address the query to retrieve all flows that are currently running using
get_client().read_flow_runs()
. No worries though, I can guide you through the process in Python using Prefect's API. Here's a piece of code that should do just that:
Copy code
python
from prefect import get_client

async def get_running_flows():
    async with get_client() as client:
        # Assuming the state of running flows is "Running"
        flow_runs = await client.read_flow_runs(state="Running")
        return flow_runs

# Call the function and process results
import asyncio
running_flows = asyncio.run(get_running_flows())
for flow_run in running_flows:
    print(flow_run)
This code snippet: - Uses
get_client
from Prefect to establish a connection to the Prefect API. - Queries for flow runs with the state "Running" (this assumes that running flows are denoted by this state in your deployment). - Prints out the running flow runs. Please note, depending on the version of Prefect you are using and how your Prefect deployment is set up, you may need to adjust the state filter. Additionally, this code uses
asyncio
which is the asynchronous framework that modern Prefect relies on. You should run this in an environment where
asyncio
is supported. The documentation related to interacting with Prefect API can be found in the API reference section, however, keep in mind that you might need to search for the exact method or use the Python client API reference based on the version of Prefect you're using. Since I cannot retrieve the exact documentation link for the PREFECT API you requested, I would highly recommend checking the latest version of Prefect's documentation for more detailed and updated information.