Skip to main content

Automatic HTTP request monitoring for Python applications

Project description

API Monitor SDK

Automatically monitor all HTTP requests in your Python application with zero code changes.

Installation

pip install api-monitor-sdk

Quick Start

from apimonitor import Monitor
import requests

# Initialize monitor
monitor = Monitor(api_key="your-api-key-from-dashboard")
monitor.start()

# All HTTP requests now automatically tracked
response = requests.get("https://api.github.com/users/octocat")
# Metrics sent in background - your app continues normally

# Optional: track custom business events
monitor.track_custom("payment_processed", amount=100, user_id="123")

Features

  • Zero-code monitoring - Just call monitor.start()
  • Supports multiple libraries - requests, httpx, aiohttp
  • Background sending - Non-blocking, won't slow your app
  • Batching - Sends 100 requests or every 10 seconds
  • Offline queue - Buffers metrics when network fails
  • Sampling - Monitor 10% of traffic to reduce overhead
  • Thread-safe - Works with multi-threaded applications

Configuration

monitor = Monitor(
    api_key="your-api-key",
    endpoint="https://api.yourmonitor.com/ingest",  # Custom endpoint
    batch_size=100,              # Send after N requests
    batch_timeout=10,            # Or after N seconds
    sampling_rate=1.0,           # 1.0 = 100%, 0.1 = 10%
    offline_mode=True,           # Buffer when network fails
    debug=True                   # Print debug logs
)
monitor.start()

Framework Examples

Flask

from flask import Flask
from apimonitor import Monitor

app = Flask(__name__)

monitor = Monitor(api_key="your-key")
monitor.start()

@app.route("/")
def home():
    # Any requests made here are auto-tracked
    return "Hello World"

FastAPI

from fastapi import FastAPI
from apimonitor import Monitor

app = FastAPI()

monitor = Monitor(api_key="your-key")
monitor.start()

@app.get("/")
def home():
    return {"message": "Hello World"}

Django

# In your settings.py or apps.py

from apimonitor import Monitor

monitor = Monitor(api_key="your-key")
monitor.start()

Advanced Usage

Custom Events

Track business-specific events:

# Track payment
monitor.track_custom("payment_processed", 
                     amount=99.99, 
                     currency="USD",
                     user_id="user_123")

# Track signup
monitor.track_custom("user_signup",
                     email="user@example.com",
                     plan="premium")

Stopping the Monitor

# Gracefully stop and flush remaining metrics
monitor.stop()

How It Works

  1. Interception - Monkey-patches HTTP libraries (requests, httpx, aiohttp)
  2. Collection - Captures timing, status, URL, errors
  3. Batching - Queues metrics until batch size or timeout reached
  4. Sending - Background thread sends to API endpoint
  5. Offline Queue - If network fails, saves to local SQLite database
  6. Auto-flush - On program exit, sends remaining metrics

Supported Libraries

  • requests - Most popular HTTP library
  • httpx - Modern async HTTP library
  • aiohttp - Async HTTP client/server
  • 🚧 urllib3 - Coming soon
  • 🚧 http.client - Coming soon

Requirements

  • Python 3.8+
  • requests (automatically installed)

License

MIT

Support

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

api_monitor_sdk-0.1.2.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

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

api_monitor_sdk-0.1.2-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file api_monitor_sdk-0.1.2.tar.gz.

File metadata

  • Download URL: api_monitor_sdk-0.1.2.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.11

File hashes

Hashes for api_monitor_sdk-0.1.2.tar.gz
Algorithm Hash digest
SHA256 f1c3a58566d8236b1cc9b148d7e7021bcec15acf29f28d51f10e3e3bad660fe2
MD5 06bd499edac4cf38322fe485f0940108
BLAKE2b-256 1947c6588436dcc75094b46b7032ab8c0fae2bccaa8a283a78ab2826c7c89335

See more details on using hashes here.

File details

Details for the file api_monitor_sdk-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for api_monitor_sdk-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b58a91c61d1415ae41d90736dc75abded9c0ced5f55cf5ce2ba89d398f9e1a2c
MD5 ad7cd3826f70615c3830aac771690703
BLAKE2b-256 bc0a7289a065f3499c063857821aa6249e8d856f740d667ccec633451353d80d

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