> ## Documentation Index
> Fetch the complete documentation index at: https://docs.steadwing.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Python SDK

> Install the Steadwing Python SDK to auto-capture exceptions, error logs, and HTTP breadcrumbs from your Python applications and send them to Steadwing for AI-powered root cause analysis.

## What is the Steadwing Python SDK?

The Steadwing Python SDK auto-captures exceptions, error logs, and HTTP breadcrumbs from your Python applications and sends them to Steadwing for root cause analysis. Add two lines of code and Steadwing starts monitoring your application no manual instrumentation required.

> [card] Auto-Capture
>
> Unhandled exceptions, error logs, and thread crashes captured automatically

> [card] HTTP Breadcrumbs
>
> Outgoing HTTP requests recorded with method, URL, status, and duration

> [card] FastAPI Support
>
> Automatic route error capture with request context when FastAPI is installed

> [card] Data Scrubbing
>
> Sensitive request header and variable fields redacted before sending

## Installation

```bash theme={null}
pip install steadwing
```

Requires Python 3.10+. View on [PyPI](https://pypi.org/project/steadwing/) or browse the [source on GitHub](https://github.com/steadwing/steadwing-python).

## Quick Start

Get your API key from [app.steadwing.com/organization](https://app.steadwing.com/organization), then initialize the SDK:

```python theme={null}
import steadwing

steadwing.init(
    api_key="st_your_api_key"
)
```

That's it. The SDK automatically:

* Captures unhandled exceptions (including in threads)
* Captures `logging.error()` and `logging.critical()` calls
* Records outgoing HTTP requests as breadcrumbs
* Sends heartbeats every 60 seconds
* Patches supported frameworks to capture route errors with request context

## Configuration

```python theme={null}
steadwing.init(
    api_key="st_...",           # Required: your API key
    service="my-service",       # Optional: defaults to "default"
    env="PROD",                 # Optional: defaults to "PROD"
    enabled=True,               # Optional: set False to disable
)
```

> [!NOTE]
>
> Only events sent with `env="PROD"` are considered for auto-monitoring. Events from other environments are received but will not trigger automated RCA.

## What Gets Captured

### Exceptions

| Data | Description |
| - | - |
| Stack trace | Full trace with local variables |
| Exception chain | `__cause__` and `__context__` included |
| Breadcrumbs | Last 100 events leading up to the error |
| Request context | Method, path, headers (for web framework routes) |

### Logs

* `logging.error()` and `logging.critical()` are sent as events
* All log levels are recorded as breadcrumbs for context

### HTTP Breadcrumbs

Every outgoing HTTP request is recorded with:

* Method and URL
* Response status code
* Request duration
* Rolling buffer of last 100 entries

## Data Scrubbing

Built-in redaction covers selected structured fields. For supported framework integrations (FastAPI, Django, Flask), the SDK replaces values whose exact field name matches the list below (case-insensitive) in captured request headers. Python also applies this rule to traceback-local variable names.

```
password, passwd, secret, api_key, apikey, token, auth,
authorization, cookie, csrf, session, credit_card, ssn
```

Redaction does **not** scan free-text logs, exception messages, stack traces, URLs or query strings, SQL, or values embedded inside strings. If your application may include sensitive data in these contexts, implement additional scrubbing at the application level before the data reaches Steadwing.

## Framework Support

The SDK auto-detects installed frameworks and patches them automatically. No extra configuration needed.

| Framework | What's Captured |
| - | - |
| **FastAPI** | Route errors with full request context (method, path, headers) |
| **Django** | Middleware-based exception capture with request metadata |
| **Flask** | Error handler integration with request context |
| **SQLAlchemy** | Database query breadcrumbs (query, duration) |
| **Django ORM** | Database query breadcrumbs via cursor wrapper |
| **asyncio** | Unhandled exceptions in async tasks and event loops |

## FAQs

> [accordion] Do I need to change my code?
>
> No. After calling `steadwing.init()`, the SDK hooks into Python's exception handling and logging system automatically.

> [accordion] What's the performance impact?
>
> Minimal. Events are sent asynchronously and the SDK adds negligible overhead to your application. Breadcrumbs are stored in a fixed-size ring buffer.

> [accordion] Can I disable it in development?
>
> Yes. Pass `enabled=False` to `steadwing.init()` and the SDK becomes a no-op no patches are installed and no events are sent.

> [accordion] How does it work with existing error tracking (Sentry, etc.)?
>
> The SDK coexists with other error trackers. It hooks into `sys.excepthook` and the logging module without interfering with other handlers.

> [accordion] Is my data secure?
>
> Selected request header and local-variable fields are scrubbed before transmission. Data is sent over HTTPS to Steadwing's backend. See the Data Scrubbing section for details on what is and isn't covered.

Need help? Contact us at [hello@steadwing.com](mailto:hello@steadwing.com)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.