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
Metadata
Release files for afen 1.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| afen-1.0.2.tar.gz | 3.7 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| afen-1.0.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 7.7 kB
Release files / afen-1.0.2.tar.gz
| Download URL | afen-1.0.2.tar.gz |
|---|---|
| Size | 3.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
16fa2ae7365f9e6525a555fa9de962adc358fdac4da059155c2da00365c98d60
|
|
BLAKE2b-256 checksum How to use checksums |
4d43a7d367ce76c0987df54fe034299f8b562b4387b82277669ec4c4d5a634a3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.3
|
Release files / afen-1.0.2-py3-none-any.whl
| Download URL | afen-1.0.2-py3-none-any.whl |
|---|---|
| Size | 4.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
455c28ed3f754c83884bf72246ef1ce30f3849f6f3ee21530ec22e59c9d3524e
|
|
BLAKE2b-256 checksum How to use checksums |
a4a87eb41638f909a2808db6a6edc01d154d102a1b37659558a2c52f88fa3a4f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.3
|
Security for afen 1.0.2
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.