Install the bugstack SDK for Python
The SDK is the crash-capture part of bugstack: it captures uncaught server errors and starts a fix. Middleware for FastAPI, Django, and Flask, a generic sys.excepthook integration, and the full config reference.
Compatibility
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
Get started
Sign up with GitHub and start with $100 of free credit, or book a call and we set it up with you. Once the SDK is in, an uncaught server error starts a fix: specialist agents work out the cause and write a small change, it arrives as a pull request that runs through your CI, and what happens next depends on the autonomy level you set. Connecting the repository also starts repository scanning.