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

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 (e.g., ["/health"])
excluded_headers ["authorization", "cookie", "set-cookie"] Headers to redact

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.1.tar.gz (33.1 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.1-py3-none-any.whl (28.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pyapimon-0.1.1.tar.gz
  • Upload date:
  • Size: 33.1 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.1.tar.gz
Algorithm Hash digest
SHA256 a9fb5669f03dca86e6354fcb709aab023f271bae078abe8c839a32d970f3019a
MD5 6da5ba68eb323e833d1398628ada03a8
BLAKE2b-256 1e28973f739437c74e8067de8ef23311ad88c2dcbe0632d4e4ca35ac5c91e7e2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyapimon-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 28.8 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ad2df9d7a6e8461e0b6d0d261eca097da2e1839e94ae7d4391de14601e3fd3aa
MD5 5fa61a4443586fc0ed0f0422ba99c622
BLAKE2b-256 6977507cec4d03d6ba7f6aa8ad2c0911f935806b6744ff2330cefecae6be7050

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