<@ULVA73B9P> how can i get the url link to a flow ...
# marvin-in-the-wild
t
@Marvin how can i get the url link to a flow run on the UI programatically from a flow run context?
m
It seems that the Prefect documentation does not directly provide a method to get the URL link to a flow run on the UI programmatically from a flow run context. However, typically the UI link of a flow run is constructed using a predictable pattern that includes the flow run ID which you can access from within the runtime context. Here's a general idea of how you might construct the URL for a flow run programmatically if you know your Prefect Cloud or Prefect Server base URL and you have the flow run ID from the runtime context:
Copy code
python
from prefect import context

# Assuming you have the base URL of your Prefect UI
prefect_ui_base_url = "<https://cloud.prefect.io/your-workspace-slug>"
# Fetch the flow run ID from the context
flow_run_id = context.get("flow_run_id")

# Construct the URL to the flow run in the UI
flow_run_ui_url = f"{prefect_ui_base_url}/flow-run/{flow_run_id}"
However, you should keep in mind the structure of the URL might differ based on your specific Prefect setup or version. To find out the exact method for your Prefect version, I can suggest looking into the GitHub issues or seeking clarification from the Prefect community. Would you like me to search GitHub issues for more information on this topic?
k
@Tom Matthews you can get the url from the runtime
Copy code
from prefect import flow, runtime

@flow(log_prints=True)
def foo():
   print(runtime.flow_run.api_url)
   print(runtime.flow_run.ui_url)

foo()
t
Thanks!!