Skip to main content

kusho-capture

Kusho-capture is a lightweight HTTP traffic capture middleware for Python web applications. It seamlessly integrates with popular frameworks like FastAPI, Flask, and Django to record API traffic for testing, debugging, and monitoring purposes.

Features

  • 🔄 Automatic HTTP traffic capture for API endpoints
  • 🎯 Configurable URL pattern matching
  • 📦 Support for both WSGI and ASGI applications
  • 🔍 Detailed request/response logging
  • ⚡ Async support for modern web frameworks
  • 🎛️ Configurable sampling rate for high-traffic applications
  • 📊 Batch processing of captured events
  • 🚀 Framework auto-detection

Installation

pip install kusho-capture

For framework-specific dependencies:

pip install kusho-capture[fastapi]  # For FastAPI support
pip install kusho-capture[flask]    # For Flask support
pip install kusho-capture[django]   # For Django support

Quick Start

FastAPI Example

from fastapi import FastAPI
from kusho_capture import EventCollector, setup_traffic_capture

app = FastAPI()
collector = EventCollector(
    collector_url="https://your-collector-endpoint.com",
    sample_rate=0.1,
    batch_size=100
)

app = setup_traffic_capture(app, collector, framework="fastapi")

@app.get("/api/items")
async def get_items():
    return {"items": ["item1", "item2"]}

Flask Example

from flask import Flask
from kusho_capture import EventCollector, setup_traffic_capture

app = Flask(__name__)
collector = EventCollector(
    collector_url="https://your-collector-endpoint.com",
    sample_rate=0.1,
    batch_size=100
)

app.wsgi_app = setup_traffic_capture(app.wsgi_app, collector, framework="flask")

@app.route("/api/items")
def get_items():
    return {"items": ["item1", "item2"]}

Django Example

# settings.py
MIDDLEWARE = [
    'kusho_capture.WSGIMiddleware',
    # ... other middleware
]

# somewhere in your configuration
from kusho_capture import EventCollector, setup_traffic_capture

collector = EventCollector(
    collector_url="https://your-collector-endpoint.com",
    sample_rate=0.1,
    batch_size=100
)

application = setup_traffic_capture(application, collector, framework="django")

Configuration

EventCollector Options

  • collector_url: URL of your event collection endpoint
  • batch_size: Number of events to batch before sending (default: 100)
  • flush_interval: Maximum time to wait before sending a batch in seconds (default: 60)
  • max_queue_size: Maximum number of events to queue (default: 10000)
  • sample_rate: Percentage of requests to capture (default: 0.1 = 10%)

Middleware Options

  • url_patterns: List of URL patterns to match for capture (default: ['/api/'])
  • framework: Auto-detected by default, can be explicitly set to 'fastapi', 'flask', or 'django'

Event Data Structure

Captured events include:

  • Timestamp
  • Request path and method
  • Request headers
  • Query parameters
  • Request body (for POST/PUT/PATCH requests)
  • Response status and headers
  • Response time

Contributing

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

License

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

Metadata

Release files for kusho-capture 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for kusho-capture 0.1.0
File Size Uploaded Provenance
kusho_capture-0.1.0.tar.gz 6.3 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for kusho-capture 0.1.0
File Interpreter ABI Platform
kusho_capture-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 13.0 kB

Release files / kusho_capture-0.1.0.tar.gz

Download URL kusho_capture-0.1.0.tar.gz
Size 6.3 kB
Tags Source
SHA-256 checksum
How to use checksums
7d7e925e781d3e3cbb17ef0a2d67397aeebb5cba37f4427a0efc865940d046c4
BLAKE2b-256 checksum
How to use checksums
1a35411bb1fa50a3cbfd2bca1838cceed1856135003ef81b203ddabbb9db8b84
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.13.1

Release files / kusho_capture-0.1.0-py3-none-any.whl

Download URL kusho_capture-0.1.0-py3-none-any.whl
Size 6.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
396748912921fb95b9d9bb9f9f9c3c09cc517a1852d893096a86f5619f4061c7
BLAKE2b-256 checksum
How to use checksums
cad3c34db2dd25823e8dc0c2c78d21fe0247c76fc942b1d72bdd70f8743efcc0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.13.1

Security for kusho-capture 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page