Skip to main content

Python SDK for API Failure Recorder - Track and monitor API failures

Project description

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

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

afir_sdk-0.1.0.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

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

afir_sdk-0.1.0-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file afir_sdk-0.1.0.tar.gz.

File metadata

  • Download URL: afir_sdk-0.1.0.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for afir_sdk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b1fe824ea5dbb16db9162f8fcfbcdd0a2f89a612d9b896c2af80346fef2831b1
MD5 a11df05f576c91d9fcf3bd04170d3aa7
BLAKE2b-256 b742a068ea4070c6143e1e9fcf2b0df72674f7ae04829e0ea87cef20982fd306

See more details on using hashes here.

File details

Details for the file afir_sdk-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: afir_sdk-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for afir_sdk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 aa111057eb21ff4263f54e4c465bfc33958b105b7ff8bf6805745d068326d68c
MD5 ca29762586e75707385195a488ef7c30
BLAKE2b-256 a082b29c34b7a94208575e1832183821090715b5965072826c7993805b9d0149

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