Self-hosted error monitoring SDK for Python applications. Compatible with FastAPI, Flask, Django, Celery, and any Python application.
pip install errorwatch
# With framework extras
pip install errorwatch[fastapi]
pip install errorwatch[flask]
pip install errorwatch[django]
pip install errorwatch[celery]
pip install errorwatch[sqlalchemy]
pip install errorwatch[all]import errorwatch
errorwatch.init(
api_key="ew_live_your_api_key",
endpoint="https://api.errorwatch.io",
environment="production",
release="1.0.0",
)
# Automatic capture via sys.excepthook — unhandled exceptions are sent automatically
# Manual capture
try:
risky_operation()
except Exception as e:
errorwatch.capture_exception(e)
# Capture a message
errorwatch.capture_message("Deployment completed", level="info")from fastapi import FastAPI
import errorwatch
from errorwatch.integrations.fastapi import ErrorWatchMiddleware
app = FastAPI()
errorwatch.init(
api_key="ew_live_xxx",
endpoint="https://api.errorwatch.io",
)
app.add_middleware(ErrorWatchMiddleware)from flask import Flask
import errorwatch
from errorwatch.integrations.flask import ErrorWatchFlask
app = Flask(__name__)
errorwatch.init(
api_key="ew_live_xxx",
endpoint="https://api.errorwatch.io",
)
ErrorWatchFlask(app)# settings.py
MIDDLEWARE = [
"errorwatch.integrations.django.ErrorWatchMiddleware",
# ... other middleware
]
# manage.py or wsgi.py (before Django starts)
import errorwatch
errorwatch.init(
api_key="ew_live_xxx",
endpoint="https://api.errorwatch.io",
)import errorwatch
from errorwatch.integrations.celery import install
errorwatch.init(
api_key="ew_live_xxx",
endpoint="https://api.errorwatch.io",
)
install() # Hooks into Celery signalserrorwatch.set_user({
"id": "123",
"email": "user@example.com",
"username": "johndoe",
})errorwatch.add_breadcrumb(
message="User clicked checkout",
category="ui",
data={"button": "checkout-btn"},
)with errorwatch.start_transaction("process-order", op="task") as txn:
with txn.start_child("db.query", description="SELECT * FROM orders") as span:
orders = db.query("SELECT * FROM orders")
with txn.start_child("http.client", description="POST /api/payment") as span:
response = httpx.post("/api/payment")
span.set_data("http.status_code", response.status_code)from sqlalchemy import create_engine
from errorwatch.integrations.sqlalchemy import install
engine = create_engine("postgresql://...")
install(engine) # Auto-traces all SQL queriesimport httpx
from errorwatch.integrations.httpx_integration import install_hooks
client = httpx.Client()
install_hooks(client) # Auto-traces outgoing HTTP requestsimport logging
from errorwatch.integrations.logging_handler import ErrorWatchHandler
handler = ErrorWatchHandler(level=logging.ERROR)
logging.getLogger().addHandler(handler)errorwatch.init(
# Required
api_key="ew_live_xxx",
endpoint="https://api.errorwatch.io",
# Optional
environment="production", # Default: "production"
release="1.2.3", # App version
enabled=True, # Kill switch
sample_rate=1.0, # Error sampling (0.0-1.0)
# Hooks
before_send=lambda event: event, # Filter/modify events, return None to drop
# Transport
transport={
"timeout": 5.0,
"retry_attempts": 2,
"circuit_breaker_threshold": 5,
"circuit_breaker_cooldown": 60.0,
},
# Breadcrumbs
breadcrumbs={"enabled": True, "max_count": 100},
# APM
apm={"enabled": True, "sample_rate": 1.0},
# Logs
logs={"enabled": True, "level": "error"},
)- Python >= 3.10
- httpx >= 0.24.0
MIT