apiforgepy
API observability & intelligence for FastAPI/Starlette — local-first, privacy-first.
Track latency, error rates, and behavioral trends of your APIs. Everything stays on your machine.
Install
pip install apiforgepy
Quick start
from fastapi import FastAPI
from apiforgepy import ApiForgeMiddleware
app = FastAPI()
app.add_middleware(ApiForgeMiddleware)
@app.get("/users/{user_id}")
def get_user(user_id: int):
return {"id": user_id}
# Dashboard auto-starts at http://localhost:4242
Dashboard
Open http://localhost:4242 after starting your app. No configuration needed — the dashboard server starts automatically in the background.
- Health Score (0–100) — global API health at a glance
- Latency percentiles — P50 / P90 / P99 per route
- Error rates — 4xx and 5xx breakdown
- Automatic insights — latency anomalies, dead endpoints, release regressions
- Time series chart — click any route to see its latency over time
Data is stored locally in .apiforge.db (SQLite). Nothing leaves your machine.
Configuration
app.add_middleware(
ApiForgeMiddleware,
db_path=".apiforge.db",
dashboard_port=4242, # set to 0 to disable
env="production",
release="v1.4.0", # enables release regression detection
service="user-service",
sampling=1.0, # 0.0–1.0 sample rate
ignore_paths=["/health", "/favicon.ico"],
)
Cloud mode
Send metrics to the APIForge SaaS platform instead of storing them locally:
app.add_middleware(
ApiForgeMiddleware,
cloud_url=os.environ["APIFORGE_CLOUD_URL"],
api_key=os.environ["APIFORGE_API_KEY"],
service="user-service",
env="production",
release=os.environ.get("APP_VERSION"),
)
In cloud mode, metrics are aggregated in memory for 60 seconds and sent as a single batch — the local dashboard and SQLite database are not used.
Release tracking
Pass your release version to enable before/after deployment comparison:
import os
app.add_middleware(ApiForgeMiddleware, release=os.environ.get("APP_VERSION"))
When a new release is detected, APIForge compares P90 latency before and after and surfaces regressions automatically.
What you get
- Per-route latency — P50, P90, P99 per endpoint, updated every 60 s
- Error rate by route — 2xx / 3xx / 4xx / 5xx breakdown
- API Health Score — a single 0–100 score summarising your API's health
- Ghost route detection — requests that match no declared Starlette/FastAPI route
- Latency anomaly alerts — Z-score detection against a 7-day baseline
- Dead endpoint detection — routes with no traffic for 21+ days
- Release regression analysis — automatic P90 comparison per deploy
- Progressive drift detection — slow latency increases over weeks
- Untracked route detection — declared routes that never received traffic
- Inflight concurrency tracking —
inflight_avgandinflight_maxper route
Graceful shutdown
Cleanup (flush buffer, close dashboard, close SQLite) happens automatically via atexit. For explicit control in long-running processes:
from contextlib import asynccontextmanager
from fastapi import FastAPI
from apiforgepy import ApiForgeMiddleware
forge = None
@asynccontextmanager
async def lifespan(app):
yield
if forge:
forge.shutdown()
app = FastAPI(lifespan=lifespan)
forge = ApiForgeMiddleware(app) # store reference before adding
app.add_middleware(ApiForgeMiddleware)
Privacy by design
The middleware never reads request or response bodies, headers, cookies, or tokens. Route parameters are captured as patterns only (/users/{user_id} — never /users/42). In local mode, zero data leaves your machine.
Requirements
- Python ≥ 3.11
- Starlette ≥ 0.27 (FastAPI ≥ 0.110 includes this)
License
MIT — APIForge Organisation
Metadata
Release files for apiforgepy 4.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| apiforgepy-4.0.0.tar.gz | 746.4 kB | Without provenance | Details for apiforgepy-4.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| apiforgepy-4.0.0-py3-none-any.whl | Python 3 | none | any | Details for apiforgepy-4.0.0-py3-none-any.whl |
Total release size: 1.5 MB
Release files / apiforgepy-4.0.0.tar.gz
| Download URL | apiforgepy-4.0.0.tar.gz |
|---|---|
| Size | 746.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b41c12dc954c87ba4d25198bc683fe96dbcc7f96205cbd99055f40909434f44d
|
|
BLAKE2b-256 checksum How to use checksums |
9765e1f94c43f798b4aab17c032979f53f7fcf719aaa8e45d3fe31e66ded63f0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.13
|
Release files / apiforgepy-4.0.0-py3-none-any.whl
| Download URL | apiforgepy-4.0.0-py3-none-any.whl |
|---|---|
| Size | 747.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5f005a101a6aca71e37ff9dc53f59ae06a45a023cba24f19bb8de866fe0cf8d2
|
|
BLAKE2b-256 checksum How to use checksums |
00a4b4b2640a2d3f0adfc04f5ced7865619b1ec0ea8476c42bd12445115d6399
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.13
|
Security for apiforgepy 4.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.