Matt Alhonte
10/07/2023, 12:55 AM<http://prefect.cli.deployment.ls|prefect.cli.deployment.ls>Marvin
10/07/2023, 12:55 AMpython
from prefect.cli.deployment import ls
# Query deployments
deployments = ls()
# Print deployment details
for deployment in deployments:
    print(deployment)Matt Alhonte
10/07/2023, 12:56 AMTypeError: 'coroutine' object is not iterableMarvin
10/07/2023, 12:56 AMawaitpython
import asyncio
from prefect.cli.deployment import ls
# Define an async function to query deployments
async def query_deployments():
    deployments = await ls()
    # Print deployment details
    for deployment in deployments:
        print(deployment)
# Run the async function
asyncio.run(query_deployments())Matt Alhonte
10/07/2023, 12:58 AMRuntimeError: asyncio.run() cannot be called from a running event loopMarvin
10/07/2023, 12:58 AMpython
import asyncio
from prefect.cli.deployment import ls
# Define an async function to query deployments
async def query_deployments():
    deployments = await ls()
    # Print deployment details
    for deployment in deployments:
        print(deployment)
# Get the current event loop
loop = asyncio.get_event_loop()
# Run the async function in the existing event loop
loop.run_until_complete(query_deployments())asyncio.get_event_loop()run_until_complete()Matt Alhonte
10/07/2023, 1:00 AMasyncMarvin
10/07/2023, 1:00 AMasyncrequestspython
import requests
# Set the Prefect API URL
api_url = "<https://api.prefect.io/graphql>"
# Set your Prefect API token
api_token = "YOUR_PREFECT_API_TOKEN"
# Set the query to get deployments for a specific flow
query = """
{
  flow(where: {name: {_eq: "YOUR_FLOW_NAME"}}) {
    deployments {
      name
    }
  }
}
"""
# Set the headers for the request
headers = {
  "Authorization": f"Bearer {api_token}",
  "Content-Type": "application/json"
}
# Send the request to the Prefect API
response = <http://requests.post|requests.post>(api_url, json={"query": query}, headers=headers)
# Print the response
print(response.json())"YOUR_PREFECT_API_TOKEN""YOUR_FLOW_NAME"requests