๐Ÿž 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)
ะŸั€ะธะผะตั€ ะธัะฟะพะปัŒะทะพะฒะฐะฝะธั GraphQL Ariadne ั FastAPI ะธ ัั€ะฐะฒะฝะตะฝะธะต ะตะณะพ ั GraphQL Graphene FastAPI

FastAPI Ariadne Example ะŸั€ะธะผะตั€ ะธัะฟะพะปัŒะทะพะฒะฐะฝะธั GraphQL Ariadne ั FastAPI ะธ ัั€ะฐะฒะฝะตะฝะธะต ะตะณะพ ั GraphQL Graphene FastAPI - GitHub ###ะ—ะฐะฟัƒัะบ ะฝะฐ ะปะพะบะฐะปัŒะฝะพะผ ะพะบั€ัƒ

ZeBrains Team 9 Nov 10, 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
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
Voucher FastAPI

Voucher-API Requirement Docker Installed on system Libraries Pandas Psycopg2 FastAPI PyArrow Pydantic Uvicorn How to run Download the repo on your sys

Hassan Munir 1 Jan 26, 2022
Easily integrate socket.io with your FastAPI app ๐Ÿš€

fastapi-socketio Easly integrate socket.io with your FastAPI app. Installation Install this plugin using pip: $ pip install fastapi-socketio Usage To

Srdjan Stankovic 210 Dec 23, 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
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
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
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
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
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
Hook Slinger acts as a simple service that lets you send, retry, and manage event-triggered POST requests, aka webhooks

Hook Slinger acts as a simple service that lets you send, retry, and manage event-triggered POST requests, aka webhooks. It provides a fully self-contained docker image that is easy to orchestrate, m

Redowan Delowar 96 Jan 02, 2023
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
A set of demo of deploying a Machine Learning Model in production using various methods

Machine Learning Model in Production This git is for those who have concern about serving your machine learning model to production. Overview The tuto

Vo Van Tu 53 Sep 14, 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
flask extension for integration with the awesome pydantic package

flask extension for integration with the awesome pydantic package

249 Jan 06, 2023
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 01, 2022
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
์Šคํƒ€ํŠธ์—… ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ

์Šคํƒ€ํŠธ์—… ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ ๅคง ๋ฐ•๋žŒํšŒ Seed ~ Series B์— ์žˆ๋Š” ์Šคํƒ€ํŠธ์—…์„ ์œ„ํ•œ ์ฑ„์šฉ์ •๋ณด ํŽ˜์ด์ง€์ž…๋‹ˆ๋‹ค. Back-end, Frontend, Mobile ๋“ฑ ๊ฐœ๋ฐœ์ž๋ฅผ ๋Œ€์ƒ์œผ๋กœ ์ง„ํ–‰ํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ํ•ด๋‹น ์Šคํƒ€ํŠธ์—…์— ์ข…์‚ฌํ•˜์‹œ๋Š” ๋ถ„๋ฟ๋งŒ ์•„๋‹ˆ๋ผ ์ฑ„์šฉ ๊ด€๋ จ ์ •๋ณด๋ฅผ ์•Œ๊ณ  ๊ณ„์‹œ๋‹ค๋ฉด

JuHyun Lee 58 Dec 14, 2022
User authentication fastapi with python

user-authentication-fastapi Authentication API Development Setup environment You should create a virtual environment and activate it: virtualenv venv

Sabir Hussain 3 Mar 03, 2022