Metadata-Version: 2.4
Name: pyapimon
Version: 0.1.0
Summary: Python middleware for API monitoring and analytics
License: MIT
Keywords: api,monitoring,middleware,analytics,fastapi,django,flask
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: System :: Monitoring
Requires-Python: >=3.10
Description-Content-Type: text/markdown
Requires-Dist: sqlalchemy>=2.0.0
Requires-Dist: click>=8.1.0
Requires-Dist: rich>=13.0.0
Requires-Dist: textual>=0.50.0
Requires-Dist: python-dateutil>=2.8.0
Provides-Extra: llm
Requires-Dist: openai>=1.0.0; extra == "llm"
Requires-Dist: google-genai>=0.3.0; extra == "llm"
Requires-Dist: anthropic>=0.18.0; extra == "llm"
Provides-Extra: dev
Requires-Dist: pytest>=7.0; extra == "dev"
Requires-Dist: httpx>=0.24; extra == "dev"
Requires-Dist: fastapi>=0.100; extra == "dev"
Requires-Dist: flask>=2.0; extra == "dev"
Requires-Dist: django>=4.0; extra == "dev"

# 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

```bash
pip install pyapimon
```

With LLM-powered insights:

```bash
pip install pyapimon[llm]
```

## Quickstart

### FastAPI

```python
from fastapi import FastAPI
from pyapimon import FastAPIMiddleware

app = FastAPI()
app.add_middleware(FastAPIMiddleware)
```

### Django

Add to `settings.py`:

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

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

### Flask

```python
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

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

## License

MIT
