<@ULVA73B9P> can you give me an example function t...
# ask-marvin
l
@Marvin can you give me an example function to get specific deployment via name?
m
thought for 39.9 seconds
Here are minimal examples for Prefect 3.x. Async (recommended in most apps):
Copy code
from prefect.client.orchestration import get_client

# name must be "flow_name/deployment_name", e.g., "etl-flow/prod"
async def get_deployment_by_name(name: str):
    async with get_client() as client:
        return await client.read_deployment_by_name(name)

# Convenience wrapper if you have names separately
async def get_deployment(flow_name: str, deployment_name: str):
    return await get_deployment_by_name(f"{flow_name}/{deployment_name}")
Sync version:
Copy code
from prefect.client.orchestration import SyncPrefectClient

def get_deployment_by_name_sync(name: str):
    with SyncPrefectClient() as client:
        return client.read_deployment_by_name(name)
Usage example:
Copy code
deployment = await get_deployment_by_name("my-flow/prod")
print(deployment.id, deployment.name)
If you’d prefer a version that handles “not found” more gracefully, I can add try/except around the call—just say the behavior you want.
l
Can you give me the link @Marvin of the docs for this?
m
thought for 56.3 seconds
Here you go: - REST API endpoint: Read deployment by name - Deployments API overview: Deployments API In Prefect 3.x, the Python client’s
read_deployment_by_name("flow_name/deployment_name")
maps to that REST endpoint.