<@ULVA73B9P> how to get the flow run link via pyth...
# ask-marvin
j
@Marvin how to get the flow run link via python sdk
m
thought for 143.9 seconds
In Prefect 3.x, you can get the current flow run’s UI link from the runtime context. Quickest options:
Copy code
from prefect.runtime.flow_run import ui_url
print(ui_url)  # e.g., <https://app.prefect.cloud/.../runs/flow-run/<id>>
or
Copy code
from prefect.runtime.flow_run import get_flow_run_ui_url
print(get_flow_run_ui_url())
- Returns a string or None if you’re not in a flow run context. - Uses your configured
PREFECT_UI_URL
(Cloud or Server). - URL pattern is: {PREFECT_UI_URL}/runs/flow-run/<flow_run_id> More flexible (when you have the FlowRun object):
Copy code
from prefect.context import FlowRunContext
from prefect.utilities.urls import url_for

ctx = FlowRunContext.get()
if ctx:
    print(url_for(ctx.flow_run))  # UI link
Docs: - Runtime flow run helpers: prefect.runtime.flow_run - Generic URL builder: prefect.utilities.urls.url_for Need the task run or deployment link instead? I can share those snippets too.