API Insights SDK
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
- Request Capture: The SDK intercepts HTTP requests and responses
- Metadata Collection: Raw HTTP metadata is collected (headers, status codes, latency, etc.)
- Batching: Requests are batched for efficient transmission
- Async Transmission: Data is sent to the API Insights server in the background
- 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_sizeandflush_intervalbased 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
Metadata
Release files for api-insights-sdk 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| api_insights_sdk-1.0.0.tar.gz | 11.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| api_insights_sdk-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 23.9 kB
Release files / api_insights_sdk-1.0.0.tar.gz
| Download URL | api_insights_sdk-1.0.0.tar.gz |
|---|---|
| Size | 11.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ad836d80bc9d60c9311f3799de03d9ce6733b8db0eaae5b8a61834677fe2f1b4
|
|
BLAKE2b-256 checksum How to use checksums |
8562ecd7205c2313674212a5818c495bdd85b2b35465a3f33f983dfca9755b53
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.13
|
Release files / api_insights_sdk-1.0.0-py3-none-any.whl
| Download URL | api_insights_sdk-1.0.0-py3-none-any.whl |
|---|---|
| Size | 12.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4a741948a2c66d4cd32bc2feea237f85bb6342ecda6f193aaaa2880a2d2929d5
|
|
BLAKE2b-256 checksum How to use checksums |
2efe4cb6a8ebbc09b22111700b2018dbc073a61cc98e0eacc1dd762e29fdb203
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.13
|