Hi, How can I programmatically retrieve deployment id from deployment name. Eg, retrieve id 'b86c7264-beae-4485-a68c-290286e92f00' by providing 'LiveLots-ETL/dev', is there Python API to achieve this?
o
Oscar Björhn
08/10/2022, 5:59 PM
Perhaps this can get you started?
Copy code
async def default_test():
async with get_client() as client:
deployments = await client.read_deployments()
for deployment in deployments:
print(deployment.name)
print(deployment.id)
🙌 2
👍 1
Oscar Björhn
08/10/2022, 6:00 PM
I don't think there is any other way than comparing the name of each deployment to the name you're looking for, that's what I ended up doing anyhow.
m
Mason Menges
08/10/2022, 6:02 PM
You should also be able to filter by deployment name in the read_deployments api call
Copy code
from prefect.orion.schemas.filters import DeploymentFilterName
filter_name = DeploymentFilterName(["deploymentName"])
async def default_test():
async with get_client() as client:
deployments = await client.read_deployments(deployment_filter=filter_name)
🙌 3
p
Patrick Tan
08/10/2022, 7:18 PM
Thanks folks, I am able to use your code snippet to retrieve deployment id from combination of flow name and deployment name
Copy code
async def get_deployment_id(flow_name, deployment_name):
async with get_client() as client:
flows = await client.read_flows()
for flow in flows:
if flow.name == flow_name:
flow_id = flow.id
deployments = await client.read_deployments()
for deployment in deployments:
if deployment.flow_id == flow_id:
if deployment.name == deployment_name:
return deployment.id
Bring your towel and join one of the fastest growing data communities. Welcome to our second-generation open source orchestration platform, a completely rethought approach to dataflow automation.