Skip to main content

AFIR SDK - Python SDK for API Failure Recorder

A lightweight Python SDK for monitoring and tracking API failures in your web applications.

Installation

Using pip

pip install afir-sdk

Using uv

uv add afir-sdk

Quick Start

FastAPI Integration

from fastapi import FastAPI
from afir_sdk import AFIRConfig
from afir_sdk.middleware.fastapi import AFIRMiddleware

# Configure the SDK
config = AFIRConfig(
    api_key="your-api-key",
    endpoint="http://localhost:8000/api/v1",  # Your AFIR server
    service_name="my-api",
    environment="prod"
)

# Create your app
app = FastAPI()

# Add the middleware
app.add_middleware(AFIRMiddleware, config=config)

# Your routes here
@app.get("/users/{user_id}")
def get_user(user_id: int):
    # If this returns a 4xx/5xx, it will be tracked automatically
    return {"user_id": user_id}

Manual Event Tracking

from afir_sdk import AFIRClient, AFIRConfig

config = AFIRConfig(
    api_key="your-api-key",
    service_name="my-service",
    environment="prod"
)

client = AFIRClient(config)

# Track an event manually
client.track_event(
    method="POST",
    path="/api/payment",
    status_code=500,
    latency_ms=1500,
    error_payload={"error": "Payment gateway timeout"}
)

# Always shutdown gracefully
client.shutdown()

Configuration Options

Option Type Default Description
api_key str required Your AFIR API key
endpoint str http://localhost:8000/api/v1 AFIR server URL
service_name str unknown-service Name of your service
environment str dev Environment (prod, staging, dev)
enabled bool True Enable/disable tracking
batch_size int 10 Events per batch
flush_interval float 5.0 Seconds between flushes
ignored_paths list ["/health", "/healthz", ...] Paths to skip
min_status_code int 400 Minimum status to track

Features

  • ✅ Automatic failure detection (4xx/5xx responses)
  • ✅ Request batching for efficiency
  • ✅ Background thread for non-blocking sends
  • ✅ Correlation ID support for tracing
  • ✅ Automatic header redaction (Authorization, Cookie)
  • ✅ Graceful shutdown with flush

License

MIT

Metadata

Release files for afir-sdk 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for afir-sdk 0.1.0
File Size Uploaded Provenance
afir_sdk-0.1.0.tar.gz 5.4 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for afir-sdk 0.1.0
File Interpreter ABI Platform
afir_sdk-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 12.7 kB

Release files / afir_sdk-0.1.0.tar.gz

Download URL afir_sdk-0.1.0.tar.gz
Size 5.4 kB
Tags Source
SHA-256 checksum
How to use checksums
b1fe824ea5dbb16db9162f8fcfbcdd0a2f89a612d9b896c2af80346fef2831b1
BLAKE2b-256 checksum
How to use checksums
b742a068ea4070c6143e1e9fcf2b0df72674f7ae04829e0ea87cef20982fd306
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.7

Release files / afir_sdk-0.1.0-py3-none-any.whl

Download URL afir_sdk-0.1.0-py3-none-any.whl
Size 7.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
aa111057eb21ff4263f54e4c465bfc33958b105b7ff8bf6805745d068326d68c
BLAKE2b-256 checksum
How to use checksums
a082b29c34b7a94208575e1832183821090715b5965072826c7993805b9d0149
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.7

Security for afir-sdk 0.1.0

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.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page