Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion burr/tracking/server/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,17 @@ async def lifespan(app: FastAPI):
await backend.lifespan(app).__anext__()


app = FastAPI(lifespan=lifespan)
def create_burr_ui_app() -> FastAPI:
return FastAPI(lifespan=lifespan)

app = create_burr_ui_app()

def mount_burr_ui(parent_app: FastAPI, path: str = "/burr") -> None:
"""
Mount the Burr UI inside another FastAPI app.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doc string for parameters

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and example code on how to mount it from some other code.

Also can you add and example to /examples and docs to docs/ for this new feature you're adding so that it's documented on how to use it? The example will show folks and prove out that this works.

"""
ui_app = create_burr_ui_app()
parent_app.mount(path, ui_app, name="burr-ui")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's expose name as a parameter



@app.get("/ready")
Expand Down
22 changes: 22 additions & 0 deletions docs/concepts/tracking.rst
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,25 @@ This will print the URL to access the Burr UI web app.
from google.colab import output
output.serve_kernel_port_as_window(7241) # this will open a new window
output.serve_kernel_port_as_iframe(7241) # this will inline in an iframe

---------------------------------------------
Mount Burr UI inside an existing FastAPI app
---------------------------------------------

You can embed the Burr UI inside an existing FastAPI application using the
``mount_burr_ui`` helper.

Example:

.. code-block:: python

from fastapi import FastAPI
from burr.tracking.server.run import mount_burr_ui

app = FastAPI()

# Mount Burr UI under /burr
mount_burr_ui(app, path="/burr")

This allows you to run the Burr tracking UI alongside your own FastAPI
application in the same server process.
24 changes: 24 additions & 0 deletions examples/fastapi_mount_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0.

from fastapi import FastAPI
import uvicorn

from burr.tracking.server.run import mount_burr_ui

app = FastAPI()

# Mount Burr UI
mount_burr_ui(app, path="/burr")


@app.get("/")
def root():
return {"message": "Main FastAPI app with Burr UI mounted"}


if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=8000)