Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

afen-1.0.1.tar.gz (3.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

afen-1.0.1-py3-none-any.whl (3.4 kB view details)

Uploaded Python 3

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

Hashes for afen-1.0.1.tar.gz
Algorithm Hash digest
SHA256 c23de91b906fff2f742e173625ba9eed56f5888e1a36558b47cc3d14023ffcf7
MD5 67c3441681851b906d5d1ffb36e46e3a
BLAKE2b-256 c0f4f080940321fec0dfd6ccd9068d1613376c6c3ea63c1f828555c75bd960fa

See more details on using hashes here.

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

Hashes for afen-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1459b1327d2d2d8692a0c914092808662dc4d4f9e8330f92c73da87479601849
MD5 d52eafd8247cf5c2375b438d69ef8f86
BLAKE2b-256 5372b955c5ef0867d8edc40482958871792fc46b7d7163d7c0dc8964f885b005

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page