Skip to main content

Real-time API monitoring for Flask/FastAPI with async, zero-blocking logging

Project description

api-watch

Real-time API monitoring for Flask/FastAPI with zero-blocking async logging

PyPI version Python 3.7+ License: MIT

A lightweight, developer-focused tool that streams your API requests, responses, and metadata to a beautiful real-time dashboard. Perfect for debugging, development, and understanding your API traffic.

api-watch Dashboard


Features

  • Zero Performance Impact - Fire-and-forget async logging that never blocks your API
  • Real-time Streaming - WebSocket-powered dashboard shows requests as they happen
  • Auto-Start Dashboard - Just import and use, dashboard starts automatically
  • Full Visibility - Method, path, status, timing, headers, request/response data
  • Filter by Status - Quickly filter requests by status code
  • Request Statistics - Visual metrics and charts
  • Minimal UI - Clean, fast dashboard focused on what matters
  • Multi-Framework - Works with Flask and FastAPI
  • Production Ready - Standalone mode for Docker/Kubernetes
  • Optimized Dependencies - Only install what you need

Quick Start

Installation

For Flask:

pip install api-watch[flask]

For FastAPI:

pip install api-watch[fastapi]

For both:

pip install api-watch[all]

Flask Integration (Auto-Start)

from flask import Flask
from apiwatch import ApiWatcher
from apiwatch.middleware_flask import FlaskWatchdogMiddleware

app = Flask(__name__)

# Dashboard auto-starts
api_watcher = ApiWatcher(service_name='my-flask-app')
FlaskWatchdogMiddleware(app, api_watcher)

@app.route('/api/users')
def get_users():
    return {"users": [...]}

if __name__ == '__main__':
    app.run(port=5000)

Run it:

python app.py

Open dashboard:

http://localhost:22222

FastAPI Integration

from fastapi import FastAPI
from apiwatch import ApiWatcher
from apiwatch.middleware_fastapi import FastapiwatchMiddleware

app = FastAPI()

# Dashboard auto-starts
api_watcher = ApiWatcher(service_name='my-fastapi-app')
app.add_middleware(FastapiwatchMiddleware, watcher=api_watcher)

@app.get("/api/users")
async def get_users():
    return {"users": [...]}

Run it:

uvicorn app:app --port 8000

📊 Dashboard Features

Real-time Request Monitoring

  • ✅ Live streaming of API requests
  • ✅ Color-coded HTTP methods (GET, POST, PUT, DELETE)
  • ✅ Status code highlighting (success/error)
  • ✅ Response time tracking
  • ✅ Service name badges (multi-service support)

Filters & Search

  • Filter by status code (2xx, 3xx, 4xx, 5xx, All)
  • Sort by newest, oldest, fastest, sloweset, status(high-low)
  • Filter by HTTP method

Request Details

  • Full request/response bodies
  • Query parameters
  • Headers (sensitive headers filtered)
  • Timestamp and duration

Use Cases

Development & Debugging

# See exactly what's hitting your API in real-time
# No more print() debugging!

API Testing

# Watch your integration tests run
# Verify request/response data instantly

Microservices Monitoring

# Monitor traffic between multiple services
# Debug complex request flows

Configuration

Basic Options

api_watcher = ApiWatcher(
    service_name='my-app',           # Service identifier
    max_history=1000,                # Requests to keep in memory
    dashboard_host='localhost',      # Dashboard host
    dashboard_port=22222,            # Dashboard port
    auto_start_dashboard=True        # Auto-start if not running
)

Middleware Options

Flask:

FlaskWatchdogMiddleware(
    app, 
    api_watcher,
    capture_request_body=True,   # Log request bodies
    capture_response_body=True   # Log response bodies
)

FastAPI:

app.add_middleware(
    FastapiwatchMiddleware,
    watcher=api_watcher,
    capture_request_body=True,   # Log request bodies
    capture_response_body=True   # Log response bodies
)

Production Deployment

Standalone Mode

For production, run the dashboard as a separate service:

Terminal 1: Start Dashboard

python -m apiwatch

Terminal 2: Start Your App

from apiwatch import ApiWatcher

api_watcher = ApiWatcher(
    service_name='my-app',
    auto_start_dashboard=False  # Don't auto-start in production
)

Docker Compose

services:
  apiwatch:
    image: theisaac/api-watch:latest
    container_name: apiwatch
    ports:
      - "22222:22222"
    restart: unless-stopped
    environment:
      - PYTHONUNBUFFERED=1
      - WATCHDOG_USERNAME=admin
      - WATCHDOG_PASSWORD=admin
    command: python -m apiwatch

Service code:

import os
from apiwatch import ApiWatcher

api_watcher = ApiWatcher(
    service_name=os.getenv('SERVICE_NAME', 'api-service'),
    dashboard_host=os.getenv('WATCHDOG_HOST', 'localhost'),
    dashboard_port=int(os.getenv('WATCHDOG_PORT', 22222)),
    auto_start_dashboard=False
)

How It Works

Flask/FastAPI Request
        ↓
   Middleware intercepts
        ↓
   Queue.put_nowait() (non-blocking, <0.1ms)
        ↓
   App continues normally
        ↓
Background Async Worker
        ↓
HTTP POST to Dashboard
        ↓
Dashboard broadcasts via WebSocket
        ↓
Browser UI updates in real-time

Zero blocking! Your API never waits for logging.


Requirements

  • Python 3.7+
  • aiohttp 3.8+ (always required)
  • Flask 2.0+ (optional - only for Flask integration)
  • FastAPI 0.68+ & Starlette 0.14+ (optional - only for FastAPI integration)

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

api_watch-0.1.3.tar.gz (98.7 kB view details)

Uploaded Source

Built Distribution

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

api_watch-0.1.3-py3-none-any.whl (19.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for api_watch-0.1.3.tar.gz
Algorithm Hash digest
SHA256 e00f09b6daf748d4699e8031f5e84d1f96191a1664d99f5c96e0792f10b74ca1
MD5 1f113e959c1afb1d62873fe516f3a15a
BLAKE2b-256 36c5f6796fabd8a25153ddbf4c7eb2e06b69a2d98c6a6f246417933f4e372730

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for api_watch-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 a28106d80c44546cc054eea1a68d3331b8f253ec3b31e25391995916aee5bf34
MD5 c41cfe9d5d21427be00a0f519cf43471
BLAKE2b-256 175f91d2e6da4cd9ccf57be675ee97b8971fa03fa4d3eedd73ee9be19e7c5e09

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