Python SDK for Checkend error monitoring
Project description
Checkend Python SDK
Python SDK for Checkend error monitoring. Zero dependencies, async by default.
Features
- Zero dependencies - Uses only Python standard library
- Async by default - Non-blocking error sending via background thread
- Framework integrations - Django, Flask, FastAPI/Starlette
- Automatic context - Request, user, and custom context tracking
- Sensitive data filtering - Automatic scrubbing of passwords, tokens, etc.
- Testing utilities - Capture errors in tests without sending
Installation
pip install checkend
Quick Start
import checkend
# Configure the SDK
checkend.configure(api_key='your-api-key')
# Report an error
try:
do_something()
except Exception as e:
checkend.notify(e)
Configuration
import checkend
checkend.configure(
api_key='your-api-key', # Required: Your Checkend ingestion key
endpoint='https://app.checkend.com', # Optional: Custom endpoint
environment='production', # Optional: Auto-detected if not set
enabled=True, # Optional: Enable/disable reporting
async_send=True, # Optional: Async sending (default: True)
timeout=15, # Optional: HTTP timeout in seconds
filter_keys=['password', 'secret'], # Optional: Additional keys to filter
ignored_exceptions=[KeyError], # Optional: Exceptions to ignore
debug=False, # Optional: Enable debug logging
)
Environment Variables
CHECKEND_API_KEY=your-api-key
CHECKEND_ENDPOINT=https://your-server.com
CHECKEND_ENVIRONMENT=production
CHECKEND_DEBUG=true
Manual Error Reporting
import checkend
# Basic error reporting
try:
risky_operation()
except Exception as e:
checkend.notify(e)
# With additional context
try:
process_order(order_id)
except Exception as e:
checkend.notify(
e,
context={'order_id': order_id},
user={'id': user.id, 'email': user.email},
tags=['orders', 'critical'],
fingerprint='order-processing-error',
)
# Synchronous sending (blocks until sent)
response = checkend.notify_sync(e)
print(f"Notice ID: {response['id']}")
Context & User Tracking
import checkend
# Set context for all errors in this request
checkend.set_context({
'order_id': 12345,
'feature_flag': 'new-checkout',
})
# Set user information
checkend.set_user({
'id': user.id,
'email': user.email,
'name': user.name,
})
# Set request information
checkend.set_request({
'url': request.url,
'method': request.method,
'headers': dict(request.headers),
})
# Clear all context (call at end of request)
checkend.clear()
Framework Integrations
Django
# settings.py
MIDDLEWARE = [
'checkend.integrations.django.DjangoMiddleware',
# ... other middleware
]
# Configure in settings.py or apps.py
import checkend
checkend.configure(api_key='your-api-key')
Flask
from flask import Flask
import checkend
from checkend.integrations.flask import init_flask
app = Flask(__name__)
checkend.configure(api_key='your-api-key')
init_flask(app)
FastAPI
from fastapi import FastAPI
import checkend
from checkend.integrations.fastapi import init_fastapi
app = FastAPI()
checkend.configure(api_key='your-api-key')
init_fastapi(app)
Testing
Use the Testing class to capture errors without sending them:
import checkend
from checkend import Testing
def test_error_reporting():
# Enable testing mode
Testing.setup()
checkend.configure(api_key='test-key')
try:
# Trigger an error
raise ValueError("Test error")
except Exception as e:
checkend.notify(e)
# Assert on captured notices
assert Testing.has_notices()
assert Testing.notice_count() == 1
notices = Testing.notices()
assert notices[0].error_class == 'ValueError'
# Clean up
Testing.teardown()
checkend.reset()
Filtering Sensitive Data
By default, these keys are filtered: password, secret, token, api_key, authorization, credit_card, cvv, ssn, etc.
Add custom keys:
checkend.configure(
api_key='your-api-key',
filter_keys=['custom_secret', 'internal_token'],
)
Filtered values appear as [FILTERED] in the dashboard.
Ignoring Exceptions
checkend.configure(
api_key='your-api-key',
ignored_exceptions=[
KeyboardInterrupt,
SystemExit,
'MyCustomException',
'django.http.Http404',
],
)
Before Notify Callbacks
def add_extra_context(notice):
notice.context['server'] = 'web-1'
return True # Return False to skip sending
def filter_specific_errors(notice):
if 'ignore-me' in notice.message:
return False # Don't send this error
return True
checkend.configure(
api_key='your-api-key',
before_notify=[add_extra_context, filter_specific_errors],
)
Graceful Shutdown
The SDK automatically flushes pending notices on program exit. For manual control:
# Wait for pending notices to send
checkend.flush(timeout=10)
# Stop the worker thread
checkend.stop(timeout=5)
Requirements
- Python 3.9+
- No external dependencies
Development
# Install dev dependencies
pip install -e ".[dev]"
# Run tests
pytest
# Run tests with coverage
pytest --cov=checkend
# Lint
ruff check .
ruff format .
License
MIT License - see LICENSE for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file checkend-1.0.0.tar.gz.
File metadata
- Download URL: checkend-1.0.0.tar.gz
- Upload date:
- Size: 27.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
778485d416d506c1e8359f60a4b5f6a9ad3da8ab06a66f4e25d2565468b9304b
|
|
| MD5 |
1db3ae3d99fd61a41c704886262d15a2
|
|
| BLAKE2b-256 |
1c276c030030cb5bb8547d22b79be15fbb3679c31834caf4d2b97cd64c89dee3
|
File details
Details for the file checkend-1.0.0-py3-none-any.whl.
File metadata
- Download URL: checkend-1.0.0-py3-none-any.whl
- Upload date:
- Size: 26.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d449f633048872d6147389e2f40e3923e89cb3b63156a5a055e6551f463becf0
|
|
| MD5 |
71152d3f136ec582a04b367c37fa15ce
|
|
| BLAKE2b-256 |
1a7a72a024193ffc40c4c59077ce5299ae0906b325f6ad16b44e3b577bb92213
|