dbwarden-fastapi
FastAPI integration for dbwarden.
Provides request-scoped sessions, a migration-aware lifespan, and health/status routers.
Hooks
| Hook | Provides |
|---|---|
session_factory / sync_session_factory |
Request-scoped AsyncSession / Session dependencies, backing database_config(...).async_session and .sync_session |
clickhouse_session_factory / clickhouse_sync_session_factory |
Shared ClickHouse client dependencies |
lifespan |
Startup schema check or auto-migration, optional readiness gate, seed application, and pool warmup; disposes engines on shutdown |
health_routes |
GET /, /liveness, /readiness, /{database_name} |
migration_routes |
GET /status and POST /migrate |
Also exported directly: dbwarden_lifespan, DBWardenRouter, DBWardenHealthRouter, MetricsRouter, MetricsMiddleware, QueryTracingMiddleware, PoolMetricsCollector, migration_lock, sync_migration_lock, override_database, and migration_state.
Automatic schemas
Re-exports schemap's @auto_schema and SchemaConfig, so Pydantic schemas can be generated from your SQLAlchemy models:
from dbwarden_fastapi import auto_schema
@auto_schema
class User(Base): ...
Usage
from fastapi import FastAPI
from dbwarden_fastapi import DBWardenHealthRouter, dbwarden_lifespan
app = FastAPI(lifespan=lambda app: dbwarden_lifespan(app, mode="check"))
app.include_router(DBWardenHealthRouter(), prefix="/health")
Installation
dbwarden plugin add dbwarden-fastapi
Optional extras: [metrics] for Prometheus counters, [redis] for the distributed migration_lock, [clickhouse] for ClickHouse sessions.
Tenancy and lifecycle
get_tenant_session() selects a registered database for each request.
TenantResolver(source="header") reads X-DBWarden-Database by default. Use
source="host", source="both", precedence="host", or host_mapping to map
hostnames to registered database names. A custom sync or async callable accepting
Request may also be supplied. get_session() also accepts a registered
DatabaseHandle or DbwardenDatabase class.
For dbwarden_lifespan(mode="migrate"), background_migrations=True supports
background_migration_readiness="block" (default), "serve", or "fail".
Metrics refresh during lifespan every 30 seconds by default and refreshes stale
scrapes; set metrics_refresh_interval=None to disable the periodic task.
Set opentelemetry=True with the [opentelemetry] extra to instrument FastAPI.
Trust tier
This is an official dbwarden plugin. Its distribution name is classified before any of its code is imported, and dbwarden plugin add verifies the PyPI Trusted-Publishing attestation (PEP 740) against dbwarden-org/dbwarden-fastapi before installing. It loads automatically once installed, with no dbwarden plugin trust step.
Development
uv venv && uv pip install -e . -e ../dbwarden pytest
pytest -q
The tests/test_conformance.py suite runs dbwarden's shared conformance harness (dbwarden.plugin_conformance): entry point resolution, no import-time side effects, hook signatures, public-API-only imports, and idempotent setup().
License
MIT
Release files for dbwarden-fastapi 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| dbwarden_fastapi-0.2.0.tar.gz | 36.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| dbwarden_fastapi-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 66.6 kB
Release files / dbwarden_fastapi-0.2.0.tar.gz
| Download URL | dbwarden_fastapi-0.2.0.tar.gz |
|---|---|
| Size | 36.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f683a872d2f73f893ceedfc45b95b6e5ce1991fa9f5403f97d5f9412d8ea52a2
|
|
BLAKE2b-256 checksum How to use checksums |
0be5c5a537122b68612db5c661f717cfbcd00ed175ff044e038e506e214386ec
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 17, 2026.
Transparency logRelease files / dbwarden_fastapi-0.2.0-py3-none-any.whl
| Download URL | dbwarden_fastapi-0.2.0-py3-none-any.whl |
|---|---|
| Size | 30.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
525d5124394ef384fbda78e3b36b8791ee674cfe627e1944628c3359c12ed503
|
|
BLAKE2b-256 checksum How to use checksums |
a2022cdd66aeecfbcda287e9960ad89ae1563a951cddc56f24644d18fa9dc0cc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 17, 2026.
Transparency log