🐞 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)
Feature rich robust FastAPI template.

Flexible and Lightweight general-purpose template for FastAPI. Usage ⚠️ Git, Python and Poetry must be installed and accessible ⚠️ Poetry version must

Pavel Kirilin 588 Jan 04, 2023
Code for my FastAPI tutorial

FastAPI tutorial Code for my video tutorial FastAPI tutorial What is FastAPI? FastAPI is a high-performant REST API framework for Python. It's built o

José Haro Peralta 9 Nov 15, 2022
Sample project showing reliable data ingestion application using FastAPI and dramatiq

Create and deploy a reliable data ingestion service with FastAPI, SQLModel and Dramatiq This is the source code for the data ingestion service explain

François Voron 31 Nov 30, 2022
Dead-simple mailer micro-service for static websites

Mailer Dead-simple mailer micro-service for static websites A free and open-source software alternative to contact form services such as FormSpree, to

Romain Clement 42 Dec 21, 2022
Ansible Inventory Plugin, created to get hosts from HTTP API.

ansible-ws-inventory-plugin Ansible Inventory Plugin, created to get hosts from HTTP API. Features: Database compatible with MongoDB and Filesystem (J

Carlos Neto 0 Feb 05, 2022
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
Mixer -- Is a fixtures replacement. Supported Django, Flask, SqlAlchemy and custom python objects.

The Mixer is a helper to generate instances of Django or SQLAlchemy models. It's useful for testing and fixture replacement. Fast and convenient test-

Kirill Klenov 871 Dec 25, 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
Local Telegram Bot With FastAPI & Ngrok

An easy local telegram bot server with python, fastapi and ngrok.

Ömer Faruk Özdemir 7 Dec 25, 2022
Practice-python is a simple Fast api project for dealing with modern rest api technologies.

Practice Python Practice-python is a simple Fast api project for dealing with modern rest api technologies. Deployment with docker Go to the project r

0 Sep 19, 2022
FastAPI Socket.io with first-class documentation using AsyncAPI

fastapi-sio Socket.io FastAPI integration library with first-class documentation using AsyncAPI The usage of the library is very familiar to the exper

Marián Hlaváč 9 Jan 02, 2023
A rate limiter for Starlette and FastAPI

SlowApi A rate limiting library for Starlette and FastAPI adapted from flask-limiter. Note: this is alpha quality code still, the API may change, and

Laurent Savaete 562 Jan 01, 2023
MS Graph API authentication example with Fast API

MS Graph API authentication example with Fast API What it is & does This is a simple python service/webapp, using FastAPI with server side rendering,

Andrew Hart 4 Aug 11, 2022
Adds simple SQLAlchemy support to FastAPI

FastAPI-SQLAlchemy FastAPI-SQLAlchemy provides a simple integration between FastAPI and SQLAlchemy in your application. It gives access to useful help

Michael Freeborn 465 Jan 07, 2023
Turns your Python functions into microservices with web API, interactive GUI, and more.

Instantly turn your Python functions into production-ready microservices. Deploy and access your services via HTTP API or interactive UI. Seamlessly export your services into portable, shareable, and

Machine Learning Tooling 2.8k Jan 04, 2023
京东图片点击验证码识别

京东图片验证码识别 本项目是@yqchilde 大佬的 JDMemberCloseAccount 识别图形验证码(#45)思路验证,若你也有思路可以提交Issue和PR也可以在 @yqchilde 的 TG群 找到我 声明 本脚本只是为了学习研究使用 本脚本除了采集处理验证码图片没有其他任何功能,也

AntonVanke 37 Dec 22, 2022
The template for building scalable web APIs based on FastAPI, Tortoise ORM and other.

FastAPI and Tortoise ORM. Powerful but simple template for web APIs w/ FastAPI (as web framework) and Tortoise-ORM (for working via database without h

prostomarkeloff 95 Jan 08, 2023
CLI and Streamlit applications to create APIs from Excel data files within seconds, using FastAPI

FastAPI-Wrapper CLI & APIness Streamlit App Arvindra Sehmi, Oxford Economics Ltd. | Website | LinkedIn (Updated: 21 April, 2021) fastapi-wrapper is mo

Arvindra 49 Dec 03, 2022
Generate Class & Decorators for your FastAPI project ✨🚀

Classes and Decorators to use FastAPI with class based routing. In particular this allows you to construct an instance of a class and have methods of that instance be route handlers for FastAPI & Pyt

Yasser Tahiri 34 Oct 27, 2022
A basic JSON-RPC implementation for your Flask-powered sites

Flask JSON-RPC A basic JSON-RPC implementation for your Flask-powered sites. Some reasons you might want to use: Simple, powerful, flexible and python

Cenobit Technologies 273 Dec 01, 2022