Catalog PyPI
PACKAGE EXPLORERView in registry

afir-sdk

PyPI

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

apifailuresincidentsmonitoringobservability
Versions collected1
Direct dependencies3From release 0.1.0
Last observed20 Oct, 21:07 UTC

README

Version 0.1.0 documentation

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

OptionTypeDefaultDescription
api_keystrrequiredYour AFIR API key
endpointstrhttp://localhost:8000/api/v1AFIR server URL
service_namestrunknown-serviceName of your service
environmentstrdevEnvironment (prod, staging, dev)
enabledboolTrueEnable/disable tracking
batch_sizeint10Events per batch
flush_intervalfloat5.0Seconds between flushes
ignored_pathslist["/health", "/healthz", ...]Paths to skip
min_status_codeint400Minimum 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

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Versions 1

Collected releases
VersionPublishedDirect dependenciesOpen version
0.1.030 Jan 20263

Package advisories

0
No matching advisories collected

This describes our collected data; it is not a security assessment.

Repository

PENDING
api-failure-recorder/afir-sdk

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 21:07 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package:e8e9671cf9771c97038787dda2c9d69596d682ff9fef677b23319442c9cf72e3