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.2.tar.gz (3.7 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.2-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file afen-1.0.2.tar.gz.

File metadata

  • Download URL: afen-1.0.2.tar.gz
  • Upload date:
  • Size: 3.7 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.2.tar.gz
Algorithm Hash digest
SHA256 16fa2ae7365f9e6525a555fa9de962adc358fdac4da059155c2da00365c98d60
MD5 e910c7b03339458b3280fbe2b3edf191
BLAKE2b-256 4d43a7d367ce76c0987df54fe034299f8b562b4387b82277669ec4c4d5a634a3

See more details on using hashes here.

File details

Details for the file afen-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: afen-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 4.0 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 455c28ed3f754c83884bf72246ef1ce30f3849f6f3ee21530ec22e59c9d3524e
MD5 d5af80f0851e99a835572cdd502003f7
BLAKE2b-256 a4a87eb41638f909a2808db6a6edc01d154d102a1b37659558a2c52f88fa3a4f

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