Skip to main content

Estimate the USD cost of an AI-agent transcript (Claude Code, Codex, Pi).

Project description

obol — Python binding (ctypes)

Installing from PyPI: pip install primeradianthq-obol, then import obol. The native library is bundled in the wheel — no Rust toolchain, no cargo build, no OBOL_LIB. The sections below are for in-repo development.

A thin, pure-Python binding over obol's C ABI (obol-ffi). No build step: it loads the prebuilt shared library with ctypes and re-types the JSON the Rust core returns. The Rust core stays the single source of truth for all accounting; this package only marshals C strings and parses JSON into dataclasses.

Install / point at the library

The binding needs the obol-ffi shared library (libobol_ffi.dylib on macOS, libobol_ffi.so on Linux). It is located, in order:

  1. $OBOL_LIB — an explicit absolute path to the shared library.
  2. Beside the installed obol package (for packaged installs).
  3. target/release/ then target/debug/ relative to the repo root (for in-tree dev).

For in-tree development, just build the dylib and the target/debug fallback finds it with no env:

mise exec rust@1.96.0 -- cargo build -p obol-ffi

If the library lives somewhere else, set OBOL_LIB=/abs/path/to/libobol_ffi.dylib.

Usage

import obol

print(obol.version())  # "0.1.1"

est = obol.estimate_path("transcript.jsonl", dialect="claude")  # dialect=None auto-detects
print(est.total_usd, est.pricing_as_of)
for m in est.per_model:
    print(m.model, m.provider, m.subtotal_usd)

# Or from in-memory bytes:
est = obol.estimate_bytes(open("transcript.jsonl", "rb").read())

# Refresh the on-disk pricing snapshot (network; caller supplies the date):
report = obol.refresh("2026-06-05")

On a nonzero status, the call raises obol.ObolError carrying .code, .kind, and .message from the FFI error envelope.

Pricing tables must exist

estimate_* reads a pricing snapshot from disk. Either run obol refresh (the CLI), or point OBOL_PRICING_DIR at a directory containing current.json. With no snapshot the call raises ObolError with kind == "PricingTablesMissing" (code 1).

Ownership & safety contract

obol owns every string it returns through an out-parameter. This binding honors the contract automatically in _lib._decode_and_free: it copies the obol-owned C string into Python bytes, then calls obol_string_free, then the caller parses the copy. The Rust-owned pointer never outlives the copy and is never freed twice. obol_version() returns a static string and is never freed. You do not manage any of this yourself — the public API returns plain dataclasses.

Tests

mise exec rust@1.96.0 -- cargo build -p obol-ffi   # build the dylib first
cd bindings/python && PYTHONPATH=. python -m pytest tests -q

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

primeradianthq_obol-0.1.1-py3-none-manylinux_2_28_x86_64.whl (1.3 MB view details)

Uploaded Python 3manylinux: glibc 2.28+ x86-64

primeradianthq_obol-0.1.1-py3-none-manylinux_2_28_aarch64.whl (1.2 MB view details)

Uploaded Python 3manylinux: glibc 2.28+ ARM64

primeradianthq_obol-0.1.1-py3-none-macosx_11_0_arm64.whl (1.2 MB view details)

Uploaded Python 3macOS 11.0+ ARM64

primeradianthq_obol-0.1.1-py3-none-macosx_10_12_x86_64.whl (1.2 MB view details)

Uploaded Python 3macOS 10.12+ x86-64

File details

Details for the file primeradianthq_obol-0.1.1-py3-none-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for primeradianthq_obol-0.1.1-py3-none-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 c1caf7a9ed8d8dd9d8b80ad9c5a2337abe7974b1a43e8182edd307af584f4e67
MD5 1e7fda02b4e4ad04f68b0877bb8083da
BLAKE2b-256 0f72302010a05284fce8b123248fb993e462a2788e107afcce41ecba6f49760b

See more details on using hashes here.

Provenance

The following attestation bundles were made for primeradianthq_obol-0.1.1-py3-none-manylinux_2_28_x86_64.whl:

Publisher: pypi-release.yml on prime-radiant-inc/obol

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

File details

Details for the file primeradianthq_obol-0.1.1-py3-none-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for primeradianthq_obol-0.1.1-py3-none-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 aec62797419c2d2bf3c79b8231095958ac21cc03a93793d5eab05f88d8eeb806
MD5 c81ff2e5d47f4cb67a8e58f51706144e
BLAKE2b-256 89863000b5eae345f3569e80d96efe31cf6fec4d01f79adeee3e98bd2161c712

See more details on using hashes here.

Provenance

The following attestation bundles were made for primeradianthq_obol-0.1.1-py3-none-manylinux_2_28_aarch64.whl:

Publisher: pypi-release.yml on prime-radiant-inc/obol

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

File details

Details for the file primeradianthq_obol-0.1.1-py3-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for primeradianthq_obol-0.1.1-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1836a0c6682f6c6559cbb62789278369fe2d1ae8855b9e645f6da4651cf02f80
MD5 0b2958ad44b89e0693b9afaeb81276d4
BLAKE2b-256 e2d953b00080a83730d42a8a6e77822ca72c424601a152f805d51d80f0bf69d2

See more details on using hashes here.

Provenance

The following attestation bundles were made for primeradianthq_obol-0.1.1-py3-none-macosx_11_0_arm64.whl:

Publisher: pypi-release.yml on prime-radiant-inc/obol

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

File details

Details for the file primeradianthq_obol-0.1.1-py3-none-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for primeradianthq_obol-0.1.1-py3-none-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 8720d70df87dc0c2eaef43bc908e8796af0526a44ab5dcbdedd9d815aa16adf3
MD5 d029d0f4b1138f1a572c3bd1a7db8a85
BLAKE2b-256 8fcee56a4e93dc43c998191791d4749210336c068144937733470b98da247101

See more details on using hashes here.

Provenance

The following attestation bundles were made for primeradianthq_obol-0.1.1-py3-none-macosx_10_12_x86_64.whl:

Publisher: pypi-release.yml on prime-radiant-inc/obol

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