Slackbot
04/25/2024, 7:35 AMMarvin
04/25/2024, 7:35 AMpython
import asyncio
from datetime import datetime, timezone
from prefect import get_client
from prefect.client import FlowRunFilter, DeploymentFilter
from prefect.orion.schemas.sorting import FlowRunSort
async with get_client() as client:
flow_runs = await client.read_flow_runs(
flow_run_filter=FlowRunFilter(),
deployment_filter=DeploymentFilter(
id='your-deployment-id'
),
sort=FlowRunSort.START_TIME_DESC,
limit=10 # Adjust the limit as needed
)
print(flow_runs)
For further details, you'll want to refer to the DeploymentFilter
and FlowRunFilter
classes in the filters API reference for more ways to filter flow runs and other objects in your Prefect ecosystem.
Make sure to replace 'your-deployment-id'
with the actual deployment ID of the flow you're interested in. You can modify the FlowRunFilter
to include more specific filtering based on your needs, such as time frame, state, etc.
If you still need to use the REST API directly, the Python client examples above can guide you to structure your REST API requests similarly, as the GraphQL queries made by the Python client would be analogous to the REST API calls.Marvin
04/25/2024, 7:39 AMpython
import requests
import json
account_id = 'your-account-id'
workspace_id = 'your-workspace-id'
deployment_id = 'your-deployment-id'
prefect_token = 'your-prefect-token'
# Endpoint to get flow runs associated with a specific flow or deployment
# This URL will likely change depending on your Prefect version and precise needs
url = f"<https://api.prefect.cloud/api/accounts/{account_id}/workspaces/{workspace_id}/deployments/{deployment_id}/flow_runs>"
# Headers with authorization token
headers = {"Authorization": f"Bearer {prefect_token}"}
# Make a GET request to the API
response = requests.get(url=url, headers=headers)
# Parse the response JSON to get flow runs
flow_runs = json.loads(response.text)
# Example processing of flow_runs
for flow_run in flow_runs:
print(flow_run['id'], flow_run['name'])
Please replace your-account-id
, your-workspace-id
, your-deployment-id
, and your-prefect-token
with your actual Prefect account, workspace, and deployment IDs, and your Prefect Cloud access token.
Keep in mind that Prefect's REST API documentation may provide more accurate and detailed endpoints with the necessary parameters for filtering and sorting the flow runs. I would recommend checking the latest Prefect documentation or contacting Prefect support for the most up-to-date information on the REST API endpoints.