Skip to main content

Real-time variable dumper for FastAPI — inspired by Laradumps

Project description

⚡ SmartDebugger

Real-time variable dump viewer for FastAPI — inspired by Laradumps.

Call sd(variable) anywhere in your FastAPI app and see it appear instantly in the browser.


Quick start

1. Install dependencies

pip install fastapi uvicorn requests

2. Start the debugger server

python run.py

Open http://localhost:8765 in your browser.

3. Use sd() in your FastAPI app

from client import ds

@app.get("/users/{user_id}")
async def get_user(user_id: int):
    user = db.get_user(user_id)
    sd(user, label="user from DB")          # dumps to the UI, non-blocking
    return user

Project structure

smart_debugger/
├── client/          # Python client library (the sd() function)
│   ├── __init__.py
│   └── ds.py
├── server/          # FastAPI dump server
│   ├── __init__.py
│   ├── app.py       # Routes: POST /dump, GET /dumps, WS /ws
│   └── manager.py   # WebSocket connection manager
├── static/          # Web UI (vanilla JS, no build step)
│   ├── index.html
│   ├── styles.css
│   └── app.js
├── example/
│   └── app.py       # Demo FastAPI app
├── run.py           # Server launcher
└── pyproject.toml

sd() reference

sd(data, label=None, level="info")
Parameter Type Default Description
data any Any Python value to inspect
label str None Human-readable name shown in the UI
level str "info" One of info, debug, warning, error

Returns data unchanged, so you can inline the call:

return sd(result, "final result")

Configuration

from client import configure

configure(
    server_url="http://localhost:8765",  # default
    timeout=1.0,                         # seconds — kept short
    enabled=True,                        # set False in production
)

UI features

  • Real-time WebSocket feed
  • Collapsible JSON tree viewer (auto-collapses at depth 3)
  • Level badges: info / debug / warning / error
  • Filter by level and free-text search (label, file, value)
  • Sort newest / oldest
  • Copy-to-clipboard button
  • File + line number + function name for every dump
  • Dark mode by default

Example routes (demo app)

# Start server
python run.py

# Start demo app in another terminal
uvicorn example.app:app --port 8000 --reload

# Hit the routes and watch the UI
curl http://localhost:8000/
curl http://localhost:8000/users/42
curl http://localhost:8000/error
curl -X POST http://localhost:8000/items \
     -H "Content-Type: application/json" \
     -d '{"name": "widget", "price": 9.99}'
curl http://localhost:8000/products

How it works

FastAPI app          SmartDebugger server        Browser
    │                        │                      │
    │  sd(data)              │                      │
    │─── POST /dump ────────>│                      │
    │   (daemon thread)      │── WS broadcast ─────>│
    │                        │                      │ (live update)
    │  (request continues)   │                      │
  1. sd() captures the caller's file/line/function via inspect.
  2. It serialises the value and fires a POST request on a daemon thread — completely non-blocking.
  3. The server stores the dump in a deque(maxlen=200) and broadcasts it to all connected WebSocket clients.
  4. The browser receives the payload and renders it as a collapsible JSON tree.

If the server is not running, sd() silently does nothing — it never crashes your app.


Disabling in production

import os
from client import configure

configure(enabled=os.getenv("DEBUG", "false").lower() == "true")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

smartdump-0.1.1.tar.gz (14.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

smartdump-0.1.1-py3-none-any.whl (15.2 kB view details)

Uploaded Python 3

File details

Details for the file smartdump-0.1.1.tar.gz.

File metadata

  • Download URL: smartdump-0.1.1.tar.gz
  • Upload date:
  • Size: 14.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.11

File hashes

Hashes for smartdump-0.1.1.tar.gz
Algorithm Hash digest
SHA256 d134d76633347e37a790b65fdb38e8e3017ddca8dd070f43d49a2e0270cfc583
MD5 11f53128ea3619d63aaa84fba5578bf6
BLAKE2b-256 7ae255244a3e153818142ce4f845126340ee0c9f6275b9f78aa23d43875f0812

See more details on using hashes here.

File details

Details for the file smartdump-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: smartdump-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 15.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.11

File hashes

Hashes for smartdump-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2a2f9622ebb57100acdb9a3ee6b42473b57ab1e7df2718375cc632f0fecc155c
MD5 695f4e0a5159ff49cc19930376c0e6d7
BLAKE2b-256 2ed680ef806914b052a07de90a5af6d82c36a23334b7b9b93305b59f98a1556a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page