How databricks-solutions/lakebase-fastapi-app works
This is a FastAPI read API for orders stored in a Lakebase autoscaling Postgres table synced from Databricks sample data. The main flow is a client request through the versioned orders routes, a database session, and queries against the synced table; responses use order and pagination models. The app also exposes health checks and initializes the database engine and OAuth token refresh at startup. The README documents bundle provisioning and post-deploy access grants; their wiring is represented from documentation, while the database implementation excerpt is partial.
Main entry points: database.py DB session layer · app.py FastAPI app · orders.py Orders routes · __init__.py V1 routes
Components 15
API surface
- FastAPI app
src/app.py - API router
src/routers/__init__.py - V1 routes
src/routers/v1/__init__.py - Health route
src/routers/v1/healthcheck.py
Order data
- Orders routes
src/routers/v1/orders.py - Order models
src/models/orders.py - Synced orders table
Database connectivity
- DB session layer
src/core/database.py - OAuth credentials
src/core/database.py - Lakebase endpoint
Provisioning
- UC source table
- Bundle provisioning
databricks.yml - Access grant hook
scripts/grant_app_access.py - App principal
Other components
- API client
Connections 18
- API client → FastAPI app: sends requests
- FastAPI app → API router: mounts
- API router → V1 routes: includes
- V1 routes → Orders routes: dispatches
- V1 routes → Health route: dispatches
- Orders routes → DB session layer: requests session
- Orders routes → Order models: validates and shapes
- Orders routes → Synced orders table: queries
- Order models → Synced orders table: maps
- FastAPI app → DB session layer: initializes engine
- FastAPI app → DB session layer: starts token refresh
- DB session layer → OAuth credentials: refreshes credentials
- OAuth credentials → Lakebase endpoint: requests tokens
- DB session layer → Lakebase endpoint: connects
- UC source table → Synced orders table: syncs data
- Bundle provisioning → Access grant hook: runs post-deploy
- Access grant hook → App principal: grants read access
- Access grant hook → Lakebase endpoint: connects as deployer