Add fastapi-postgres-app template#236
Open
sysopmatt wants to merge 1 commit into
Open
Conversation
Minimal FastAPI service that connects to a Lakebase Autoscaling
(Postgres) database. Async stack (SQLAlchemy AsyncEngine + asyncpg),
background OAuth token refresh every 50 minutes, no front-end.
Pairs with the apps-cookbook.dev FastAPI + Lakebase recipe, adapted for
Autoscaling — uses w.postgres.generate_database_credential(endpoint=...)
instead of the Provisioned variant.
Layout:
fastapi-postgres-app/
├── main.py FastAPI entrypoint + lifespan
├── config/database.py Lakebase connection + token refresh
├── routes/health.py /healthz, /api/health
├── manifest.yaml Resource binding (postgres_spec)
├── app.yaml uvicorn + PGENDPOINT valueFrom
├── requirements.txt
└── .env.example Local dev only
Customer flow on Databricks Apps:
1. Create the app
2. Settings → Resources → Add resource: Lakebase Autoscaling project,
Permission 'Can connect and create', Resource key 'postgres'
3. Deploy
The resource binding auto-injects PG* env vars and app.yaml's
`valueFrom: postgres` populates PGENDPOINT. No manual env config needed
for deploy.
Naming and conventions match the existing peer templates
(flask-postgres-app, dash-postgres-app, streamlit-postgres-app):
`postgres_spec` in manifest, resource key `postgres`, env var
`PGENDPOINT`, requirements.txt for deps.
Fills a gap: the repo had flask/dash/streamlit-postgres-app and
appkit-lakebase (Node.js) but no FastAPI equivalent for Lakebase
Autoscaling.
README also includes a Postman service-principal recipe for exercising
the deployed API.
sysopmatt
force-pushed
the
add-fastapi-postgres-app
branch
from
June 8, 2026 21:52
5240d47 to
1d6d863
Compare
sysopmatt
marked this pull request as ready for review
June 8, 2026 21:58
Author
|
Heads up on the base Happy to add a row for this template (or fill in the whole Autoscaling family) if you'd like. |
LuuOW
reviewed
Jun 17, 2026
LuuOW
left a comment
There was a problem hiding this comment.
Technical audit: Implementation verified for system consistency and engineering integrity.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a
fastapi-postgres-app/template — a minimal FastAPI service that connects to a Lakebase Autoscaling (Postgres) database.Unlike the sibling
*-postgres-apptemplates (Flask / Dash / Streamlit) which use syncpsycopg, this one uses an async stack (SQLAlchemyAsyncEngine+asyncpg) because FastAPI is async-first — sync DB drivers insideasync defhandlers block the event loop. Background OAuth token refresh every 50 min, no front-end.Why
The repo has Lakebase Autoscaling templates for Flask (
flask-postgres-app), Dash (dash-postgres-app), Streamlit (streamlit-postgres-app), and Node.js (appkit-lakebase) — but no FastAPI equivalent. Customers building Python REST/async backends on Databricks Apps have been copy-pasting from the apps-cookbook.dev FastAPI + Lakebase recipe, which is written against Lakebase Provisioned. This template fills that gap and adapts the recipe for Autoscaling (w.postgres.generate_database_credential(endpoint=...)instead of the Provisioned credential call).Conventions
Matches the existing
*-postgres-apppeers where it makes sense:postgres_specinmanifest.yaml, resource keypostgres, permissionCAN_CONNECT_AND_CREATEPGENDPOINTenv var (valueFrom: postgresinapp.yaml)requirements.txtfor deps (web-app family usesrequirements.txt; agent/MCP family usespyproject.toml)databricks-sdk>=0.81.0aligned with peersJustified divergences (FastAPI-idiomatic):
asyncpg+ SQLAlchemyAsyncEngine) — peers are sync@asynccontextmanager) for engine init / token-refresh taskAPIRouter+ structured layout (config/,routes/) — peers are flatLivenessResponse,ReadinessResponse) for OpenAPI/Swagger clarityDepends(get_async_db)wiring on/api/healthto demonstrate the per-request session pattern users will extendLayout
Customer flow on Databricks Apps
Can connect and create, resource keypostgresThe resource binding auto-injects
PG*env vars andapp.yaml'svalueFrom: postgrespopulatesPGENDPOINT. No manual env config needed for deploy.Routes
//docs/healthz/api/healthSELECT 1The Swagger UI clearly labels which endpoint touches the DB and which doesn't.
The README also includes a Postman service-principal recipe (Client Credentials grant) for exercising the deployed API.
What this template intentionally doesn't include
Kept minimal as a starting point — no front-end, no application table queries, no writes, no user-authorized queries (connects as the app SP), no Alembic migrations.