🐞 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
:rocket: CLI tool for FastAPI. Generating new FastAPI projects & boilerplates made easy.

Project generator and manager for FastAPI. Source Code: View it on Github Features ?? Creates customizable project boilerplate. Creates customizable a

Yagiz Degirmenci 1k Jan 2, 2023
Simple FastAPI Example : Blog API using FastAPI : Beginner Friendly

fastapi_blog FastAPI : Simple Blog API with CRUD operation Steps to run the project: git clone https://github.com/mrAvi07/fastapi_blog.git cd fastapi-

Avinash Alanjkar 1 Oct 8, 2022
Пример использования GraphQL Ariadne с FastAPI и сравнение его с GraphQL Graphene FastAPI

FastAPI Ariadne Example Пример использования GraphQL Ariadne с FastAPI и сравнение его с GraphQL Graphene FastAPI - GitHub ###Запуск на локальном окру

ZeBrains Team 9 Nov 10, 2022
Sample-fastapi - A sample app using Fastapi that you can deploy on App Platform

Getting Started We provide a sample app using Fastapi that you can deploy on App

Erhan BÜTE 2 Jan 17, 2022
Flask-vs-FastAPI - Understanding Flask vs FastAPI Web Framework. A comparison of two different RestAPI frameworks.

Flask-vs-FastAPI Understanding Flask vs FastAPI Web Framework. A comparison of two different RestAPI frameworks. IntroductionIn Flask is a popular mic

Mithlesh Navlakhe 1 Jan 1, 2022
fastapi-admin2 is an upgraded fastapi-admin, that supports ORM dialects, true Dependency Injection and extendability

FastAPI2 Admin Introduction fastapi-admin2 is an upgraded fastapi-admin, that supports ORM dialects, true Dependency Injection and extendability. Now

Glib 14 Dec 5, 2022
Code Specialist 27 Oct 16, 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
Utils for fastapi based services.

Installation pip install fastapi-serviceutils Usage For more details and usage see: readthedocs Development Getting started After cloning the repo

Simon Kallfass 31 Nov 25, 2022
Utils for fastapi based services.

Installation pip install fastapi-serviceutils Usage For more details and usage see: readthedocs Development Getting started After cloning the repo

Simon Kallfass 20 Dec 18, 2020
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 8, 2023
Github timeline htmx based web app rewritten from Common Lisp to Python FastAPI

python-fastapi-github-timeline Rewrite of Common Lisp htmx app _cl-github-timeline into Python using FastAPI. This project tries to prove, that with h

Jan Vlčinský 4 Mar 25, 2022
Basic fastapi blockchain - An api based blockchain with full functionality

Basic fastapi blockchain - An api based blockchain with full functionality

null 1 Nov 27, 2021
Redis-based rate-limiting for FastAPI

Redis-based rate-limiting for FastAPI

Glib 6 Nov 14, 2022
A dynamic FastAPI router that automatically creates CRUD routes for your models

⚡ Create CRUD routes with lighting speed ⚡ A dynamic FastAPI router that automatically creates CRUD routes for your models

Adam Watkins 950 Jan 8, 2023
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 7, 2023
Opinionated set of utilities on top of FastAPI

FastAPI Contrib Opinionated set of utilities on top of FastAPI Free software: MIT license Documentation: https://fastapi-contrib.readthedocs.io. Featu

identix.one 543 Jan 5, 2023
Reusable utilities for FastAPI

Reusable utilities for FastAPI Documentation: https://fastapi-utils.davidmontague.xyz Source Code: https://github.com/dmontagu/fastapi-utils FastAPI i

David Montague 1.3k Jan 4, 2023