Skip to main content

API Sentinel 🛡️

Python 3.10+ FastAPI License: MIT OpenAPI 3.x

API Sentinel is an asynchronous FastAPI / ASGI middleware and developer telemetry dashboard that detects real-time contract drifts between runtime API payloads and your OpenAPI specification.


🚀 Key Features

  • ⚡ Zero-Latency Async Interception: Uses non-blocking background tasks (asyncio.create_task) and request buffering so your API responses stream immediately without waiting for validation.
  • 🔍 Comprehensive Drift Detection: Detects missing required fields, undocumented query/path parameters, type mismatches, undocumented HTTP status codes, and extra fields.
  • 📊 Real-Time Developer Dashboard: Built-in interactive dashboard with live polling, KPI metrics, pass/fail rate timeline charts, and severity breakdowns.
  • 💾 Database Persistence: Automatically records validation history and schema diffs to SQLite via SQLAlchemy (aiosqlite), persisting telemetry across server restarts.
  • 🪄 OpenAPI Specification Wizard: Visual form-based generator to design, preview, test, and save OpenAPI specs directly from the browser.
  • 💻 CLI Tooling: Built-in api-sentinel command-line interface to launch dashboards and validate specifications.

📦 Installation

From PyPI (Standard):

pip install api-drift-detector

From GitHub (Latest):

pip install git+https://github.com/T41h4X/API_sentinel.git

⚡ Quick Start

1. Integrate Middleware with FastAPI

Add APISentinelMiddleware to your FastAPI application:

from fastapi import FastAPI
from api_sentinel import APISentinelMiddleware

app = FastAPI(title="My API")

# Register Sentinel Middleware
app.add_middleware(
    APISentinelMiddleware,
    openapi_path="openapi.yaml",            # Path to your OpenAPI spec
    dashboard_url="http://127.0.0.1:8001",  # URL of the Sentinel dashboard
    enabled=True,
)

@app.get("/api/v1/users")
async def get_users():
    return [{"id": 1, "name": "Alice"}]

2. Launch the Sentinel Dashboard

Run the built-in dashboard from your terminal:

api-sentinel dashboard --port 8001

Open your browser at http://127.0.0.1:8001 to monitor incoming traffic, validation results, and contract drifts in real time.


💻 Command Line Interface (CLI)

API Sentinel provides the api-sentinel (or sentinel) CLI:

# Start the monitoring dashboard
api-sentinel dashboard --host 127.0.0.1 --port 8001

# Start dashboard in development mode with auto-reload
api-sentinel dashboard --reload

# Validate an OpenAPI specification file
api-sentinel validate --spec openapi.yaml

# Check installed version
api-sentinel version

⚙️ Configuration

API Sentinel can be configured using environment variables (prefixed with SENTINEL_) or a .env file:

Variable Default Description
SENTINEL_DATABASE_URL sqlite+aiosqlite:///./sentinel.db SQLAlchemy database connection string
SENTINEL_RETENTION_DAYS 30 Number of days to retain validation records before cleanup
SENTINEL_MASKED_FIELDS ["password", "token", "credit_card", "authorization"] Sensitive payload fields automatically masked
SENTINEL_SELECTIVE_PERSISTENCE false When true, only saves WARNING and FAILED validation results
SENTINEL_OPENAPI_SPEC_PATH openapi.yaml Default OpenAPI specification file path

🧪 Running the Demo Locally

Clone the repository and test the full demo application:

git clone https://github.com/T41h4X/API_sentinel.git
cd API_sentinel

# Create and activate environment
python -m venv .venv
.\.venv\Scripts\activate      # Windows
source .venv/bin/activate    # Linux / macOS

# Install in editable mode
pip install -e .

# Launch all demo services (Windows)
start_all.cmd

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

Release files for api-drift-detector 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for api-drift-detector 0.1.0
File Size Uploaded
api_drift_detector-0.1.0.tar.gz 107.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for api-drift-detector 0.1.0
File Interpreter ABI Platform
api_drift_detector-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 181.9 kB

Release files / api_drift_detector-0.1.0.tar.gz

Download URL api_drift_detector-0.1.0.tar.gz
Size 107.7 kB
Tags Source
SHA-256 checksum
How to use checksums
22b0150f7f015a68bc66cfbea1456f20b7f666efe97f8bcd50f3e180fcee8247
BLAKE2b-256 checksum
How to use checksums
417fade6be0f4820e9efa547e189dced048ab0bf11a1a33683f667192ab54543
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.9

Release files / api_drift_detector-0.1.0-py3-none-any.whl

Download URL api_drift_detector-0.1.0-py3-none-any.whl
Size 74.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a479939fe171516d63d5bff14e754fc965c1c31f8b2fb9d5d03ee127d802f7e8
BLAKE2b-256 checksum
How to use checksums
52f9a9c8d2db47737dbb26e5498b651cd811592fed1e034aebdf22d60e6fa9fb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.9

Release history Release notifications | RSS feed

0.1.2

2 release files

0.1.1

2 release files

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page