<@ULVA73B9P> How to easily fetch flow name and dep...
# ask-marvin
p
@Marvin How to easily fetch flow name and deployment name from flow run id or FlowRun object for the completed flows?
m
To fetch the flow name from a flow run ID, you can utilize the Prefect Runtime module which provides access to the current flow run metadata. Here's an example of how you could generate the flow run name from within the flow using information like the flow name and parameters:
Copy code
python
from prefect import flow
from prefect.runtime import flow_run

@flow
def my_flow(name: str, limit: int = 100):
    pass  # Your flow logic here

def generate_flow_run_name():
    flow_name = flow_run.flow_name  # Retrieve the flow name
    parameters = flow_run.parameters
    name = parameters["name"]
    limit = parameters["limit"]
    return f"{flow_name}-with-{name}-and-{limit}"

my_flow(flow_run_name=generate_flow_run_name)
For deployment name, the documentation suggests that when a flow is run without a deployment, it will log "I belong to deployment None". If it is run as part of a deployment, it should log the name of the deployment instead. The runtime context will return an empty value when information is not available. See the Runtime Context documentation for more details and the full list of available attributes. However, if you are looking to fetch these details for already completed flows, you would typically use the Prefect client within your Python code to query the Prefect API for this metadata. Unfortunately, the specific documentation or code examples for fetching these details post-run weren't directly found in this search. For more precise code examples, I would recommend looking into the Prefect Client documentation or contacting Prefect support.