Skip to main content

OpenStat Python SDK

PyPI Python License: MIT

Native telemetry for AI agents, trading bots, and on-chain workflows.

OpenStat gives your app a structured timeline for agent runs: heartbeats, model completions, decisions, risk checks, paper orders, fills, positions, PnL snapshots, tool calls, errors, and chain transaction metadata.

Features

  • Agent-native events - send OpenStat lifecycle, decision, risk, trading, model, tool, error, and chain transaction events with one Python client.
  • Trading timeline helpers - record orders, fills, positions, and PnL snapshots using OpenStat-compatible event fields.
  • Run correlation - preserve run_id, strategy, symbol, venue, agent identity, trace IDs, span IDs, tags, and metadata across the whole run.
  • Vendor-neutral model telemetry - track provider, model, status, latency, token counts, and stage metadata without coupling your app to one LLM vendor.
  • OpenTelemetry-ready config - generate OTLP/HTTP URLs and auth headers for traces, logs, and metrics exporters.
  • Project scaffolding - run openstat init to add starter files to an existing Python app.
  • Zero runtime dependencies - the core SDK uses only the Python standard library.

Installation

Minimal SDK:

pip install openstat-sdk

For local development and tests:

pip install -e ".[test]"

Quick Start

from openstat import OpenStatClient

client = OpenStatClient(
    api_key="ostat_...",
    service_name="paper-trader",
    environment="production",
)

run = client.start_agent_run(strategy="breakout")
run_id = run["run_id"]
agent = {"id": "agent-1", "name": "Paper Trader"}

client.record_run_lifecycle(
    run_id=run_id,
    agent=agent,
    status="running",
    strategy="breakout",
    symbols=["BTC-USD"],
    summary="Run started.",
)

client.record_decision(
    run_id=run_id,
    agent=agent,
    strategy="breakout",
    symbol="BTC-USD",
    venue="paper",
    action="enter_long",
    confidence=82,
    rationale_summary="Momentum and risk budget aligned.",
)

client.record_run_lifecycle(
    run_id=run_id,
    agent=agent,
    status="completed",
    strategy="breakout",
    symbols=["BTC-USD"],
    summary="Run completed.",
)

endpoint defaults to https://api.openstat.online. Set OPENSTAT_ENDPOINT=http://localhost:4000 only when sending telemetry to a local OpenStat API during development.

Trading Agent Example

Use the trading helpers when you want OpenStat to render the full paper-trading timeline for one agent run.

decision_id = "decision-lp-1"

client.record_decision(
    run_id=run_id,
    agent=agent,
    decision_id=decision_id,
    strategy="paper-lp-v1",
    symbol="ETH-USDC",
    venue="paper",
    action="open",
    confidence=76,
)

client.record_risk_check(
    run_id=run_id,
    agent=agent,
    decision_id=decision_id,
    result="approved",
    reason="Within exposure and volatility limits.",
    metadata={
        "strategy": "paper-lp-v1",
        "symbol": "ETH-USDC",
        "risk_score": 32,
    },
)

client.record_order(
    run_id=run_id,
    agent=agent,
    strategy="paper-lp-v1",
    symbol="ETH-USDC",
    venue="paper",
    side="buy",
    order_type="market",
    quantity="1000",
    price="1",
    decision_id=decision_id,
    metadata={
        "paper_notional_usd": 1000,
        "estimation_method": "shadow_yield_only_v1",
    },
)

client.record_fill(
    run_id=run_id,
    agent=agent,
    strategy="paper-lp-v1",
    symbol="ETH-USDC",
    venue="paper",
    side="buy",
    quantity="1000",
    price="1",
    fee="1.00",
)

client.record_position(
    run_id=run_id,
    agent=agent,
    strategy="paper-lp-v1",
    symbol="ETH-USDC",
    venue="paper",
    quantity="1000",
    average_price="1",
    metadata={"market_value": "1000"},
)

client.record_pnl_snapshot(
    run_id=run_id,
    agent=agent,
    strategy="paper-lp-v1",
    symbol="ETH-USDC",
    realized_pnl="0",
    unrealized_pnl="3.42",
    equity="10003.42",
    metadata={"estimated": True, "venue": "paper"},
)

For domain-specific systems such as LP research, keep OpenStat's accepted trading fields (side, quantity, price, fee, order_type) in the event data and put pool addresses, range state, paper notional, or estimation methods inside metadata.

CLI

Add editable OpenStat starter files to an existing Python project:

openstat init

Choose a target path:

openstat init --path ./my-agent

Overwrite existing starter files:

openstat init --force

The command creates:

File Purpose
.env.openstat.example Environment variable template
openstat_integration.py Small client factory for your app
OPENSTAT.md Local integration notes

Configuration

The SDK constructor accepts explicit values, but most apps keep secrets and deployment-specific settings in environment variables.

Variable Description
OPENSTAT_API_KEY API key from the OpenStat dashboard
OPENSTAT_ENDPOINT API endpoint, defaults to hosted OpenStat
OPENSTAT_SERVICE_NAME App or service family name
OPENSTAT_ENVIRONMENT Deployment environment, such as dev or prod

OpenTelemetry

Generate OTLP/HTTP targets and headers for OpenTelemetry exporters:

from openstat import create_opentelemetry_http_config

otlp = create_opentelemetry_http_config(
    api_key="ostat_...",
    service_name="paper-trader",
)

print(otlp["traces"]["url"])
print(otlp["traces"]["headers"])

Examples

The repository includes a runnable trading-agent example:

python examples/trading_agent.py

Development

python -m pip install -e ".[test]"
python -m pytest

Build a local distribution:

python -m pip install build
python -m build

Links

License

MIT

Download files

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

Source Distribution

openstat_sdk-0.2.2.tar.gz (10.5 kB view details)

Uploaded Source

Built Distribution

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

openstat_sdk-0.2.2-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file openstat_sdk-0.2.2.tar.gz.

File metadata

  • Download URL: openstat_sdk-0.2.2.tar.gz
  • Upload date:
  • Size: 10.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for openstat_sdk-0.2.2.tar.gz
Algorithm Hash digest
SHA256 61f8cd80fe7a5759670ee21556c6146bf937f2b6d2df4ce7d6944138f59e4890
MD5 796bb69bf12d0457ed0258a4200501ed
BLAKE2b-256 622f05653ef3210d6c0aa3a5e2d3810e8b424f663844183af3d02799e9702d95

See more details on using hashes here.

Provenance

The following attestation bundles were made for openstat_sdk-0.2.2.tar.gz:

Publisher: workflow.yml on kezuflow/openstat

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

File details

Details for the file openstat_sdk-0.2.2-py3-none-any.whl.

File metadata

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

File hashes

Hashes for openstat_sdk-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6c18d59687eb047460e793c63a67c799ecd3ec930edc91c2718bda7368bc7808
MD5 b5e33a0e897fb2b86671887c0bed2d26
BLAKE2b-256 6cf78abf5db0f289105e7545ef2a1386649105ca6cc9071dae4ce46a5efa8c9c

See more details on using hashes here.

Provenance

The following attestation bundles were made for openstat_sdk-0.2.2-py3-none-any.whl:

Publisher: workflow.yml on kezuflow/openstat

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

Release history Release notifications | RSS feed

This release

0.2.2 This release

2 files

0.2.1

2 files

0.1.1

2 files

0.1.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page