Skip to main content

FlowSurgeon — framework-agnostic profiling middleware for Python (WSGI & ASGI).

Project description

FlowSurgeon

Framework-agnostic profiling middleware for Python — works with Flask (WSGI) and FastAPI / Starlette (ASGI) out of the box.

FlowSurgeon injects a lightweight debug panel into every HTML response and stores request history in a local SQLite database, giving you timing, headers, and status codes without touching your application code.

Features

  • Zero required dependencies — pure stdlib
  • WSGI middleware (FlowSurgeonWSGI) for Flask, Django, and any WSGI app
  • ASGI middleware (FlowSurgeonASGI) for FastAPI, Starlette, and any ASGI app
  • FlowSurgeon() factory — auto-detects WSGI vs ASGI
  • Inline debug panel injected into HTML responses
  • Built-in history UI at /__flowsurgeon__/
  • SQLite persistence with auto-pruning
  • Sensitive header redaction (Authorization, Cookie)
  • FLOWSURGEON_ENABLED environment variable kill switch

Installation

pip install flowsurgeon

Quick start

FastAPI (ASGI)

from fastapi import FastAPI
from flowsurgeon import FlowSurgeon, Config

_app = FastAPI()
app = FlowSurgeon(_app, config=Config(enabled=True))

@_app.get("/")
async def index():
    return {"hello": "world"}

Run with uvicorn:

uvicorn myapp:app

Flask (WSGI)

from flask import Flask
from flowsurgeon import FlowSurgeon, Config

flask_app = Flask(__name__)
flask_app.wsgi_app = FlowSurgeon(
    flask_app.wsgi_app,
    config=Config(enabled=True),
)

Configuration

from flowsurgeon import Config

Config(
    enabled=True,                          # default: False (or FLOWSURGEON_ENABLED=1)
    allowed_hosts=["127.0.0.1", "::1"],    # hosts that see the panel
    db_path="flowsurgeon.db",              # SQLite file path
    max_stored_requests=1000,              # auto-prune threshold
    debug_route="/__flowsurgeon__",        # history UI prefix
    strip_sensitive_headers=["authorization", "cookie", "set-cookie"],
)

Debug UI

Route Description
/__flowsurgeon__/ Paginated request history
/__flowsurgeon__/{id} Full detail for one request

Roadmap

  • v0.3.0 — SQL query tracking (SQLAlchemy, DB-API 2.0)
  • v0.4.0 — CPU and memory profiling panel
  • v0.5.0 — Log capture and headers panel
  • v0.6.0 — Improved history/search UI

License

MIT

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

flowsurgeon-0.3.0.tar.gz (16.0 kB view details)

Uploaded Source

Built Distribution

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

flowsurgeon-0.3.0-py3-none-any.whl (24.9 kB view details)

Uploaded Python 3

File details

Details for the file flowsurgeon-0.3.0.tar.gz.

File metadata

  • Download URL: flowsurgeon-0.3.0.tar.gz
  • Upload date:
  • Size: 16.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for flowsurgeon-0.3.0.tar.gz
Algorithm Hash digest
SHA256 c482aeb0b9f025468119e003afd602eac1c0d1192a5ea7b160c5e00418110922
MD5 dd10e65f880f4d890fbff09b0c5ef210
BLAKE2b-256 7fc38f6171c9b212e9704d9774c20bafc5e29ba826f46feacfc1c994cb7b2d44

See more details on using hashes here.

File details

Details for the file flowsurgeon-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: flowsurgeon-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 24.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for flowsurgeon-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 63fba82234f67a793da7f12e477bcee82073632a6ca88f03d4f3b97ccba5c671
MD5 991de026461e66a8633d846a8508a346
BLAKE2b-256 9cb3e7a0779e7632e6c98f607f8552848c0e15e7fd310956dd5c3cb07b2eeeeb

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