<@ULVA73B9P> I am running flows from my client app...
# ask-marvin
r
@Marvin I am running flows from my client app using run_deployment API. Is it possible to retrieve flow_name after run_deployment returns ?
m
thought for 96.3 seconds
Yes — but not directly from the
FlowRun
object
that
run_deployment()
returns.
run_deployment()
returns a
FlowRun
, which includes
flow_id
, not
flow_name
. To get the flow name, read the flow by that ID. Example:
Copy code
python
from prefect.deployments import run_deployment
from prefect.client.orchestration import get_client

flow_run = run_deployment(
    name="my-flow/my-deployment",
    timeout=0,
)

with get_client(sync_client=True) as client:
    flow = client.read_flow(flow_run.flow_id)
    flow_name = flow.name

print(flow_name)
If you're in async code:
Copy code
python
from prefect.deployments import run_deployment
from prefect.client.orchestration import get_client

async def main():
    flow_run = await run_deployment(
        name="my-flow/my-deployment",
        timeout=0,
    )

    async with get_client() as client:
        flow = await client.read_flow(flow_run.flow_id)
        return flow.name
A few details: -
flow_run.name
= the flow run name -
flow_run.flow_id
= the underlying flow's ID -
flow.name
= the flow name you want So the short answer is: - No,
run_deployment()
does not return
flow_name
directly - Yes, you can retrieve it immediately afterward using
flow_run.flow_id
Relevant docs: - `run_deployment` API - Prefect client API If you want, I can also show you how to get the deployment name + flow name in one helper function.