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.2.tar.gz
(31.6 kB
view hashes)
Built Distribution
Close
Hashes for fastapi_toolbar-1.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | de8e1ec8c64524afab48d149e91cee73927810f732417a129ea4aa0f341ad91b |
|
MD5 | 6a7e3e8684e5988ef98d9f9810b13423 |
|
BLAKE2b-256 | 50a02904935a119fe78b7aef48fddab014cc74f0485df13ca5bc85da82bf9ba1 |