🐞 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)
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
Single Page App with Flask and Vue.js

Developing a Single Page App with FastAPI and Vue.js Want to learn how to build this? Check out the post. Want to use this project? Build the images a

91 Jan 05, 2023
A web application using [FastAPI + streamlit + Docker] Neural Style Transfer (NST) refers to a class of software algorithms that manipulate digital images

Neural Style Transfer Web App - [FastAPI + streamlit + Docker] NST - application based on the Perceptual Losses for Real-Time Style Transfer and Super

Roman Spiridonov 3 Dec 05, 2022
Hyperlinks for pydantic models

Hyperlinks for pydantic models In a typical web application relationships between resources are modeled by primary and foreign keys in a database (int

Jaakko Moisio 10 Apr 18, 2022
Basic fastapi blockchain - An api based blockchain with full functionality

Basic fastapi blockchain - An api based blockchain with full functionality

1 Nov 27, 2021
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
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-PostgreSQL-Celery-RabbitMQ-Redis bakcend with Docker containerization

FastAPI - PostgreSQL - Celery - Rabbitmq backend This source code implements the following architecture: All the required database endpoints are imple

Juan Esteban Aristizabal 54 Nov 26, 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 08, 2023
FastAPI simple cache

FastAPI Cache Implements simple lightweight cache system as dependencies in FastAPI. Installation pip install fastapi-cache Usage example from fastapi

Ivan Sushkov 188 Dec 29, 2022
Cookiecutter template for FastAPI projects using: Machine Learning, Poetry, Azure Pipelines and Pytests

cookiecutter-fastapi In order to create a template to FastAPI projects. 🚀 Important To use this project you don't need fork it. Just run cookiecutter

Arthur Henrique 225 Dec 28, 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
🔀⏳ Easy throttling with asyncio support

Throttler Zero-dependency Python package for easy throttling with asyncio support. 📝 Table of Contents 🎒 Install 🛠 Usage Examples Throttler and Thr

Ramzan Bekbulatov 80 Dec 07, 2022
FastAPI client generator

FastAPI-based API Client Generator Generate a mypy- and IDE-friendly API client from an OpenAPI spec. Sync and async interfaces are both available Com

David Montague 283 Jan 04, 2023
Simple example of FastAPI + Celery + Triton for benchmarking

You can see the previous work from: https://github.com/Curt-Park/producer-consumer-fastapi-celery https://github.com/Curt-Park/triton-inference-server

Jinwoo Park (Curt) 37 Dec 29, 2022
This repository contains learning resources for Python Fast API Framework and Docker

This repository contains learning resources for Python Fast API Framework and Docker, Build High Performing Apps With Python BootCamp by Lux Academy and Data Science East Africa.

Harun Mbaabu Mwenda 23 Nov 20, 2022
Learn to deploy a FastAPI application into production DigitalOcean App Platform

Learn to deploy a FastAPI application into production DigitalOcean App Platform. This is a microservice for our Try Django 3.2 project. The goal is to extract any and all text from images using a tec

Coding For Entrepreneurs 59 Nov 29, 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 05, 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 02, 2023
High-performance Async REST API, in Python. FastAPI + GINO + Arq + Uvicorn (w/ Redis and PostgreSQL).

fastapi-gino-arq-uvicorn High-performance Async REST API, in Python. FastAPI + GINO + Arq + Uvicorn (powered by Redis & PostgreSQL). Contents Get Star

Leo Sussan 351 Jan 04, 2023