Skip to main content

Python middleware for API monitoring and analytics

Project description

pyapimon

Python middleware for API monitoring and analytics. Integrates directly into your web framework to capture request/response data, store it locally, and provide a rich CLI for exploration and insights.

Install

pip install pyapimon

With LLM-powered insights:

pip install pyapimon[llm]

Quickstart

FastAPI

from fastapi import FastAPI
from pyapimon import FastAPIMiddleware

app = FastAPI()
app.add_middleware(FastAPIMiddleware)

Django

Add to settings.py:

MIDDLEWARE = [
    "pyapimon.middleware.django.DjangoMiddleware",
    # ... other middleware
]

# Optional
PYAPIMON = {
    "db_path": "/tmp/apimon.db",
    "flush_interval": 3,
}

Flask

from flask import Flask
from pyapimon import FlaskMiddleware

app = Flask(__name__)
FlaskMiddleware(app)

CLI Commands

CLI commands now support interactive timeframe selection (e.g., past 24h, 7d, 30d, all-time). If you do not provide the --hours option, pyapimon will prompt you automatically.

pyapimon stats            Route statistics table
pyapimon requests         Recent request list
pyapimon request <id>     Single request detail
pyapimon ui               Interactive TUI dashboard
pyapimon dashboard        Rich terminal dashboard
pyapimon insights         LLM-powered analysis
pyapimon suggestions      Rule-based suggestions
pyapimon graph            ASCII time-series graph
pyapimon export <file>    Export analytics to JSON
pyapimon clear            Clear all captured data
pyapimon doctor           Verify middleware is working
pyapimon version          Show version

Configuration

All options are optional with sane defaults:

Option Default Description
db_path "apimon.db" SQLite database file path
flush_interval 2.0 Seconds between batch flushes
flush_size 100 Max buffered records before force-flush
record_bodies True Capture request/response bodies
body_max_length 10000 Truncate bodies beyond this length
excluded_paths [] Paths to skip. Accepts a list ["/health"] or a comma-separated string "/health,/metrics"
excluded_headers ["authorization", "cookie", "set-cookie"] Headers to redact

Key Features

  • Performance Tracking: Measure average response times, max/min, and Request/Second metrics.
  • Percentiles & Status Codes: View P50, P90, P95, and P99 latency percentiles alongside HTTP status distributions in the rich dashboard.
  • LLM Insights: Pass your analytics to an LLM provider for deep architectural advice.
  • Zero Overhead: Utilizes a background thread and queue mechanism to prevent adding latency to your API routes.

Development

git clone https://github.com/Mohammad-Palla/pyapimon.git
cd pyapimon
pip install -e ".[dev]"
pytest

License

MIT

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

pyapimon-0.1.3.tar.gz (37.0 kB view details)

Uploaded Source

Built Distribution

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

pyapimon-0.1.3-py3-none-any.whl (32.3 kB view details)

Uploaded Python 3

File details

Details for the file pyapimon-0.1.3.tar.gz.

File metadata

  • Download URL: pyapimon-0.1.3.tar.gz
  • Upload date:
  • Size: 37.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for pyapimon-0.1.3.tar.gz
Algorithm Hash digest
SHA256 07ed9d46523dd68624f9e9fd627c9c8d85228b0e0d16a1e4903406c215e4ad2c
MD5 ddbf18031d02458932680f2f68924e02
BLAKE2b-256 32963c9ee4e905c6ebe369884eab86fba6bd9f6e3b7ed21b367b15b79a2f22dc

See more details on using hashes here.

File details

Details for the file pyapimon-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: pyapimon-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 32.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for pyapimon-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 a68a17179d3f81ede065fbdc80c0e01848cc63d06e2f82ede8aca3ef4d36dc4b
MD5 605a1921819b2670c72de004e5de2b41
BLAKE2b-256 e9d36debfc0c1a85b7d1a2c395b503150360f9bc6845efda46b4241a054bd330

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