Skip to main content

octri (Python)

Error and performance monitoring for Python backends. Report errors out of Flask, FastAPI, or Django with original-source context per stack frame, time every request into a waterfall, and join each server error to the client SDK error for the same request through the W3C traceparent header. In the dashboard you see the full client and server stack under one trace.

Octri turns an OpenAPI spec into a documentation site, client SDKs for ten languages, an MCP server your AI assistant can call, and monitoring for the API behind them. This package is the Python monitoring runtime, and it works on its own: a generated Octri API SDK is not required. See octri.dev/monitoring.

Python 3.8 or newer. Pure standard library, with no required dependencies. The Python sibling of @octri/node.

Install

pip install octri

Setup

from octri import init

init(
    url="https://monitoring.example.com",   # your monitoring base URL
    token=os.environ["OCTRI_TOKEN"],         # your project ingest token
    environment="<your project id>",         # the dashboard project id
    release=os.environ.get("GIT_SHA"),       # optional
)

Hosted users can copy the project-scoped URL, token, and environment from the Monitoring connection settings (or its API). Pass token=None only when pointing at an open self-hosted ingest endpoint. Every request carries an idempotency key.

Standalone events

No generated API SDK is required to send your own events:

from octri import capture_event

capture_event(
    "checkout.completed",
    user={"id": customer.id},
    tags={"region": "eu-west", "plan": "growth"},
    context={"order_id": order.id, "total": order.total},
)

Delivery is best-effort and happens off the calling thread. Pass event_id to make a retried delivery idempotent.

Flask

from octri.flask import octri_flask

app = Flask(__name__)
octri_flask(app)   # observes unhandled request exceptions; nothing else to wire

FastAPI / Starlette

from octri.fastapi import OctriMiddleware

app = FastAPI()
app.add_middleware(OctriMiddleware)   # reports unhandled 500s, then re-raises

Django

# settings.py, after calling init(...) somewhere at startup
MIDDLEWARE = [
    # ...
    "octri.django.OctriMiddleware",
]

How linking works

The Octri client SDK sends a traceparent header on every request. Each integration reads it, captures the failing exception (with source context for each in-app frame), and reports it tagged octri.origin=server under the same traceId, so the client SDK error and this server error appear as one linked trace in the dashboard.

For compiled/minified clients, the dashboard pairs this with source maps / source bundles; the Python server frames already carry their original source inline.

Spans & the request waterfall

The middleware times each request. To see where time goes inside it, let Octri instrument common I/O automatically, or open spans yourself.

Automatic

octri.auto_instrument()                       # traces requests + urllib (outbound HTTP)
octri.instrument(cursor, ["execute"], op="db")  # your own DB client / util module, once
octri.instrument(cache, ["get", "set"], op="cache")

@octri.traced(op="fn")
def compute_totals(orders): ...

Every instrumented call (and every outbound HTTP request) becomes a sub-span under the current request, with no per-call code. Calls to your monitoring backend are never traced (no feedback loop).

Manual

with octri.span("orders.list", op="db"):
    rows = db.query(sql)

s = octri.start_span("render", op="view")
# ...work...
s.finish()

op ("db", "cache", "http", and so on) color-codes the bar in the dashboard waterfall.

Manual capture

from octri import capture_error, trace_from_header

try:
    ...
except Exception as exc:
    capture_error(exc, trace=trace_from_header(request.headers.get("traceparent")))
    raise

The rest of Octri

Product What it does
API Studio Your OpenAPI spec becomes a hosted documentation site with a live request playground, editable page by page.
SDK Studio The same spec becomes client libraries for ten languages, versioned and released together.
MCP Your endpoints and docs become tools an AI assistant can call, generated from the same spec.
Monitoring Errors, traces, uptime and releases for the API, joined to the SDK calls that reached it.

Monitoring runtimes

More

MIT licensed.

Metadata

Release files for octri 1.0.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 octri 1.0.1
File Size Uploaded
octri-1.0.1.tar.gz 16.4 kB Details

Built distribution (wheel)

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

Total release size: 31.0 kB

Release files / octri-1.0.1.tar.gz

Download URL octri-1.0.1.tar.gz
Size 16.4 kB
Tags Source
SHA-256 checksum
How to use checksums
d9c8d9d78737c034bb45683c8743952e0f803f5498dd58b62d30bb206633a321
BLAKE2b-256 checksum
How to use checksums
108058aaabd0ee1fb65624bf2cf304f5b357d559db5693a7e552123221921bb5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release files / octri-1.0.1-py3-none-any.whl

Download URL octri-1.0.1-py3-none-any.whl
Size 14.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
968c6d4bfc9c4ceb6233ed2b7aeaefd55fd8db67d84e279c1a276712e7ecb0f1
BLAKE2b-256 checksum
How to use checksums
9b7a4e6a35a6f80b695415dd5c444f6f7f158ed773bd357757a4c122787c9801
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release history Release notifications | RSS feed

1.2.0

2 release files

1.1.0

2 release files

This release

1.0.1 This release

2 release files

1.0.0

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