Skip to main content

obyflow-python

Python instrumentation SDK for Obyflow — an AI-native, CLI-first observability platform for tracing, debugging, and understanding modern applications (LLM calls, vector-store queries, LangChain steps, and plain HTTP included).

Events are captured locally to SQLite (no external backend required) and can then be explored, correlated, and investigated with the obyflow CLI.

Installation

pip install obyflow-python

Requires Python ≥ 3.9.

Optional extras

pip install "obyflow-python[langchain]"   # LangChain callback instrumentation
pip install "obyflow-python[analysis]"    # scikit-learn/numpy-backed ML anomaly detection

Quick start

from obyflow import start
from obyflow.instrumentation.asgi import ObyflowASGIMiddleware

handle = start(service="checkout-api")
app.add_middleware(ObyflowASGIMiddleware, service="checkout-api", store=handle.store)

For synchronous WSGI apps (Flask, Django sync views), use ObyflowWSGIMiddleware instead:

from obyflow import start
from obyflow.instrumentation.wsgi import ObyflowWSGIMiddleware

handle = start(service="checkout-api")
app.wsgi_app = ObyflowWSGIMiddleware(app.wsgi_app, service="checkout-api", store=handle.store)

Unlike the Node SDK, which auto-instruments any http-based server via a runtime patch installed by start(), Python's inbound HTTP tracing requires this explicit middleware registration by design (Node's global http.Server.prototype.emit patch has no equivalent that's safe across Python's various sync/async server models).

start() auto-instruments outbound HTTP, including automatic cross-service trace propagation (x-obyflow-trace-id / x-obyflow-parent-span-id headers), so traces stay linked across service boundaries with no manual header wiring.

handle.instrument is pre-bound to service/store/deployment_id/resource_attributes, so vector-store and LangChain instrumentation don't need those threaded through every call site:

handle.instrument.pinecone(index)
handle.instrument.langchain()

For manual trace-context propagation, use with_trace_context as a scoped context manager instead of the lower-level set_trace_context/reset_trace_context pair:

from obyflow import TraceContext, with_trace_context

with with_trace_context(TraceContext(trace_id="trace_123", request_id="req_123")):
    ...

Then, from the same project:

npx obyflow init
npx obyflow traces
npx obyflow investigate --since 15m

What's included

  • Canonical event modelEvent, EmbeddingAttributes, VectorOpAttributes, ChainAttributes, ToolCallAttributes, LlmCallAttributes, with validate_event/safe_validate_event
  • ASGI middleware (ObyflowASGIMiddleware) — automatic inbound request tracing for FastAPI/Starlette and other ASGI apps
  • WSGI middleware (ObyflowWSGIMiddleware) — automatic inbound request tracing for Flask and Django (sync) apps
  • Outbound HTTP instrumentation (instrument_outbound_http) — wraps outbound calls (requests/httpx) with automatic trace-context propagation
  • LangChain instrumentation (ObyflowLangChainCallbackHandler / create_langchain_callback_handler) — chain, tool, and LLM call events
  • Vector database instrumentation — Pinecone, Qdrant, Weaviate, Chroma, pgvector, and Milvus, plus OpenAI/Anthropic/Cohere embedding calls
  • Statistical anomaly detection (compute_baseline_stats, classify_severity) — plain mean/stddev z-scored deviation baselining; a separate, Python-only convenience toolkit, not a port of the TypeScript core's rolling/robust baseline engine (see "Anomaly detection: Node vs Python" below)
  • ML-based anomaly detection (detect_ml_anomalies, [analysis] extra) — scikit-learn-backed anomaly scoring over event duration/error-rate features; Python-exclusive, with no TypeScript/core equivalent

Anomaly detection: Node vs Python

Capability Node/CLI (packages/core) Python (obyflow.analysis)
Mean/stddev baselining Yes Yes
Median/MAD ("robust") baselining Yes No
Rolling time-windowed buckets Yes No
Deployment-aware bucketing Yes No
Configurable z-score threshold Yes No (fixed thresholds in classify_severity)
ML-based detection (IsolationForest) No Yes (detect_ml_anomalies, [analysis] extra)

obyflow.analysis.stats/obyflow.analysis.anomaly are a separate, Python-only convenience toolkit rather than a port of the CLI's packages/core/src/anomaly/baseline.ts engine. A Python caller of compute_baseline_stats should not expect the same rigor (robust/rolling/deployment-aware baselining) the CLI's investigate/ask/incident commands get from core.

  • Redaction (redaction.py) — scrubs sensitive fields (passwords, tokens, credit cards, SSNs, API keys) before events are stored
  • Resource attributes (resource_attributes.py) — every event is auto-tagged with hostname, PID, Python version, and the current git commit SHA (from CI env vars or a local git rev-parse HEAD), powering commit-based "what changed" correlation in the CLI with no extra setup
  • Trace context propagation (context.py) — get_active_trace_id, get_active_request_id, get_active_span_id, get_active_parent_span_id, get_active_trace_context, and the scoped with_trace_context context manager for manual instrumentation

Links

License

MIT © Anupam Kumar

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

obyflow_python-0.0.7.tar.gz (32.0 kB view details)

Uploaded Source

Built Distribution

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

obyflow_python-0.0.7-py3-none-any.whl (26.8 kB view details)

Uploaded Python 3

File details

Details for the file obyflow_python-0.0.7.tar.gz.

File metadata

  • Download URL: obyflow_python-0.0.7.tar.gz
  • Upload date:
  • Size: 32.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.7

File hashes

Hashes for obyflow_python-0.0.7.tar.gz
Algorithm Hash digest
SHA256 2b85ca93a2f6c1b45e1b634dcfc252bae9dca9b122f2d7afedf11284acd91ac8
MD5 bead4b192e27058f8ae48975445a28c5
BLAKE2b-256 345025f357f2540e400004a7edb269662b445dac5b85bf2bccb4c6a2df59e9f5

See more details on using hashes here.

File details

Details for the file obyflow_python-0.0.7-py3-none-any.whl.

File metadata

  • Download URL: obyflow_python-0.0.7-py3-none-any.whl
  • Upload date:
  • Size: 26.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.7

File hashes

Hashes for obyflow_python-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 d41229cf6041b6c33d9152d870c5fe11b131446e5ed9f7b77bd8d6f99b94787f
MD5 818fb1c4f6c68ce7b77331b5e8aeb1de
BLAKE2b-256 8542f62d62a75bb90c54916f5f954c6b2e6462d45383c16046456498925dae4a

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.0.7 This release

2 files

0.0.6

2 files

0.0.5

2 files

0.0.4

2 files

0.0.3

2 files

0.0.2

2 files

0.0.1

2 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