Skip to main content

SDK for tracking API requests

Project description

API Insights SDK

PyPI version Python versions License: MIT

A lightweight Python SDK for tracking and monitoring API requests across Django, Flask, FastAPI, and other Python HTTP frameworks. The SDK automatically collects HTTP request/response metadata and sends it to the API Insights server for comprehensive analytics and insights.

Features

  • Multi-Framework Support: Works seamlessly with Django, Flask, FastAPI, and any Python HTTP framework
  • Automatic Tracking: Minimal code changes required - use decorators or middleware
  • Async Processing: Background worker thread for non-blocking data transmission
  • Configurable Batching: Efficient batch processing of request metadata
  • Low Overhead: Minimal performance impact on your applications
  • Python 3.8+: Compatible with modern Python versions

Installation

Install the SDK using pip:

pip install api-insights-sdk

Quick Start

Basic Usage with Decorator

from api_insights_sdk import APIInsightsTracker, track_api

# Initialize the tracker
tracker = APIInsightsTracker(api_key='your_api_key')

# Use the decorator on your endpoints
@app.route('/users')
@track_api(tracker)
def get_users():
    return {'users': []}

Django Integration

Add the middleware to your settings.py:

MIDDLEWARE = [
    # ... other middleware
    'sdk.django_middleware.APIInsightsMiddleware',
]

# Configure your API key
API_INSIGHTS_API_KEY = 'your_api_key'

Flask Integration

from flask import Flask
from sdk.flask_extension import APIInsightsFlask

app = Flask(__name__)
insights = APIInsightsFlask(app, api_key='your_api_key')

@app.route('/users')
def get_users():
    return {'users': []}

Configuration

APIInsightsTracker Parameters

tracker = APIInsightsTracker(
    api_key='your_api_key',                    # Your API Insights project key
    endpoint='https://api.yourservice.com/api/v1/track/',  # Tracking endpoint
    batch_size=100,                             # Requests to batch before sending
    flush_interval=5.0,                         # Seconds between auto-flushes
    async_mode=True,                            # Enable async processing
    timeout=5.0,                                # Request timeout in seconds
)

How It Works

  1. Request Capture: The SDK intercepts HTTP requests and responses
  2. Metadata Collection: Raw HTTP metadata is collected (headers, status codes, latency, etc.)
  3. Batching: Requests are batched for efficient transmission
  4. Async Transmission: Data is sent to the API Insights server in the background
  5. Server-Side Analytics: The API Insights server processes the raw data to generate insights and analytics

API Key

To use the API Insights SDK, you need an API key from your API Insights project. You can obtain this from your API Insights dashboard.

Performance Considerations

  • Asynchronous Processing: By default, the SDK uses a background worker thread to send data without blocking your application
  • Batch Processing: Configure batch_size and flush_interval based on your traffic patterns
  • Minimal Overhead: The SDK is designed to have minimal impact on your application's performance

Error Handling

The SDK gracefully handles network errors and timeouts:

  • Failed requests are logged but do not affect your application
  • Errors are reported via Python's standard logging module
import logging

# Enable debug logging to see SDK operations
logging.getLogger('api_insights_sdk').setLevel(logging.DEBUG)

Supported Frameworks

  • Django: Via middleware integration
  • Flask: Via extension wrapper
  • FastAPI: Via decorator support
  • Any WSGI/ASGI Application: Via the decorator pattern

Python Versions

The SDK requires Python 3.8 or higher.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support

For issues, feature requests, or questions, please visit our GitHub repository or contact support at rahulrathod315@gmail.com.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Changelog

Version 1.0.0 (2026-01-31)

  • Initial release
  • Support for Django middleware
  • Support for Flask extension
  • Decorator-based tracking for any framework
  • Async batch processing with configurable parameters

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_insights_sdk-1.0.0.tar.gz (11.3 kB view details)

Uploaded Source

Built Distribution

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

api_insights_sdk-1.0.0-py3-none-any.whl (12.6 kB view details)

Uploaded Python 3

File details

Details for the file api_insights_sdk-1.0.0.tar.gz.

File metadata

  • Download URL: api_insights_sdk-1.0.0.tar.gz
  • Upload date:
  • Size: 11.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for api_insights_sdk-1.0.0.tar.gz
Algorithm Hash digest
SHA256 ad836d80bc9d60c9311f3799de03d9ce6733b8db0eaae5b8a61834677fe2f1b4
MD5 7d044c5519a0c5cd25a1816308fb1bb0
BLAKE2b-256 8562ecd7205c2313674212a5818c495bdd85b2b35465a3f33f983dfca9755b53

See more details on using hashes here.

File details

Details for the file api_insights_sdk-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for api_insights_sdk-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4a741948a2c66d4cd32bc2feea237f85bb6342ecda6f193aaaa2880a2d2929d5
MD5 1c857d04869c3f1aec2366be7b29f8ec
BLAKE2b-256 2efe4cb6a8ebbc09b22111700b2018dbc073a61cc98e0eacc1dd762e29fdb203

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