Skip to main content

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.

pip install townhouse
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:

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

Flask:

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

Django (settings.py):

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

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

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:

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

Metadata

Release files for townhouse 0.4.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 townhouse 0.4.0
File Size Uploaded Provenance Actions
townhouse-0.4.0.tar.gz 14.5 kB Without provenance Details for townhouse-0.4.0.tar.gz

Built distribution (wheel)

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

Total release size: 27.8 kB

Release files / townhouse-0.4.0.tar.gz

Download URL townhouse-0.4.0.tar.gz
Size 14.5 kB
Tags Source
SHA-256 checksum
How to use checksums
4ce00cce8f271371be31a6d56ba872d818cb3fd85effb2e4230bcf92616ff3d1
BLAKE2b-256 checksum
How to use checksums
c6aa8365f0cca6a0590c97b017da8df62045c558d068094592f98ad9226bdb6d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.4

Release files / townhouse-0.4.0-py3-none-any.whl

Download URL townhouse-0.4.0-py3-none-any.whl
Size 13.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8286124fef3e8d064820d5da45392916c2cd795277fa7fa3042848661c533b14
BLAKE2b-256 checksum
How to use checksums
adc0480ab583712e7967c90924e4af84892b8e3acd3739425e48a6ee27558fff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.4

Security for townhouse 0.4.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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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.

Release history Release notifications | RSS feed

This release

0.4.0 This release

2 release files No provenance

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