APIPurse SDK — Python
Python port of sdk/apipurse-sdk (the TypeScript reference implementation).
Dependency-free (standard library only) client for /api/track/completion —
the real-time tracking endpoint. Verified end-to-end in this repo's sandbox
against fake OpenAI/Anthropic-shaped clients (streaming + non-streaming).
Two integration styles, both call the same endpoint under the hood:
- Automatic (
wrap_openai()/wrap_anthropic()) — wrap your existing client once at setup; every subsequent.create()call is tracked with zero changes at each call site. Works with both sync and async clients (OpenAI/AsyncOpenAI,Anthropic/AsyncAnthropic) — detected automatically. - Manual (
APIPurse.track_completion()) — call it yourself right after a completion.
Neither is a network proxy: no request or response data is ever routed through APIPurse's servers. Only the model ID and token counts are sent.
Install
Not yet published to PyPI. Copy the apipurse/ folder into your project, or:
pip install -e /path/to/sdk-python
Usage
import os
from openai import OpenAI
from apipurse import APIPurse, wrap_openai
apipurse = APIPurse(
ingest_token=os.environ["APIPURSE_INGEST_TOKEN"],
provider_id=os.environ["APIPURSE_PROVIDER_ID"],
base_url="https://your-apipurse-domain.com",
)
client = wrap_openai(OpenAI(), apipurse)
# Tracked automatically:
completion = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "Hello"}],
)
For Anthropic:
from anthropic import Anthropic
from apipurse import wrap_anthropic
client = wrap_anthropic(Anthropic(), apipurse)
message = client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=1024,
messages=[{"role": "user", "content": "Hello"}],
)
Manual path (any provider, any call shape):
result = apipurse.track_completion(
model="gpt-4o", input_tokens=120, output_tokens=48,
)
Publishing to PyPI
Ships as plain source. To publish: add a [project] version bump
workflow, then python -m build && twine upload dist/*. Needs a PyPI
account/org you control — not done here.
Metadata
Release files for apipurse-sdk 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| apipurse_sdk-0.1.0.tar.gz | 5.6 kB | Without provenance | Details for apipurse_sdk-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| apipurse_sdk-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for apipurse_sdk-0.1.0-py3-none-any.whl |
Total release size: 13.1 kB
Release files / apipurse_sdk-0.1.0.tar.gz
| Download URL | apipurse_sdk-0.1.0.tar.gz |
|---|---|
| Size | 5.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cb2b4bd4eb79639937c3e8bc948a45fd0d8bfa8eb6fd35337cf7fbd8b55f779f
|
|
BLAKE2b-256 checksum How to use checksums |
59aa01b07e183da3e78e5610c8884f6b40f64a4f2c65931e08ab58a7b291e07f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.6
|
Release files / apipurse_sdk-0.1.0-py3-none-any.whl
| Download URL | apipurse_sdk-0.1.0-py3-none-any.whl |
|---|---|
| Size | 7.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3eda37b938ae585b0be2361e3b0d878350150a45ec417acad99ef67af3680752
|
|
BLAKE2b-256 checksum How to use checksums |
2c31aaf03b80bebc71c263e97abd73aa33c571fb4f6bb3644d4930364efbfa64
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.6
|
Security for apipurse-sdk 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.