Skip to main content

Python SDK for the Mainwave AI observability platform

Project description

mainwave

Python SDK for the Mainwave AI observability platform.

Install

pip install "mainwave[openai]"        # one platform
pip install "mainwave[langchain]"     # LangChain + a callback handler
pip install "mainwave[all]"           # everything (kick-the-tires only)

Per-platform pinning is recommended in production.

Quickstart

import mainwave

mainwave.init(
    api_key="...",                                       # or MAINWAVE_API_KEY
    use_case_id="00000000-0000-0000-0000-000000000001",  # or MAINWAVE_USE_CASE_ID
    collector_url="https://collector.mainwave.com",      # default
)

with mainwave.run("INV-12345", metadata={"customer": "acme"}):
    # ... do work; auto-instrumented LLM calls land under this run
    ...

mainwave.flush()  # before exit

init() auto-wires every supported instrumentor that's already importable, so the snippet above needs no instrument() call. Reach for instrument() only to wire a framework imported after init() ran (lazy import, CLI subcommand, FastAPI lifespan) — see Public API.

mainwave.run(...) is optional — without it, every OTel trace becomes its own logical run. Wrap explicitly when one logical operation spans multiple traces (loops, fan-out, multiple LLM invocations per request); the integration guide wraps every agent execution for exactly this reason.

Not seeing data?

The SDK never raises into your app, so a misconfigured endpoint or key fails quietly. Turn on its logger to see what's happening:

import logging
logging.getLogger("mainwave").setLevel(logging.INFO)   # add a handler if you have none

At INFO it logs the first successful export, which instrumentors wired, and a WARNING for any framework that didn't. mainwave.flush() returns False on a failed drain — check it before a hard exit. Confirm collector_url and the API key, and that the framework's extra is installed (pip install "mainwave[openai]").

Public API

  • mainwave.init(...) — set up the SDK once, at process start.
  • mainwave.instrument(name=None) — re-wire instrumentors after late imports.
  • mainwave.run(...) / mainwave.arun(...) / mainwave.start_run(...) — open a logical run (sync CM, async CM, imperative).
  • mainwave.span(name, attrs=...) — escape hatch for manual spans.
  • mainwave.flush(timeout=30.0) / mainwave.aflush(timeout=30.0) — drain buffers.
  • mainwave.langchain.CallbackHandler — optional explicit LangChain handler.
  • mainwave.testingreset() + install_in_memory_provider() for tests.

LangChain users

Use the native CallbackHandler (captures model reasoning + step trajectory) OR auto-instrumentation (instrument(name="langchain")) — not both, or every call is double-counted. You don't have to police it: attaching the handler disables the OpenInference LangChain instrumentor automatically, and init(skip_instrumentors=["langchain"]) skips wiring it up front.

Several agents in one process

init() sets one use_case_id and service_name for the whole process. When a single process runs more than one agent — and you want each reported as its own use case or agent — override per invocation on the LangChain handler:

divergence = mainwave.langchain.CallbackHandler(
    use_case_id="…",          # which use case these spans roll up to
    service_name="divergence",  # which agent within it
)
chain.invoke(payload, config={"callbacks": [divergence]})

A handler's use_case_id / service_name apply only to the spans it emits, so several agents can share one use case (distinguished by service_name) or land in different use cases from the same process. Omit either to inherit the init() default; an empty value is ignored rather than applied.

See also

Spec: docs/agent_sdk/ in the platform monorepo.

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

mainwave-0.1.0rc2.tar.gz (33.3 kB view details)

Uploaded Source

Built Distribution

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

mainwave-0.1.0rc2-py3-none-any.whl (38.9 kB view details)

Uploaded Python 3

File details

Details for the file mainwave-0.1.0rc2.tar.gz.

File metadata

  • Download URL: mainwave-0.1.0rc2.tar.gz
  • Upload date:
  • Size: 33.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mainwave-0.1.0rc2.tar.gz
Algorithm Hash digest
SHA256 7d47fa01fda2d1927a21cbcf7527315cb8c8f10ba6ea3bbf8a9461683b6c44ec
MD5 5029ddf51b9f9f4cdcc3e4b12da6d889
BLAKE2b-256 fa97dfdf4c7e3cfb0decec1ed3eca6f8adeed81d24a9db5cf02379491b46b884

See more details on using hashes here.

Provenance

The following attestation bundles were made for mainwave-0.1.0rc2.tar.gz:

Publisher: sdk-publish.yml on mainwaveai/mainwave

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

File details

Details for the file mainwave-0.1.0rc2-py3-none-any.whl.

File metadata

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

File hashes

Hashes for mainwave-0.1.0rc2-py3-none-any.whl
Algorithm Hash digest
SHA256 6330f17ce10d44c1da8be08751cbe34d39c13ff3530e0420e65179c6c5a9b5d8
MD5 79f6fa564b4670b189e13cefd6ac23df
BLAKE2b-256 1dddead5d359e7cb2889349235568e1f8ecc2da83a1597fecd04d812ce27497b

See more details on using hashes here.

Provenance

The following attestation bundles were made for mainwave-0.1.0rc2-py3-none-any.whl:

Publisher: sdk-publish.yml on mainwaveai/mainwave

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