Afen Python SDK - capture and send runtime errors to Afen
Project description
Afen Python SDK
Capture runtime errors and send them to an Afen instance.
- Automatic capture of unhandled exceptions via
sys.excepthook - Manual capture with optional context
- Async support
- Django middleware integration
- Python ≥ 3.8, zero heavy dependencies
Installation
pip install afen-client
Quick Start
from afen.client import AfenClient
client = AfenClient(
api_url="http://localhost:3000",
api_key="your-api-token",
service_name="my-service",
)
That's it. A global sys.excepthook is registered automatically — all unhandled exceptions are forwarded to Afen without any further setup.
Manual Capture
try:
process_payment(payload)
except Exception as e:
client.capture(e, context={"order_id": payload["id"]})
raise
Async Support
async def handler(request):
try:
await process_payment(payload)
except Exception as e:
await client.capture_async(e, context={"order_id": payload["id"]})
raise
Disable Auto-Capture
client = AfenClient(
api_url="http://localhost:3000",
api_key="your-api-token",
service_name="my-service",
auto_capture=False,
)
Django Integration
# settings.py
MIDDLEWARE = [
"afen.integrations.django.AfenMiddleware",
...
]
AFEN = {
"API_URL": "http://localhost:3000",
"API_KEY": "your-api-token",
"SERVICE_NAME": "my-django-app",
}
Captures all unhandled Django exceptions and attaches request.path, request.method, and response status as context.
Configuration
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
api_url |
str |
✓ | — | Afen server URL |
api_key |
str |
✓ | — | API key |
service_name |
str |
✓ | — | Identifies the source service |
environment |
str |
"development" |
Deployment environment | |
release |
str |
None |
Release or version tag | |
auto_capture |
bool |
True |
Register global exception hook | |
timeout |
int |
5 |
Request timeout in seconds |
Requirements
- Python ≥ 3.8
requests≥ 2.28.0
License
MIT © Anamn
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 afen-1.0.1.tar.gz.
File metadata
- Download URL: afen-1.0.1.tar.gz
- Upload date:
- Size: 3.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c23de91b906fff2f742e173625ba9eed56f5888e1a36558b47cc3d14023ffcf7
|
|
| MD5 |
67c3441681851b906d5d1ffb36e46e3a
|
|
| BLAKE2b-256 |
c0f4f080940321fec0dfd6ccd9068d1613376c6c3ea63c1f828555c75bd960fa
|
File details
Details for the file afen-1.0.1-py3-none-any.whl.
File metadata
- Download URL: afen-1.0.1-py3-none-any.whl
- Upload date:
- Size: 3.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1459b1327d2d2d8692a0c914092808662dc4d4f9e8330f92c73da87479601849
|
|
| MD5 |
d52eafd8247cf5c2375b438d69ef8f86
|
|
| BLAKE2b-256 |
5372b955c5ef0867d8edc40482958871792fc46b7d7163d7c0dc8964f885b005
|