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.2.tar.gz (34.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.2-py3-none-any.whl (29.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pyapimon-0.1.2.tar.gz
  • Upload date:
  • Size: 34.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.2.tar.gz
Algorithm Hash digest
SHA256 ba438d753f2dd9b3cbca0616616560aa7f2f5b02604933c7db467ca26e42d068
MD5 1ad7dd0b413e6e8348c98bdcf43b0195
BLAKE2b-256 e8a609e331e6557217cf3b63f27e2592c1de1bcc75b87166a477f7a65dcff97b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyapimon-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 29.7 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b98eb97f4a89f563b74e8aed30854d9a05206647e127ee0b0e47489c3bcf2b51
MD5 de6cb407e03874c046c856aabf9e8378
BLAKE2b-256 53bcfa1cec54781ebd0c88d9b95a125c5121959a5d002bf7242e9818ae038bb7

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