Skip to main content

FastAPI runtime hooks for DBWarden.

Project description

dbwarden-fastapi

FastAPI runtime integration for DBWarden.

dbwarden-fastapi is an official DBWarden plugin. It is discovered automatically through its dbwarden.plugins entry point and loaded without a consent prompt once installed.

What It Provides

Value hooks that back DBWarden's FastAPI helpers:

  • session_factory, sync_session_factory: async and sync SQLAlchemy session dependencies.
  • clickhouse_session_factory, clickhouse_sync_session_factory: async and sync ClickHouse client dependencies.
  • lifespan: an application lifespan that runs migrations or schema checks on startup and disposes engines on shutdown.
  • health_routes: liveness, readiness, and per-database health endpoints.
  • migration_routes: status and migrate endpoints for operational control.

Each hook imports FastAPI and DBWarden internals lazily inside its own body, so installing the package pulls in nothing heavy and importing it has no side effects.

Install

dbwarden plugin add dbwarden-fastapi

plugin add verifies the package provenance (a PyPI PEP 740 attestation from the official repository) before installing. You can also install it directly with your package manager:

uv add dbwarden-fastapi
# or
pip install dbwarden-fastapi

FastAPI itself is expected to be a dependency of your application; install it alongside this plugin.

Use

DBWarden loads the plugin automatically. Confirm it is present:

dbwarden plugin list

Then wire the FastAPI helpers into your app. They resolve through this plugin when it is installed and fall back to core defaults when it is not:

from fastapi import Depends, FastAPI
from sqlalchemy.ext.asyncio import AsyncSession

from dbwarden.extensions.fastapi import (
    DBWardenHealthRouter,
    DBWardenRouter,
    dbwarden_lifespan,
    get_session,
)

app = FastAPI(lifespan=lambda app: dbwarden_lifespan(mode="check"))
app.include_router(DBWardenHealthRouter(), prefix="/health")
app.include_router(DBWardenRouter(), prefix="/dbwarden")


@app.get("/users")
async def users(session: AsyncSession = Depends(get_session("primary"))):
    ...

Development

pip install -e . pytest
pytest -q

The test suite is the DBWarden conformance suite plus plugin-specific checks. See the DBWarden plugin docs.

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.0.tar.gz (5.7 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.0-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dbwarden_fastapi-0.1.0.tar.gz
  • Upload date:
  • Size: 5.7 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.0.tar.gz
Algorithm Hash digest
SHA256 8bcb5d2f99ded27dd9595f33d79a5f12cdb5da2b5f4db3e9713aa0ec42e0a67f
MD5 a5cef14ffd92bacb32049427e40dc711
BLAKE2b-256 92866367aaf13e489d4e8f17d20fa8f7e3acffe662e7b41eeda96b592e57cbe2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for dbwarden_fastapi-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0f596a3c184672f10c2edbf32937fe2e2d4a4bc0453559d77bf7353acaa903ec
MD5 ae61596aaa7deaf89176ab5245094011
BLAKE2b-256 80f86feda7183154ef3c99079b6d73b7622ab540cec7242f0ecb363738a0dcb5

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