Skip to main content

bugstack-python

The Bugstack SDK for Python: Django, Flask and FastAPI.

Bugstack is autonomous software maintenance. It watches your app and your repository, fixes what breaks, and sends every change as a pull request you control. This SDK is how your app tells Bugstack about an uncaught server error.

PyPI Python License: MIT

Installation

pip install bugstack

Quick Start

import bugstack

bugstack.init(api_key="bs_live_...")

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

Framework Integrations

FastAPI

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

app = FastAPI()
app.add_middleware(FastAPIMiddleware)

bugstack.init(api_key="bs_live_...")

Django

# settings.py
MIDDLEWARE = [
    'bugstack.integrations.django.BugStackMiddleware',
    # ... other middleware
]

BUGSTACK_API_KEY = "bs_live_..."
BUGSTACK_AUTO_FIX = True  # optional

Flask

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

app = Flask(__name__)
bugstack.init(api_key="bs_live_...")
init_app(app)

Generic (sys.excepthook)

from bugstack.integrations.generic import install_hooks

bugstack.init(api_key="bs_live_...")
install_hooks()

Caught-and-logged errors (logging)

Most failures never reach sys.excepthook. An except block logs them and the app carries on:

try:
    grant_credits(order)
except KeyError:
    logger.exception("[billing] grant failed")   # a log line nobody reads

Once bugstack.init() has run, these reach Bugstack too. It is on by default and needs no handler: every log record still goes to your handlers exactly as before, and logging.basicConfig() still works after init().

  • Forwarded: an ERROR (or higher) record that carries an exception, as exc_info (logger.exception(...), exc_info=True) or as a % argument (logger.error("row failed: %s", exc)). The report is anchored at the logging call, so each logging site is its own issue.
  • Left as a log line: ERROR records with no exception (set capture_log_messages=True to forward them as their message), the SDK's own bugstack logger, and an exception capture_exception already sent.
  • Bounded: at most 20 a minute per process, the same site and message at most once per 5 minutes, then the usual fingerprint dedup. The logged text goes through redact_fields, and bearer tokens are masked. Forwarding never raises.
bugstack.init(api_key="bs_live_...", capture_logging=False)        # turn it off
bugstack.init(api_key="bs_live_...", capture_log_messages=True)    # also forward message-only ERROR records

Configuration

bugstack.init(
    api_key="bs_live_...",          # Required
    environment="production",       # Default: "production"
    auto_fix=True,                  # Let Bugstack open a fix for errors this SDK reports
    debug=False,                    # Log SDK activity
    dry_run=False,                  # Log without sending
    enabled=True,                   # Kill switch
    deduplication_window=300,       # Seconds (default: 5 min)
    timeout=5.0,                    # HTTP timeout in seconds
    max_retries=3,                  # Retry attempts
    ignored_errors=[                # Errors to skip
        KeyboardInterrupt,
        "expected error message",
    ],
    before_send=my_hook,            # Inspect/modify/drop events
    redact_fields=["password"],     # Fields to redact
    capture_logging=True,           # Forward caught-and-logged errors (default: on)
    capture_log_messages=False,     # Also forward ERROR records without an exception
)

Data Transparency

before_send Hook

Inspect, modify, or drop any event before it leaves your application:

def before_send(event):
    # Drop health check errors
    if "health" in event.request.route:
        return None

    # Redact sensitive data
    event.metadata.pop("secret", None)

    return event

bugstack.init(api_key="bs_live_...", before_send=before_send)

ignored_errors

Skip specific error types or messages:

bugstack.init(
    api_key="bs_live_...",
    ignored_errors=[
        KeyboardInterrupt,          # By type
        SystemExit,                 # By type
        "Connection reset",         # By exact message
    ],
)

dry_run Mode

See exactly what would be sent without making any network requests:

bugstack.init(api_key="bs_live_...", dry_run=True)
# Prints: [BugStack DryRun] Would send: { ... }

What Gets Sent

Every error event contains exactly this — nothing more:

{
  "apiKey": "bs_live_...",
  "error": {
    "message": "division by zero",
    "stackTrace": "Traceback (most recent call last)...",
    "file": "app/api/handler.py",
    "function": "process_request",
    "fingerprint": "a1b2c3d4e5f6g7h8"
  },
  "environment": {
    "language": "python",
    "languageVersion": "3.12.1",
    "framework": "fastapi",
    "frameworkVersion": "0.109.0",
    "os": "linux",
    "sdkVersion": "1.0.0"
  },
  "timestamp": "2026-01-15T08:30:00+00:00"
}

No cookies. No IP addresses. No user data. No request bodies (unless you explicitly include them).

License

MIT — see LICENSE.

Metadata

Release files for bugstack 1.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bugstack 1.3.0
File Size Uploaded Provenance Actions
bugstack-1.3.0.tar.gz 26.5 kB With provenance Details for bugstack-1.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for bugstack 1.3.0
File Interpreter ABI Platform Actions
bugstack-1.3.0-py3-none-any.whl Python 3 none any Details for bugstack-1.3.0-py3-none-any.whl

Total release size: 46.7 kB

Release files / bugstack-1.3.0.tar.gz

Download URL bugstack-1.3.0.tar.gz
Size 26.5 kB
Tags Source
SHA-256 checksum
How to use checksums
3c9b18692b82544da10a25f43324ad68c098c4de03bded66245bc6a1ae0897e2
BLAKE2b-256 checksum
How to use checksums
abe089bff5d4717b897ef2fe303641cc40d4fe2504dc490483f5e7d175a98fe5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.

Transparency log

Release files / bugstack-1.3.0-py3-none-any.whl

Download URL bugstack-1.3.0-py3-none-any.whl
Size 20.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6c2019c4488baa46a3fbe8eed63f6beb54f9ee7e4def47a3a35c97bee3cddb17
BLAKE2b-256 checksum
How to use checksums
8e48bc9a603015499540b50ad4c8e0143c230e460e9ca65a5a931c39f38e4430
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.

Transparency log

Security for bugstack 1.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for bugstack-1.3.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page