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 details)
Built Distribution
File details
Details for the file fastapi-toolbar-1.0.3.tar.gz
.
File metadata
- Download URL: fastapi-toolbar-1.0.3.tar.gz
- Upload date:
- Size: 31.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 633048ba1166726774bb6c6efa40a2ea584f5d0897d2bcb77e3ecee7d6f7b87b |
|
MD5 | ac9a029679a4c06646dc0187f3f9e892 |
|
BLAKE2b-256 | 94e53573a50272f6318d171f6fe2d172d3bb2e36280e47a631a9b93d4f71372f |
File details
Details for the file fastapi_toolbar-1.0.3-py3-none-any.whl
.
File metadata
- Download URL: fastapi_toolbar-1.0.3-py3-none-any.whl
- Upload date:
- Size: 47.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cabae7da6739aa5bda86ba8db860907f637f64f7f4e01dff52bfec1dc9c80174 |
|
MD5 | 0e33f1dadfd1cbaeba27f2314d8354d2 |
|
BLAKE2b-256 | a528b7c6d2d50f7074cad5c9188c39c12e61f1b2407bc7484186b2a778f2d87b |