SDKs JavaScript SDK Python SDK Go SDK Ruby SDK Docs Pricing Blog Error Guides Book a Demo
Log In Start Free Trial

Install bugstack for Python

Middleware for FastAPI, Django, and Flask. Generic sys.excepthook integration and full config reference.

Compatibility

Python 3.8+

Install

pip install bugstack

Initialize

Call bugstack.init() once at application startup:

import bugstack

bugstack.init(
    api_key=os.environ["BUGSTACK_API_KEY"]
)

try:
    risky_operation()
except Exception as e:
    bugstack.capture_exception(e)

FastAPI

Add the bugstack middleware to your FastAPI application:

from fastapi import FastAPI
from bugstack.integrations.fastapi import FastAPIMiddleware

app = FastAPI()
app.add_middleware(FastAPIMiddleware, api_key=os.environ["BUGSTACK_API_KEY"])

@app.get("/")
async def root():
    return {"message": "Hello World"}

Django

Add bugstack to your Django middleware stack and configure it in settings.py:

# settings.py

MIDDLEWARE = [
    "bugstack.integrations.django.BugstackMiddleware",
    # ... other middleware
]

BUGSTACK = {
    "API_KEY": os.environ["BUGSTACK_API_KEY"],
    "ENVIRONMENT": "production",
}

Flask

Initialize bugstack with your Flask application:

from flask import Flask
from bugstack.integrations.flask import init_app

app = Flask(__name__)
init_app(app, api_key=os.environ["BUGSTACK_API_KEY"])

@app.route("/")
def hello():
    return "Hello World"

Generic Python

For scripts, workers, or any Python process, install the global exception hooks:

import bugstack

bugstack.init(api_key=os.environ["BUGSTACK_API_KEY"])

# Install sys.excepthook and threading.excepthook
bugstack.install_hooks()

Configuration Reference

Option Type Default Description
api_key str Required. Your bugstack API key.
environment str "production" Environment name (production, staging, etc.).
auto_fix bool True Enable automatic fix generation via GitHub PRs.
debug bool False Log internal SDK activity to stderr.
dry_run bool False Process errors locally without sending to the API.
enabled bool True Master kill switch for error capture.
deduplication_window int 60 Window in seconds to deduplicate identical errors.
timeout int 5 HTTP timeout in seconds for sending reports.
max_retries int 3 Number of retries on failed HTTP requests.
ignored_errors list[type] [] Exception types to ignore (e.g., [KeyboardInterrupt]).
before_send Callable None Hook to transform or drop payloads before sending.
redact_fields list[str] ["password", "secret", "token"] Field names to redact from captured data.

Next Steps

Start capturing Python errors now

bugstack catches runtime errors in production, writes the fix, runs your CI, and opens a tested pull request — in under 2 minutes.