🐞 A debug toolbar for FastAPI based on the original django-debug-toolbar. 🐞

Overview

FastAPI Debug Toolbar

FastAPI Debug Toolbar

🐞 A debug toolbar for FastAPI based on the original django-debug-toolbar. 🐞
Swagger UI & GraphQL are supported.

Test Coverage Codacy Package version


Documentation: https://fastapi-debug-toolbar.domake.io


Installation

pip install fastapi-debug-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:

app.add_middleware(
    DebugToolbarMiddleware,
    panels=["debug_toolbar.panels.sqlalchemy.SQLAlchemyPanel"],
)

Tortoise ORM

Add the TortoisePanel to your panel list:

app.add_middleware(
    DebugToolbarMiddleware,
    panels=["debug_toolbar.panels.tortoise.TortoisePanel"],
)
Comments
  • h11._util.LocalProtocolError: Too little data for declared Content-Length when open FastAPI docs

    h11._util.LocalProtocolError: Too little data for declared Content-Length when open FastAPI docs

    Dependencies:

    • fastapi 0.73.0
    • starlette 0.17.1
    • pydantic 1.9.0
    • h11 0.12.0

    Traceback

    When trying to open http://localhost:XXXX/docs:

    Traceback (most recent call last):
      File "/usr/local/lib/python3.9/site-packages/uvicorn/protocols/http/h11_impl.py", line 364, in run_asgi
        result = await app(self.scope, self.receive, self.send)
      File "/usr/local/lib/python3.9/site-packages/uvicorn/middleware/proxy_headers.py", line 75, in __call__
        return await self.app(scope, receive, send)
      File "/usr/local/lib/python3.9/site-packages/fastapi/applications.py", line 212, in __call__
        await super().__call__(scope, receive, send)
      File "/usr/local/lib/python3.9/site-packages/starlette/applications.py", line 112, in __call__
        await self.middleware_stack(scope, receive, send)
      File "/usr/local/lib/python3.9/site-packages/starlette/middleware/errors.py", line 181, in __call__
        raise exc
      File "/usr/local/lib/python3.9/site-packages/starlette/middleware/errors.py", line 159, in __call__
        await self.app(scope, receive, _send)
      File "/usr/local/lib/python3.9/site-packages/starlette/middleware/base.py", line 64, in __call__
        await response(scope, receive, send)
      File "/usr/local/lib/python3.9/site-packages/starlette/responses.py", line 244, in __call__
        await wrap(partial(self.listen_for_disconnect, receive))
      File "/usr/local/lib/python3.9/site-packages/anyio/_backends/_asyncio.py", line 574, in __aexit__
        raise exceptions[0]
      File "/usr/local/lib/python3.9/site-packages/starlette/responses.py", line 240, in wrap
        await func()
      File "/usr/local/lib/python3.9/site-packages/starlette/responses.py", line 234, in stream_response
        await send({"type": "http.response.body", "body": b"", "more_body": False})
      File "/usr/local/lib/python3.9/site-packages/starlette/middleware/errors.py", line 156, in _send
        await send(message)
      File "/usr/local/lib/python3.9/site-packages/uvicorn/protocols/http/h11_impl.py", line 468, in send
        output = self.conn.send(event)
      File "/usr/local/lib/python3.9/site-packages/h11/_connection.py", line 468, in send
        data_list = self.send_with_data_passthrough(event)
      File "/usr/local/lib/python3.9/site-packages/h11/_connection.py", line 501, in send_with_data_passthrough
        writer(event, data_list.append)
      File "/usr/local/lib/python3.9/site-packages/h11/_writers.py", line 60, in __call__
        self.send_eom(event.headers, write)
      File "/usr/local/lib/python3.9/site-packages/h11/_writers.py", line 83, in send_eom
        raise LocalProtocolError("Too little data for declared Content-Length")
    h11._util.LocalProtocolError: Too little data for declared Content-Length
    

    The issue (I think)

    https://github.com/mongkok/fastapi-debug-toolbar/blob/3552b0bbb8e1a86a4f5eaaf214e6916d52c941ef/debug_toolbar/middleware.py#L84

    On first iteration, body equals the correct body from response (b'<HTML CONTENT>'), on second iteration body is empty (b''). This empty body is use on the subsequent code, inserted on response, but line 97 never occurs.

    opened by chrismaille 3
  • try version 1.1, 1.2, 1.3 but never see the toolbar

    try version 1.1, 1.2, 1.3 but never see the toolbar

    Hi, I try it in a very simple Fastapi apps alike: from debug_toolbar.middleware import DebugToolbarMiddleware from fastapi import FastAPI

    app = FastAPI(debug=True) app.add_middleware(DebugToolbarMiddleware)

    @app.get("/") async def root(): return {"message": "Hello World"}

    start with :uvicorn main :app

    and doesn't works , I don't see the toolbar

    logs: INFO: Application startup complete. INFO: 127.0.0.1:61005 - "GET / HTTP/1.1" 200 OK INFO: 127.0.0.1:61005 - "GET /docs HTTP/1.1" 200 OK INFO: 127.0.0.1:61005 - "GET /_debug_toolbar/static/css/toolbar.css HTTP/1.1" 304 Not Modified INFO: 127.0.0.1:50609 - "GET /_debug_toolbar/static/js/toolbar.js HTTP/1.1" 304 Not Modified INFO: 127.0.0.1:61063 - "GET /_debug_toolbar/static/js/refresh.js HTTP/1.1" 304 Not Modified INFO: 127.0.0.1:60063 - "GET /_debug_toolbar/static/img/icon-white.svg HTTP/1.1" 304 Not Modified INFO: 127.0.0.1:61063 - "GET /_debug_toolbar/static/css/print.css HTTP/1.1" 304 Not Modified INFO: 127.0.0.1:60063 - "GET /openapi.json HTTP/1.1" 200 OK

    opened by ericfran 3
  • An error raised from PackageLoader in version of v0.3.0, what happened?

    An error raised from PackageLoader in version of v0.3.0, what happened?

    Here is the error stack information:

    Traceback (most recent call last):
      File "/xxx/pypoetry/virtualenvs/py3.8/lib/python3.8/multiprocessing/process.py", line 315, in _bootstrap
        self.run()
      File "/xxx/pypoetry/virtualenvs/py3.8/lib/python3.8/multiprocessing/process.py", line 108, in run
        self._target(*self._args, **self._kwargs)
      File "/xxx/pypoetry/virtualenvs/py3.8/lib/python3.8/site-packages/uvicorn/_subprocess.py", line 76, in subprocess_started
        target(sockets=sockets)
      File "/xxx/pypoetry/virtualenvs/py3.8/lib/python3.8/site-packages/uvicorn/server.py", line 60, in run
        return asyncio.run(self.serve(sockets=sockets))
      File "/xxx/pypoetry/virtualenvs/py3.8/lib/python3.8/asyncio/runners.py", line 44, in run
        return loop.run_until_complete(main)
      File "/xxx/pypoetry/virtualenvs/py3.8/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
        return future.result()
      File "/xxx/pypoetry/virtualenvs/py3.8/lib/python3.8/site-packages/uvicorn/server.py", line 67, in serve
        config.load()
      File "/xxx/pypoetry/virtualenvs/py3.8/lib/python3.8/site-packages/uvicorn/config.py", line 477, in load
        self.loaded_app = import_from_string(self.app)
      File "/xxx/pypoetry/virtualenvs/py3.8/lib/python3.8/site-packages/uvicorn/importer.py", line 21, in import_from_string
        module = importlib.import_module(module_str)
      File "xxx/importlib/__init__.py", line 127, in import_module
        return _bootstrap._gcd_import(name[level:], package, level)
      File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
      File "<frozen importlib._bootstrap>", line 991, in _find_and_load
      File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
      File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
      File "<frozen importlib._bootstrap_external>", line 783, in exec_module
      File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
      File "./main.py", line 18, in <module>
        app.add_middleware(
      File "/xxx/pypoetry/virtualenvs/py3.8/lib/python3.8/site-packages/starlette/applications.py", line 169, in add_middleware
        self.middleware_stack = self.build_middleware_stack()
      File "/xxx/pypoetry/virtualenvs/py3.8/lib/python3.8/site-packages/fastapi/applications.py", line 195, in build_middleware_stack
        app = cls(app=app, **options)
      File "/xxx/pypoetry/virtualenvs/py3.8/lib/python3.8/site-packages/debug_toolbar/middleware.py", line 31, in __init__
        self.settings = DebugToolbarSettings(**settings)
      File "/xxx/pypoetry/virtualenvs/py3.8/lib/python3.8/site-packages/debug_toolbar/settings.py", line 139, in __init__
        loaders = self.JINJA_LOADERS + [PackageLoader("debug_toolbar", "templates")]
      File "/xxx/pypoetry/virtualenvs/py3.8/lib/python3.8/site-packages/jinja2/loaders.py", line 323, in __init__
        raise ValueError(
    ValueError: The 'debug_toolbar' package was not installed in a way that PackageLoader understands.
    

    So what happened with this version v0.3.0?

    Can some useful help information be provided for this error?

    Thanks a lot!

    opened by YaoJusheng 2
  • Versions Bug & No SQL queries were recorded during this request.

    Versions Bug & No SQL queries were recorded during this request.

    Hi, im getting this error on the Versions Tab

    image

    And i am not able to get any SQL query response. I am using the Depends() function on my routes, Tried with sqllite and maria db with no success. The dependency injection setup is as the docs requsted.

    The same results with starting via python3 form my machine or docker (python:3.10.3-alpine) :(

    image image

    my requirements.txt

    fastapi==0.78.0
    uvicorn[standard]==0.18.2
    gunicorn==20.1.0
    uuid==1.30
    python-multipart==0.0.5
    weasyprint==55.0
    SQLAlchemy==1.4.39
    PyJWT==2.4.0
    cairocffi==1.3.0
    aiofiles==0.8.0
    PyPDF2==2.4.1
    bcrypt==3.2.2
    greenlet==1.1.2
    sentry-sdk==1.6.0
    fastapi_msal==0.1.7
    itsdangerous==2.1.2
    fastapi-debug-toolbar==0.2.1
    
    pydantic~=1.9.1
    starlette~=0.19.1
    flake8
    
    alembic==1.8.0
    PyMySQL~=1.0.2
    
    opened by AndreasMietk 2
  • Ability to parse UUID

    Ability to parse UUID

    https://github.com/mongkok/fastapi-debug-toolbar/blob/3552b0bbb8e1a86a4f5eaaf214e6916d52c941ef/debug_toolbar/panels/sql.py#L120-L121

    Using UUID field raise an exception

    *** TypeError: Object of type UUID is not JSON serializable

    I suggest, adding UUID serialization, by cast to str

    if isinstance(obj, UUID):
        return str(obj)
    

    Or allow setting encoder on json.dumps method

    opened by deby22 2
  • Add reviver parameter on JSON.parse redefinition

    Add reviver parameter on JSON.parse redefinition

    This solves Issue #13 that explains how the reviver parameter is excluded from the JSON.parse redefinition. This causes errors when trying to decode parameters using the openapi module contained in the FastApi framework.

    opened by armando-herastang 2
  • fix version home_page null

    fix version home_page null

    fix https://pypi.org/pypi/idna/json having the property set as null and later using ".length on null" in utils.js:82

    partially closing https://github.com/mongkok/fastapi-debug-toolbar/issues/16

    opened by AndreasMietk 1
  • JSON.parse collision with fastapi openapi module

    JSON.parse collision with fastapi openapi module

    I've experienced collisions on the JSON.parse function. When using the fastapi-debug-toolbar and /docs on fastapi which uses openapi module.

    refresh.js file redefines JSON.parse functions, excluding the reviver parameter. This cause issues on the function on get_swagger_ui_oauth2_redirect_html() function on file https://github.com/tiangolo/fastapi/blob/master/fastapi/openapi/docs.py.

    JSON.parse is used on L140:

    qp = qp ? JSON.parse('{' + arr.join() + '}',
                        function (key, value) {
                            return key === "" ? value : decodeURIComponent(value)
                        }
                ) : {}
    

    that uses the reviver function. The original implementation is not executed, but your overridden function, which does not include the reviver function which causes issues on encoded URI character not being properly decoded.

    Greetings

    opened by armando-herastang 1
  • feat: Fixes and Updates

    feat: Fixes and Updates

    • Fix h11._util.LocalProtocolError: Too little data for declared Content-Length when open FastAPI docs/swagger
    • Fix missing table error in unit tests, when sqlite drops table on memory after closing session.
    • Fix Generator-type Session dependencies not asserting AsyncExitStack. Use the settings session_generators option to pass the full python path for your generator: "foo.bar:my_db_session"
    • Do not show database credential on panels
    • Fix json encoding error using special UUID and datetime types in python
    • Show loguru logs in logging panel

    Resolves #10

    opened by chrismaille 0
Releases(0.3.2)
FastAPI Server Session is a dependency-based extension for FastAPI that adds support for server-sided session management

FastAPI Server-sided Session FastAPI Server Session is a dependency-based extension for FastAPI that adds support for server-sided session management.

DevGuyAhnaf 5 Dec 23, 2022
Prometheus exporter for metrics from the MyAudi API

Prometheus Audi Exporter This Prometheus exporter exports metrics that it fetches from the MyAudi API. Usage Checkout submodules Install dependencies

Dieter Maes 7 Dec 19, 2022
Docker image with Uvicorn managed by Gunicorn for high-performance FastAPI web applications in Python 3.6 and above with performance auto-tuning. Optionally with Alpine Linux.

Supported tags and respective Dockerfile links python3.8, latest (Dockerfile) python3.7, (Dockerfile) python3.6 (Dockerfile) python3.8-slim (Dockerfil

SebastiΓ‘n RamΓ­rez 2.1k Dec 31, 2022
REST API with FastAPI and JSON file.

FastAPI RESTAPI with a JSON py 3.10 First, to install all dependencies, in ./src/: python -m pip install -r requirements.txt Second, into the ./src/

Luis QuiΓ±ones Requelme 1 Dec 15, 2021
Adds integration of the Chameleon template language to FastAPI.

fastapi-chameleon Adds integration of the Chameleon template language to FastAPI. If you are interested in Jinja instead, see the sister project: gith

Michael Kennedy 124 Nov 26, 2022
A minimum reproducible repository for embedding panel in FastAPI

FastAPI-Panel A minimum reproducible repository for embedding panel in FastAPI Follow either This Tutorial or These steps below ↓↓↓ Clone the reposito

Tyler Houssian 15 Sep 22, 2022
Simple web app example serving a PyTorch model using streamlit and FastAPI

streamlit-fastapi-model-serving Simple example of usage of streamlit and FastAPI for ML model serving described on this blogpost and PyConES 2020 vide

Davide Fiocco 291 Jan 06, 2023
Pagination support for flask

flask-paginate Pagination support for flask framework (study from will_paginate). It supports several css frameworks. It requires Python2.6+ as string

Lix Xu 264 Nov 07, 2022
Cookiecutter API for creating Custom Skills for Azure Search using Python and Docker

cookiecutter-spacy-fastapi Python cookiecutter API for quick deployments of spaCy models with FastAPI Azure Search The API interface is compatible wit

Microsoft 379 Jan 03, 2023
Prometheus exporter for several chia node statistics

prometheus-chia-exporter Prometheus exporter for several chia node statistics It's assumed that the full node, the harvester and the wallet run on the

30 Sep 19, 2022
FastAPI pagination

FastAPI Pagination Installation # Basic version pip install fastapi-pagination # All available integrations pip install fastapi-pagination[all] Avail

Yurii Karabas 561 Jan 07, 2023
Qwerkey is a social media platform for connecting and learning more about mechanical keyboards built on React and Redux in the frontend and Flask in the backend on top of a PostgreSQL database.

Flask React Project This is the backend for the Flask React project. Getting started Clone this repository (only this branch) git clone https://github

Peter Mai 22 Dec 20, 2022
API written using Fast API to manage events and implement a leaderboard / badge system.

Open Food Facts Events API written using Fast API to manage events and implement a leaderboard / badge system. Installation To run the API locally, ru

Open Food Facts 5 Jan 07, 2023
Basic fastapi blockchain - An api based blockchain with full functionality

Basic fastapi blockchain - An api based blockchain with full functionality

1 Nov 27, 2021
FastAPI framework plugins

Plugins for FastAPI framework, high performance, easy to learn, fast to code, ready for production fastapi-plugins FastAPI framework plugins Cache Mem

RES 239 Dec 28, 2022
Fastapi-ml-template - Fastapi ml template with python

FastAPI ML Template Run Web API Local $ sh run.sh # poetry run uvicorn app.mai

Yuki Okuda 29 Nov 20, 2022
FastAPI native extension, easy and simple JWT auth

fastapi-jwt FastAPI native extension, easy and simple JWT auth

Konstantin Chernyshev 19 Dec 12, 2022
🐞 A debug toolbar for FastAPI based on the original django-debug-toolbar. 🐞

Debug Toolbar 🐞 A debug toolbar for FastAPI based on the original django-debug-toolbar. 🐞 Swagger UI & GraphQL are supported. Documentation: https:/

Dani 74 Dec 30, 2022
Light, Flexible and Extensible ASGI API framework

Starlite Starlite is a light and flexible ASGI API framework. Using Starlette and pydantic as foundations. Check out the Starlite documentation πŸ“š Cor

1.5k Jan 04, 2023
FastAPI + Postgres + Docker Compose + Heroku Deploy Template

FastAPI + Postgres + Docker Compose + Heroku Deploy ⚠️ For educational purpose only. Not ready for production use YET Features FastAPI with Postgres s

DP 12 Dec 27, 2022