Skip to main content

FastAPI integration for DBWarden

Project description

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.

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.

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dbwarden_fastapi-0.1.1.tar.gz (27.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dbwarden_fastapi-0.1.1-py3-none-any.whl (24.0 kB view details)

Uploaded Python 3

File details

Details for the file dbwarden_fastapi-0.1.1.tar.gz.

File metadata

  • Download URL: dbwarden_fastapi-0.1.1.tar.gz
  • Upload date:
  • Size: 27.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.5

File hashes

Hashes for dbwarden_fastapi-0.1.1.tar.gz
Algorithm Hash digest
SHA256 3e1c073d6331950157a3b451eb7a6a6b7dda1fa821ed301303c0ed5fc6ebacc2
MD5 5e5df839e4702f56a73bf6479711fb97
BLAKE2b-256 804daf4a0e9021bdcdc64572bbb60f58df5fc061c251aa2c827a78e7eba4f49d

See more details on using hashes here.

File details

Details for the file dbwarden_fastapi-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for dbwarden_fastapi-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a6d1c2f755cbbce30f4ca15b5b1b1819e92fe00a65fa9e6a3750d3744f706b02
MD5 049b5a886c5c7addc4c2dd9a808f6632
BLAKE2b-256 b95bbfe837cc119677be5b3937c15027dc5e3127550ac1f6f9ed190a2f9553ca

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page