Skip to main content

Zero-config latency tracking for FastAPI and Flask

Project description

LatencyX

Add one line. Know why your API is slow.

LatencyX auto-instruments your Python web app and stores traces locally — no Jaeger, no Kafka, no Docker Compose file with 11 services. Just run your app and start asking questions.

Status: Built for local development and staging. Not production-ready yet — see Production below.


What you get

  • FastAPI and Flask middleware — every request traced automatically
  • SQLAlchemy tracing — sync and async, query names, durations, parent linking
  • httpx tracing — outbound HTTP calls captured as child spans
  • Local SQLite storage — no external infra, traces survive restarts
  • CLI analysis tools — p50/p95/p99, slowest endpoints, error grouping, full trace trees

Quick start

pip install latencyx
from fastapi import FastAPI
import latencyx

app = FastAPI()
latencyx.init(app)  # done

That's it. Every request is now traced and stored in latencyx_traces.db.


CLI

The CLI is where LatencyX earns its keep. All commands read from the local SQLite database.

latencyx stats

Overall p50/p95/p99 latency, error rate, and top slow endpoints.

┌─────────────────────────────────────────────────────────────────┐
│                        LatencyX Stats                           │
├────────────────────────┬───────┬───────┬────────┬──────────────┤
│ Endpoint               │  p50  │  p95  │   p99  │  Error Rate  │
├────────────────────────┼───────┼───────┼────────┼──────────────┤
│ GET /api/users         │ 42ms  │ 310ms │ 890ms  │    1.2%      │
│ POST /api/orders       │ 120ms │ 540ms │ 1200ms │    3.8%      │
│ GET /api/products      │ 18ms  │  65ms │  140ms │    0.0%      │
└────────────────────────┴───────┴───────┴────────┴──────────────┘

latencyx slowest

The slowest recent requests, filterable by path and time range.

latencyx slowest --limit 10 --path /api/orders

latencyx errors

Recent errors grouped by endpoint and message with counts.

latencyx endpoints

All distinct paths with request count, p50/p95, and error rate.

latencyx trace <trace_id>

Full trace tree — HTTP span with child DB query spans and durations.

GET /api/orders  412ms  [200]
├── db.query  SELECT orders  180ms
├── db.query  SELECT products  95ms
└── http.client  GET payments.internal/validate  130ms

latencyx report

Request volume, error rate, top slow endpoints, top errors — all in one view.

latencyx tail

Live stream of incoming traces as they happen.


Flask

from flask import Flask
import latencyx

app = Flask(__name__)
latencyx.init(app)

SQLAlchemy

from sqlalchemy import create_engine
import latencyx

engine = create_engine("sqlite:///myapp.db")
latencyx.init(app, sqlalchemy_engine=engine)

Async engines (create_async_engine) work the same way.


Optional dependencies

pip install latencyx               # FastAPI + Flask + CLI
pip install latencyx[http]         # + httpx tracing
pip install latencyx[sqlalchemy]   # + SQLAlchemy tracing
pip install latencyx[all]          # everything

Disable with zero overhead

latencyx.init(app, enabled=False)

When disabled, all instrumentation is skipped at the entry point — no branches, no storage, no cost.


Production

LatencyX is not production-ready yet. It's designed for local development and staging environments.

Specific gaps for production use:

  • Multi-process deployments (gunicorn with multiple workers) — SQLite does not handle concurrent writes from multiple OS processes reliably under load. You'll get contention or dropped spans.
  • No retention / cleanup — the trace database grows indefinitely. There's no auto-delete yet.
  • No performance benchmarks — the per-request overhead hasn't been measured under load.
  • No migration story — a schema change on upgrade could break an existing database.

For single-process, low-traffic deployments (one uvicorn worker, internal tools, staging) it works fine in practice. For anything beyond that, wait for v1.0.0.


Compared to OpenTelemetry

LatencyX OpenTelemetry
Setup 1 line 50+ lines of config
Infrastructure None (local SQLite) Collector + backend required
Learning curve Minutes Hours to days
Best for Dev, staging, small teams Large-scale, multi-service

LatencyX isn't trying to replace OpenTelemetry. If you need distributed tracing across 20 microservices, use OTel. If you want to know why your endpoint is slow without standing up infrastructure, use LatencyX.


Roadmap

v0.3.0 is the current release.

v1.0.0 targets: Django support, Redis tracing, SQLite retention/cleanup, performance benchmarks, and a production guide.


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

latencyx-0.3.0.tar.gz (39.7 kB view details)

Uploaded Source

Built Distribution

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

latencyx-0.3.0-py3-none-any.whl (28.1 kB view details)

Uploaded Python 3

File details

Details for the file latencyx-0.3.0.tar.gz.

File metadata

  • Download URL: latencyx-0.3.0.tar.gz
  • Upload date:
  • Size: 39.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for latencyx-0.3.0.tar.gz
Algorithm Hash digest
SHA256 25f8b3f50e50f826aac0af94abd239ba8decbcd1b24319d1ddc1ea52e04ac755
MD5 96b2ca7a208cfad5ac12501b21ef741b
BLAKE2b-256 bf3eff9ed02d0bf09d670df9f01f79a6e744ff76b8d7afb0d55ac9ae8048ac23

See more details on using hashes here.

Provenance

The following attestation bundles were made for latencyx-0.3.0.tar.gz:

Publisher: publish.yaml on Devang-C/latencyx

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file latencyx-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: latencyx-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 28.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for latencyx-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4adf95b4dc500f33f0f7fec64fd30a453ef12488f3af9a79accf7ec05961a98d
MD5 b60a9584a0368af5d5b96f578adc569d
BLAKE2b-256 9ce161bea1ace8296b799f636aa2e32b974d88cf8b79c0010cfbd7b032aa1080

See more details on using hashes here.

Provenance

The following attestation bundles were made for latencyx-0.3.0-py3-none-any.whl:

Publisher: publish.yaml on Devang-C/latencyx

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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