A debug toolbar for FastAPI.
Project description
Welcome to FastAPI-Toolbar
Original work: https://github.com/mongkok/fastapi-debug-toolbar
Installation
pip install fastapi-toolbar
Quickstart
Add DebugToolbarMiddleware
middleware to your FastAPI application:
from debug_toolbar.middleware import DebugToolbarMiddleware
from fastapi import FastAPI
app = FastAPI(debug=True)
app.add_middleware(DebugToolbarMiddleware)
SQLAlchemy
Please make sure to use the "Dependency Injection" system as described in the FastAPI docs and add the SQLAlchemyPanel
to your panel list:
If you're using a database session generator (using yield
), please add the full python path of your generators
on the session_generators
options, when adding the middleware:
# database.py
from typing import Generator
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
engine = create_engine("sqlite://", connect_args={"check_same_thread": False})
SessionLocal = sessionmaker(bind=engine)
Base = declarative_base()
Base.metadata.create_all(bind=engine)
def get_db() -> Generator:
db = SessionLocal()
try:
yield db
finally:
db.close() # sqlite will drop tables in memory
Base.metadata.create_all(bind=engine) # create tables again
# app.py
from fastapi import FastAPI
from debug_toolbar.middleware import DebugToolbarMiddleware
app = FastAPI()
app.add_middleware(
DebugToolbarMiddleware,
panels=["debug_toolbar.panels.sqlalchemy.SQLAlchemyPanel"],
session_generators=["database:get_db"] # Add the full python path of your session generators
)
Tortoise ORM
Add the TortoisePanel
to your panel list:
from fastapi import FastAPI
from debug_toolbar.middleware import DebugToolbarMiddleware
app = FastAPI()
app.add_middleware(
DebugToolbarMiddleware,
panels=["debug_toolbar.panels.tortoise.TortoisePanel"],
)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
fastapi-toolbar-1.0.3.tar.gz
(31.6 kB
view hashes)
Built Distribution
Close
Hashes for fastapi_toolbar-1.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cabae7da6739aa5bda86ba8db860907f637f64f7f4e01dff52bfec1dc9c80174 |
|
MD5 | 0e33f1dadfd1cbaeba27f2314d8354d2 |
|
BLAKE2b-256 | a528b7c6d2d50f7074cad5c9188c39c12e61f1b2407bc7484186b2a778f2d87b |