API Reference

ApiWatcher

class apiwatch.ApiWatcher(service_name='main-app', max_history: int = 1000, dashboard_host: str = 'localhost', dashboard_port: int = 22222, dashboard_username: str = 'admin', dashboard_password: str = 'admin', auto_start_dashboard: bool = True)[source]

Bases: object

Async API monitoring with zero-blocking fire-and-forget pattern. Auto-starts dashboard if not running (like RabbitMQ with pika)

clear_history()[source]

Clear local request history

get_history()[source]

Get local cached requests

log_request(method: str, path: str, status_code: int | None = None, request_data: Dict | None = None, response_data: Any | None = None, duration_ms: float | None = None, headers: Dict | None = None, query_params: Dict | None = None)[source]

Fire-and-forget request logging (non-blocking)

shutdown()[source]

Gracefully shutdown watcher

Flask Middleware

class apiwatch.middleware_flask.FlaskWatchMiddleware(app, watcher, capture_request_body=True, capture_response_body=True)[source]

Bases: object

Flask middleware for ApiWatchdog - optimized for zero blocking

apiwatch.middleware_flask.watch_route(watcher: ApiWatcher)[source]

Decorator for manual route watching (alternate middleware)

Usage:

@app.route(‘/api/users/’) @watch_route(api_watcher) def get_users():

return jsonify(users)

FastAPI Middleware

class apiwatch.middleware_fastapi.FastAPIWatchMiddleware(app, watcher, capture_request_body=True, capture_response_body=True)[source]

Bases: BaseHTTPMiddleware

FastAPI middleware for ApiWatchdog - optimized for zero blocking

async dispatch(request: Request, call_next)[source]

Process request and response