Metadata-Version: 2.4
Name: townhouse
Version: 0.4.0
Summary: Townhouse error tracking for Python: FastAPI, Starlette, Flask, Django, logging and plain scripts
Author: Townhouse
License: MIT
Project-URL: Homepage, https://townhouse.dev
Keywords: townhouse,error tracking,monitoring,fastapi,flask,django
Classifier: Programming Language :: Python :: 3
Classifier: Framework :: FastAPI
Classifier: Framework :: Flask
Classifier: Framework :: Django
Classifier: Topic :: System :: Monitoring
Requires-Python: >=3.9
Description-Content-Type: text/markdown
Provides-Extra: test
Requires-Dist: pytest>=8; extra == "test"
Requires-Dist: fastapi; extra == "test"
Requires-Dist: httpx; extra == "test"
Requires-Dist: flask; extra == "test"
Requires-Dist: django; extra == "test"

# townhouse (Python)

Error tracking for Python apps, sent to Townhouse: errors grouped into problems, linked to the part of your app they
break, and fixable with your own model.

```bash
pip install townhouse
```

```python
import os, townhouse
townhouse.init(key=os.environ["TOWNHOUSE_KEY"], release=os.environ.get("GIT_SHA"), environment="production")
```

`TOWNHOUSE_KEY` is your project's ingest key (`gh_live_...`), from the Townhouse app. A DSN works too:
`townhouse.init(dsn="https://gh_live_xxx@api.townhouse.dev/<projectId>")`.

## Frameworks

FastAPI and Starlette:

```python
from townhouse.integrations.asgi import TownhouseMiddleware
app.add_middleware(TownhouseMiddleware)
```

Flask:

```python
from townhouse.integrations.flask import init_app
init_app(app)
```

Django (`settings.py`):

```python
MIDDLEWARE = ["townhouse.integrations.django.TownhouseMiddleware", *MIDDLEWARE]
```

Logging (log lines become breadcrumbs, `ERROR` and above become events):

```python
import logging
from townhouse.integrations.logging import TownhouseHandler
logging.getLogger().addHandler(TownhouseHandler())
```

## What it sends

- Uncaught exceptions from the main thread and other threads, with the process exiting as it would have.
- Unhandled view or endpoint exceptions and 5xx responses, with the route pattern.
- Frames ordered outermost first, marked in-app for your own files and not for installed packages.
- Emails and tokens masked, secret-looking fields redacted, query strings dropped, and only four request headers kept.
- Batches gzipped from a background thread, flushed at exit. No dependencies outside the standard library.

Manual capture: `townhouse.capture_exception(exc)`, `townhouse.capture_message("text", "warning")`,
`townhouse.add_breadcrumb("query", "SELECT orders")`, `townhouse.set_tag("tenant", "acme")`, `townhouse.set_user("u_123")`.

## Developing and testing

The tests cover the client and the FastAPI, Flask and Django integrations, so they need those frameworks. Install the
package in editable mode with its `test` extra, then run pytest from this folder:

```bash
python3 -m venv .venv && . .venv/bin/activate
pip install -e ".[test]"
python -m pytest -q
```
