Skip to content

prefect.cli.dashboard

open() async

Open the Prefect UI in the browser.

Source code in src/prefect/cli/dashboard.py
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
@dashboard_app.command()
async def open():
    """
    Open the Prefect UI in the browser.
    """

    if not (ui_url := PREFECT_UI_URL.value()):
        raise RuntimeError(
            "`PREFECT_UI_URL` must be set to the URL of a running Prefect server or Prefect Cloud workspace."
        )

    await run_sync_in_worker_thread(webbrowser.open_new_tab, ui_url)

    async with get_cloud_client() as client:
        try:
            current_workspace = get_current_workspace(await client.read_workspaces())
        except CloudUnauthorizedError:
            current_workspace = None

    destination = (
        f"{current_workspace.account_handle}/{current_workspace.workspace_handle}"
        if current_workspace
        else ui_url
    )

    exit_with_success(f"Opened {destination!r} in browser.")