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.0.tar.gz (6.8 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.0-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: api_monitor_sdk-0.1.0.tar.gz
  • Upload date:
  • Size: 6.8 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.0.tar.gz
Algorithm Hash digest
SHA256 35af31e3a3e8fc47b0b91de2f47c4ca9a091cd939cacbd2af6b89b10af6fa677
MD5 63ab11e96a5eb64a5b3e78fbaf5cacfa
BLAKE2b-256 ee528bb9c76e6e9e0dc5784fc05abb1a7567f8f2cdcedee986d49157073c944b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for api_monitor_sdk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cd264a537363dfc96cc1b61e45ea59272be793c67c20ab4a1c477c07c4aca8e0
MD5 876a4538a4c7ec58aa499059ec2f20cc
BLAKE2b-256 84bac76a31b25aeec671ff2bdcd451aaec2d1b2a2f99d4ea955cc6e74abc33a6

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