A modern, lightweight debug toolbar for FastAPI — inspired by Django Debug Toolbar, but built for async-first FastAPI apps.
- Real-time request/response inspection
- SQLAlchemy query counting & timing (async + sync)
- Total execution time & endpoint resolution
- Developer-only by default (safe for production)
- Easy plugin system to add custom panels
pip install fastapi-debugbar
from fastapi import FastAPI
from fastapi_debugbar import DebugBarMiddleware
app = FastAPI()
app.add_middleware(DebugBarMiddleware)
@app.get("/")
async def hello():
return {"message": "DebugBar active!"}Then open your app in the browser — you’ll see a debug toolbar overlay for each request (only in dev mode).
FastAPI lacks a built-in debug toolbar. Existing options are outdated or lack modern async support.
fastapi-debugbar — the modern, async-safe, plugin-based debug toolbar for FastAPI. Designed for SQLAlchemy 2.x and real-world dev/prod safety.
This library provides:
- Async-first design for FastAPI ≥0.100
- Extensible panels: add your own metrics easily
- Production-safe toggle (auto-disabled outside dev)
- Use
contextvarsfor per-request storage → safe for async & background tasks. - No global state pollution.
- Out-of-the-box support for SQLAlchemy 2.x event system (
before_cursor_execute/after_cursor_executefor both sync & async). - Clear roadmap for Tortoise ORM, asyncpg, or others.
-
Define a simple panel interface so devs can write:
class MyPanel(BasePanel): async def on_request_start(self, request): ... async def on_request_end(self, request, response): ...
and add it without forking.
- Only enabled when
DEBUG=trueorX-Debug-Tokenpresent. - Redacts sensitive headers (e.g., Authorization, Cookies).
- Body capture is size-limited to prevent leaks.
- Uses
pyproject.toml(PEP 621) from day one. - Ships with GitHub Actions CI + PyPI Trusted Publishing.
- Type hints, Black, Ruff/Flake8 pre-commit hooks.
- Clear, beautiful docs with real FastAPI examples (SQLAlchemy, ORM, no-ORM).
- JSON & HTML modes: developers can choose overlay or debug endpoint.
- Quickstart in 3 lines.
- Request/response panel
- SQLAlchemy panel
- Template rendering panel
- Profiler panel
- Cache hit/miss panel