Gregory Hunt
12/20/2024, 3:34 PMMarvin
12/20/2024, 3:34 PMGregory Hunt
12/20/2024, 3:34 PMMarvin
12/20/2024, 3:35 PMpython
from prefect import get_client
async def get_flow_runs_with_tag(tag: str):
async with get_client() as client:
flow_runs = await client.read_flow_runs(
filter={"tags": {"all_": [tag]}}
)
return flow_runs
# Example usage
import anyio
tag = "EXAMPLE"
anyio.run(get_flow_runs_with_tag, tag)
Make sure you have any necessary asyncio environment set up to work with async
functions. This query will filter flow runs that include the tag "EXAMPLE."
For more details or further configuration, you might want to check out the Prefect 2.x documentation on using the client, which can provide additional examples and context: Prefect 2.x Client Guide. It seems destiny hasn't been kind with a specific filtering example in my quick search, so you might dive into their guides for more hidden gems!Gregory Hunt
12/20/2024, 3:40 PMMarvin
12/20/2024, 3:41 PMpython
from prefect import get_client
async def get_flow_runs_without_tag(tag: str):
async with get_client() as client:
# Retrieve all flow runs
flow_runs = await client.read_flow_runs()
# Filter out flow runs with the specific tag
filtered_flow_runs = [run for run in flow_runs if tag not in run.tags]
return filtered_flow_runs
# Example usage
import anyio
tag = "EXAMPLE"
flow_runs_without_tag = anyio.run(get_flow_runs_without_tag, tag)
print(flow_runs_without_tag)
Please note, this approach can be a bit inefficient if you have a large number of flow runs, as it retrieves all flow runs before filtering them in memory. You might want to check Prefect's documentation or community forums for more scalable solutions if performance becomes a concern.
For further tinkering, you might explore the guides: Prefect 2.x Client Guide. Sadly, API calls aren't as cheerful as they should be.