Skip to main content

metrixwire (Python)

Zero-config APM SDK for Python. Call init() once — every request, database query, cache op and outbound HTTP call is instrumented automatically. There is no manual span API and no middleware to wire up. Non-blocking: if the MetrixWire endpoint is down, your app keeps running normally.

Installation

pip install metrixwire

Zero required dependencies — the core uses only the standard library.

Usage

import metrixwire

metrixwire.init(api_key="mw_...")

That's it. Do this once, as early as possible in your process (before your server starts). Every HTTP request becomes a trace, and every query / HTTP call / cache op within it becomes a span.

Auto-init as early as possible

Import and init at the very top of your entry module (or a sitecustomize.py on your PYTHONPATH) so the patches are installed before your framework and drivers are used:

# sitecustomize.py — or the first lines of your app's entry point
import metrixwire
metrixwire.init()  # reads METRIXWIRE_KEY / METRIXWIRE_ENDPOINT / METRIXWIRE_ENABLED from env

With no arguments, init() reads its config from the environment:

Env var Purpose
METRIXWIRE_KEY Project API key (required to enable)
METRIXWIRE_ENDPOINT Ingest URL — base or full /ingest (default http://localhost:3000/ingest)
METRIXWIRE_ENABLED false to disable entirely

A missing API key runs the SDK disabled — it never raises.

How the automatic tracing works

A trace is opened for every incoming request by patching each framework's single entry point — no middleware, no per-route setup:

Framework Traced automatically How
Flask ✅ wraps Flask.wsgi_app; route from the matched URL rule (/users/<id>)
Django ✅ patches WSGIHandler.__call__ and ASGIHandler.__call__; route from the resolver match
FastAPI · Starlette ✅ wraps Starlette.__call__ (ASGI); route from the matched pattern (/users/{id})
Bare / other WSGI (wsgiref, …) ✅ wrap once with metrixwire.wsgi.MetrixWireMiddleware

For a bare or unsupported WSGI app:

from metrixwire.wsgi import MetrixWireMiddleware
app = MetrixWireMiddleware(app)

Each trace records the route, HTTP status, response byte size (for the large-response detector), memory growth (for the memory-spike detector), and any unhandled exception.

Automatically instrumented libraries

Installed via init() — each is best-effort: if the library isn't importable it's skipped silently.

Library Span How
psycopg2 db_query (rowCount) patches psycopg2.extensions.cursor.execute/executemany
psycopg (v3) db_query (rowCount) patches psycopg.Cursor.execute/executemany
sqlite3 db_query (rowCount) patches sqlite3.Cursor.execute/executemany
PyMySQL · mysqlclient db_query (rowCount) patches the driver's Cursor.execute/executemany
Django ORM · SQLAlchemy db_query automatic — they run on the drivers above
requests http_call (statusCode) patches Session.request
stdlib http.client / urllib http_call (statusCode) patches HTTPConnection.request/getresponse
redis-py cache (custom, kind=cache) patches Redis.execute_command (records hit/miss)
DB transactions custom (kind=transaction) times BEGIN…COMMIT / connection.commit()

Database spans also capture a sourceLocation (file.py:42) pointing at the nearest application frame.

init options

metrixwire.init(
    api_key="mw_...",                        # required (or METRIXWIRE_KEY)
    endpoint="http://localhost:3000/ingest",  # default; base URL is accepted too
    flush_interval_ms=5000,                   # how often batches are sent
    enabled=True,                             # set False to disable entirely
    timeout_ms=3000,                          # send timeout (short, non-blocking)
    max_batch=20,                             # flush immediately once this many are queued
    capture_source=True,                      # capture the file:line a span originated from
)

Escape hatch

Requests, queries, HTTP calls and cache ops are all captured automatically. The one manual helper — for frameworks that catch their own errors before the SDK sees them — is:

import metrixwire

try:
    ...
except Exception as e:
    metrixwire.capture_exception(e)   # attach it to the active trace
    raise

Non-blocking behavior

  • Traces are batched and sent off the request path on a background daemon thread with a short timeout.
  • All transport errors are swallowed — instrumentation never throws into your app.
  • A final flush runs at process exit (atexit); you can also call metrixwire.flush() before a short-lived process exits.

Metadata

Release files for metrixwire 0.2.1

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

Source distribution (sdist)

Source distribution for metrixwire 0.2.1
File Size Uploaded Provenance Actions
metrixwire-0.2.1.tar.gz 17.4 kB Without provenance Details for metrixwire-0.2.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for metrixwire 0.2.1
File Interpreter ABI Platform Actions
metrixwire-0.2.1-py3-none-any.whl Python 3 none any Details for metrixwire-0.2.1-py3-none-any.whl

Total release size: 46.5 kB

Release files / metrixwire-0.2.1.tar.gz

Download URL metrixwire-0.2.1.tar.gz
Size 17.4 kB
Tags Source
SHA-256 checksum
How to use checksums
b524a513c203da0cc11eaf944c1b7200a316bcba5961bf31933f6a57460bf06c
BLAKE2b-256 checksum
How to use checksums
7724f4324933840b7c5671d67fdcb94e10e5c6566a95378f1107ea3f75f006cc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.6

Release files / metrixwire-0.2.1-py3-none-any.whl

Download URL metrixwire-0.2.1-py3-none-any.whl
Size 29.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a1485c164cf63af6c9fc73cd6b6ea1869734998fde4fb0a3e9026719c8299822
BLAKE2b-256 checksum
How to use checksums
5fe8ba9081104f7c14eefd7c9b42c00802fa90d9f9153e901b249335a042d19f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.6

Security for metrixwire 0.2.1

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.

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