<@ULVA73B9P> Can I get the flow run url when using...
# ask-marvin
f
@Marvin Can I get the flow run url when using prefect cloud at runtime in a python script?
m
thought for 118.0 seconds
Yes. In Prefect 3.x you can get it at runtime via
prefect.runtime.flow_run.ui_url
. Example:
Copy code
from prefect import flow, runtime, get_run_logger

@flow
def my_flow():
    logger = get_run_logger()
    <http://logger.info|logger.info>(f"Flow run UI: {runtime.flow_run.ui_url}")
    # Also available if you want the API URL or ID:
    <http://logger.info|logger.info>(f"Flow run API: {runtime.flow_run.api_url}")
    <http://logger.info|logger.info>(f"Flow run ID: {runtime.flow_run.id}")

if __name__ == "__main__":
    my_flow()
Notes: -
runtime.flow_run.ui_url
returns the human-friendly URL to this run in Prefect Cloud. - These values are only populated when code is running inside an actual flow run; otherwise they may be empty/None. Docs: prefect.runtime.flow_run If you’re on Prefect 2.x instead, let me know and I’ll share the equivalent approach.