FastAPI
Set up debugger in a FastAPI project.
Last updated March 19, 2026
Python + FastAPI
This guide covers adding debugger to a Python API using FastAPI. The setup takes two lines.
| Feature | Support |
|---|---|
| Server console | Yes |
| Server errors | Yes |
| HTTP requests | Yes |
| Browser script injection | Automatic |
Prerequisites
- Python 3.10 or later
Install
pip install ephem-debugger[fastapi]
Or with uv:
uv add ephem-debugger[fastapi]
Set up
Add the middleware to your FastAPI app:
from fastapi import FastAPI
from ephem_debugger_py.middleware.fastapi import Middleware, logger, close
app = FastAPI()
app.add_middleware(Middleware, port=8000)
log = logger()
@app.get("/")
async def root():
log.info("home page hit")
return {"status": "ok"}
@app.on_event("shutdown")
async def shutdown():
close()
Two lines handle debugger setup:
app.add_middleware(Middleware, port=8000)— capture HTTP requests and start the sessionlog = logger()— get a logger that writes to both stderr and the debugger store
What gets captured
- HTTP requests — method, path, status code, and latency for every request
- Logging calls — any
log.info(),log.error(),log.warning()call in your handlers
Verify
Start your server:
uvicorn app:app --reload
Open another terminal and query:
npx dbg statuspnpm dlx dbg statusbun x dbg statusyarn dlx dbg statusnpx dbg server consolepnpm dlx dbg server consolebun x dbg server consoleyarn dlx dbg server consoleProduction safety
The middleware runs unconditionally. Guard it for production:
import os
if os.getenv("DEBUG") == "1":
app.add_middleware(Middleware, port=8000)
Browser support
If your application serves HTML pages, the debugger automatically captures browser-side data. The middleware:
- Serves the browser client script at
/_/d.js - Handles browser log ingest at
POST /_/d - Auto-injects script tags into HTML responses before
</body>
No additional setup is needed. Query browser data with:
npx dbg browser consolepnpm dlx dbg browser consolebun x dbg browser consoleyarn dlx dbg browser consolenpx dbg browser errorspnpm dlx dbg browser errorsbun x dbg browser errorsyarn dlx dbg browser errorsnpx dbg browser networkpnpm dlx dbg browser networkbun x dbg browser networkyarn dlx dbg browser networknpx dbg browser cookiespnpm dlx dbg browser cookiesbun x dbg browser cookiesyarn dlx dbg browser cookiesnpx dbg browser storagepnpm dlx dbg browser storagebun x dbg browser storageyarn dlx dbg browser storageFull example
See the complete working example at examples/python/fastapi.



