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.2.tar.gz (33.1 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.2-py3-none-any.whl (44.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: flowsurgeon-0.3.2.tar.gz
  • Upload date:
  • Size: 33.1 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.2.tar.gz
Algorithm Hash digest
SHA256 a4002e50775c5108c7bee78f364766bd75ec0e98c1e5c6f3d3a0feb3337e8e6a
MD5 d34589bf2d3e4fd6bfd2b69093ae6614
BLAKE2b-256 b285f7ae85c4ff8aada98c7a7d48724064df9e6d6ffb929bf4249a4683abc99a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: flowsurgeon-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 44.5 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4bdb414d353af1c96aaac57784fca043538a2949493de28ddfec8fd593a769b1
MD5 27223de4fb847089f411503b898ed626
BLAKE2b-256 83d3051c925bc7c7a99681f5369061aa72ec7ded65d5f76799a019f77c9eb55c

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