Python
SDK overview
Every function in the Recount Python SDK: tracing, spans, alerts, groups, metadata, and the table and chart builders.
The Recount SDK exports a top-level module with all functions. Import it once and use it anywhere in your app.
import recountFunctions
| Function | Description |
|---|---|
recount.init(options=None) | Override SDK defaults (optional) |
recount.start_trace(name, fn) | Wrap work in a trace |
recount.named(name, fn) | Name the next auto-instrumented span |
recount.add_span(type_, name, ...) | Add a span to the active trace |
recount.add_message(name, text=None, opts=None) | Add a message span |
recount.add_alert(label, level, opts=None) | Flag the most recent span |
recount.add_metadata(data) | Attach metadata to the active trace |
recount.fetch(name, url, method="GET", ...) | Traced HTTP request |
recount.table(title=None) | Build a table span |
recount.table_from_records(data, title=None) | Build a table directly from records |
recount.table_from_object(data, title=None) | Build a table directly from an object |
recount.span_cell(value, span) | Create a spanning cell |
recount.chart(chart_type, title=None) | Build a chart span |
recount.chart_from_records(chart_type, data, label_key, series_keys, title=None) | Build a chart directly from records |
Integrations
Wrap third-party clients to record spans automatically, without changing your business logic.
| Import | Description |
|---|---|
wrap_anthropic | Auto-trace Anthropic messages.create() calls |
wrap_openai | Auto-trace OpenAI chat.completions.create() calls |
wrap_collection | Auto-trace PyMongo collection operations |
from recount.integrations.anthropic import wrap_anthropic
from recount.integrations.openai import wrap_openai
from recount.integrations.pymongo import wrap_collectionInstall the matching extra to pull in the third-party package:
pip install "recount-sdk[anthropic,openai,pymongo]"wrap_anthropic and wrap_openai expect an async client (AsyncAnthropic, AsyncOpenAI). wrap_collection wraps a synchronous pymongo Collection - there is no separate Motor (async MongoDB) integration.
Other exports
from recount import (
RecountOptions,
TraceOptions,
SpanOptions,
SpanType,
SpanAlert,
SpanAlertCheck,
SpanAlertLevel,
SpanAlertOptions,
TableData,
ChartData,
SpanGroup,
Trace,
TableBuilder,
ChartBuilder,
RecountError,
REDACTED,
)See the types reference for full type definitions.