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, thenimport obol. The native library is bundled in the wheel — no Rust toolchain, nocargo build, noOBOL_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:
$OBOL_LIB— an explicit absolute path to the shared library.- Beside the installed
obolpackage (for packaged installs). target/release/thentarget/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")
print(est.total_usd, est.pricing_as_of)
for m in est.per_model:
print(m.model, m.provider, m.subtotal_usd)
# 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_path 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
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file primeradianthq_obol-0.4.0-py3-none-manylinux_2_28_x86_64.whl.
File metadata
- Download URL: primeradianthq_obol-0.4.0-py3-none-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 1.4 MB
- Tags: Python 3, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
71cc9f920952f15b450797bb21862328deca3adac550695617389bfa831d95ac
|
|
| MD5 |
7753b8a89ee16ddfefe0e2fd412d6528
|
|
| BLAKE2b-256 |
792dacee14bf7b6f16c40e93b4f9fc7b1904d7c6b9dd548c06e199b412284f1a
|
Provenance
The following attestation bundles were made for primeradianthq_obol-0.4.0-py3-none-manylinux_2_28_x86_64.whl:
Publisher:
pypi-release.yml on prime-radiant-inc/obol
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
primeradianthq_obol-0.4.0-py3-none-manylinux_2_28_x86_64.whl -
Subject digest:
71cc9f920952f15b450797bb21862328deca3adac550695617389bfa831d95ac - Sigstore transparency entry: 1769542070
- Sigstore integration time:
-
Permalink:
prime-radiant-inc/obol@653b7c003539b3d4b7d2083e7f673bcaa7b90577 -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/prime-radiant-inc
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-release.yml@653b7c003539b3d4b7d2083e7f673bcaa7b90577 -
Trigger Event:
push
-
Statement type:
File details
Details for the file primeradianthq_obol-0.4.0-py3-none-manylinux_2_28_aarch64.whl.
File metadata
- Download URL: primeradianthq_obol-0.4.0-py3-none-manylinux_2_28_aarch64.whl
- Upload date:
- Size: 1.3 MB
- Tags: Python 3, manylinux: glibc 2.28+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
07abfbec11a7a6b1bd9735f5cb983cad90b3d973e11c42e7c1aada7106fb4bdb
|
|
| MD5 |
d22e25f2b879811f093df635110c0845
|
|
| BLAKE2b-256 |
9179cdf62b223839384e6c30ae7f466cdb6d5d58f16dc17f503d35a90961c786
|
Provenance
The following attestation bundles were made for primeradianthq_obol-0.4.0-py3-none-manylinux_2_28_aarch64.whl:
Publisher:
pypi-release.yml on prime-radiant-inc/obol
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
primeradianthq_obol-0.4.0-py3-none-manylinux_2_28_aarch64.whl -
Subject digest:
07abfbec11a7a6b1bd9735f5cb983cad90b3d973e11c42e7c1aada7106fb4bdb - Sigstore transparency entry: 1769542809
- Sigstore integration time:
-
Permalink:
prime-radiant-inc/obol@653b7c003539b3d4b7d2083e7f673bcaa7b90577 -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/prime-radiant-inc
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-release.yml@653b7c003539b3d4b7d2083e7f673bcaa7b90577 -
Trigger Event:
push
-
Statement type:
File details
Details for the file primeradianthq_obol-0.4.0-py3-none-macosx_11_0_arm64.whl.
File metadata
- Download URL: primeradianthq_obol-0.4.0-py3-none-macosx_11_0_arm64.whl
- Upload date:
- Size: 1.2 MB
- Tags: Python 3, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
341eec33f0226c8c5110f5eb5db0a5c419cd213c7554106dab7a0d401239c0b6
|
|
| MD5 |
44f913f57dc3717514ffb54311689f0c
|
|
| BLAKE2b-256 |
76cc9bbe01bb03ffc372693171e2471bd231be734a846755818ebad91b7f7a11
|
Provenance
The following attestation bundles were made for primeradianthq_obol-0.4.0-py3-none-macosx_11_0_arm64.whl:
Publisher:
pypi-release.yml on prime-radiant-inc/obol
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
primeradianthq_obol-0.4.0-py3-none-macosx_11_0_arm64.whl -
Subject digest:
341eec33f0226c8c5110f5eb5db0a5c419cd213c7554106dab7a0d401239c0b6 - Sigstore transparency entry: 1769543516
- Sigstore integration time:
-
Permalink:
prime-radiant-inc/obol@653b7c003539b3d4b7d2083e7f673bcaa7b90577 -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/prime-radiant-inc
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-release.yml@653b7c003539b3d4b7d2083e7f673bcaa7b90577 -
Trigger Event:
push
-
Statement type:
File details
Details for the file primeradianthq_obol-0.4.0-py3-none-macosx_10_12_x86_64.whl.
File metadata
- Download URL: primeradianthq_obol-0.4.0-py3-none-macosx_10_12_x86_64.whl
- Upload date:
- Size: 1.3 MB
- Tags: Python 3, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3c2d18d1ccc62b9f84d6b612711437c297c0c332994879329ff78a92469c30e7
|
|
| MD5 |
b41569902c3148b77991b25afdc11abe
|
|
| BLAKE2b-256 |
2a1c6963d4136e917790dc13bae6e81960cca3359b27a8c8daeefa5faa70998d
|
Provenance
The following attestation bundles were made for primeradianthq_obol-0.4.0-py3-none-macosx_10_12_x86_64.whl:
Publisher:
pypi-release.yml on prime-radiant-inc/obol
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
primeradianthq_obol-0.4.0-py3-none-macosx_10_12_x86_64.whl -
Subject digest:
3c2d18d1ccc62b9f84d6b612711437c297c0c332994879329ff78a92469c30e7 - Sigstore transparency entry: 1769544844
- Sigstore integration time:
-
Permalink:
prime-radiant-inc/obol@653b7c003539b3d4b7d2083e7f673bcaa7b90577 -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/prime-radiant-inc
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-release.yml@653b7c003539b3d4b7d2083e7f673bcaa7b90577 -
Trigger Event:
push
-
Statement type: