Skip to main content

A zero-dependency, ultra-lightweight performance terminal dashboard for Python Web Frameworks

Project description

py-api-spy

PyPI version Python version License

A zero-dependency, lightweight terminal performance dashboard for Python web frameworks.

This is the Python sibling of the @chabdulwahab/api-spy Node.js library. It maintains the identical layout, telemetry keys, and minimalist design philosophy.

Features

  • Zero Dependencies: Implemented using only standard Python library modules.
  • Low Overhead: Tailored metrics tracking with minimal CPU and memory impact.
  • Sticky Terminal Dashboard: Persisted at the bottom of the stdout stream while application logs print normally above it.
  • Thread Safe: Concurrent requests are serialized using reentrant locking mechanisms.
  • Framework Support: Built-in middlewares for FastAPI / Starlette (ASGI) and Django / DRF (WSGI).

Installation

Install the package via pip:

pip install py-api-spy

Usage

FastAPI / Starlette

Add the ASGI middleware to your FastAPI application:

from fastapi import FastAPI
from api_spy import ApiSpyMiddleware

app = FastAPI()
app.add_middleware(ApiSpyMiddleware)

@app.get("/")
def read_root():
    return {"hello": "world"}

Django / DRF

Add the WSGI middleware to your Django MIDDLEWARE list in settings.py:

MIDDLEWARE = [
    # ... other middlewares ...
    "api_spy.ApiSpyDjangoMiddleware",
]

Dashboard Design

The dashboard takes exactly 10 lines and maintains a hardcoded width of 72 characters:

  • Latency States: Green [✓] for fast routes (<= 200ms) and red [!] for slow routes (> 200ms).
  • Dot-leaders: Dim gray dots linking paths with their corresponding metrics.
  • Cross-Platform Memory: Retrieves resident set size (RAM) for Linux, macOS, and Windows.
┌──────────────────────────────────────────────────────────────────────┐
│ Active: 1          │ Total: 15          │ RAM: 14.5 MB               │
├──────────────────────────────────────────────────────────────────────┤
│ Slowest Routes (Top 5)                                               │
│ [✓] GET     /.............................................. 5ms (x8) │
│ [!] POST    /api/v1/users.............................. 205ms (x2)   │
│ -                                                                    │
│ -                                                                    │
│ -                                                                    │
└──────────────────────────────────────────────────────────────────────┘

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

py_api_spy-0.1.2.tar.gz (9.9 kB view details)

Uploaded Source

Built Distribution

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

py_api_spy-0.1.2-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: py_api_spy-0.1.2.tar.gz
  • Upload date:
  • Size: 9.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for py_api_spy-0.1.2.tar.gz
Algorithm Hash digest
SHA256 886e3e1f7ced1a497bfb1724815e2ac75d0d928978472d9fd2b5bebc2525cb30
MD5 3129024ad300ac8e05cb69fd41d9f042
BLAKE2b-256 52196763136d92f1a27f3fc0d489f110cb3a1f7bac0122b87db13d18853982de

See more details on using hashes here.

File details

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

File metadata

  • Download URL: py_api_spy-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 9.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for py_api_spy-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 69f4a26a9eb727e78973571c18fb2a552041e9383a8890a23523d73511b75a20
MD5 8b638567c7dbfbff795b2eafaa22d8b3
BLAKE2b-256 531587cf64ca118a839c3efa1b7408fe364aebb606cf1bd09b28ede2b5c3dd78

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