FluxMeter Python SDK
HTTP-only Python SDK for FluxMeter token metering and budget enforcement.
Budget checks are synchronous Redis reads. Latency is deployment-dependent (load, Redis, and network).
Python SDK 2.0.2 is versioned separately from engine/API 4.8.5 and JS SDK 2.0.0. Repository version does not confirm package-index publication.
Install
Requires 2.0.2 or newer. PyPI 1.5.0 does not export DeliveryError;
from fluxmeter import DeliveryError fails on that release.
pip install "fluxmeter>=2.0.2"
# or pin:
pip install fluxmeter==2.0.2
From a clone of this repository (before 2.0.2 is on PyPI, or to test a checkout):
pip install ./sdk/python
Usage
from fluxmeter import DeliveryError, FluxMeter
meter = FluxMeter(
api_url="http://localhost:8000",
api_key="fm_live_...",
environment="production",
)
try:
event_id = meter.track(
customer_id="cust_123",
model_id="gpt-4o",
input_tokens=500,
output_tokens=150,
parent_span_id="span_agent_42",
session_id="session_7",
)
except DeliveryError as error:
# The exception preserves the stable event ID used across bounded retries.
print(error.event_id)
track_openai, track_anthropic, and track_google extract usage from provider responses and send the same HTTP event contract. Direct track* calls raise typed delivery errors after bounded retries. FluxMeter returns acceptance only after Kafka acknowledgement and identity finalization; this is not settled billing. A quarantine receipt is not billable usage.
Direct Kafka configuration and the former local WAL were removed in 2.0.0. Kafka is an internal transport; applications should use /ingest or /ingest/batch.
See the API reference and v4 migration guide.
OpenAI wrapper: observe metering failures
import logging
from fluxmeter import wrap
logger = logging.getLogger(__name__)
def metering_failed(error):
# Send to your application's durable recovery/alerting path.
# DeliveryError preserves the event_id; retain provider usage in your app.
logger.error("Metering failure: %s, event_id=%s",
type(error).__name__, getattr(error, "event_id", None))
client = wrap(openai_client, meter, customer_id="cust_123",
fail_open=False, on_metering_error=metering_failed)
The callback receives the original exception on non-streaming tracking failures
and stream tracking failures. A warning is always logged. For compatibility, the
provider result remains available and callback exceptions are logged rather than
replacing that result. Do not retry a provider call just because its metering
failed: recover delivery of the original usage.
fail_open controls admission failure behavior only. wrap() reserves before
every call (streaming and not) and attaches reservationId on track so Flink
releases the hold at settlement. Do not call reconcile immediately after
/ingest. Unused holds (provider failure) are released immediately.
Metadata
Release files for fluxmeter 2.0.2
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 |
|---|---|---|---|---|
| fluxmeter-2.0.2.tar.gz | 14.8 kB | With provenance | Details for fluxmeter-2.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| fluxmeter-2.0.2-py3-none-any.whl | Python 3 | none | any | Details for fluxmeter-2.0.2-py3-none-any.whl |
Total release size: 27.6 kB
Release files / fluxmeter-2.0.2.tar.gz
| Download URL | fluxmeter-2.0.2.tar.gz |
|---|---|
| Size | 14.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4cdd4155a697aada4a8d66d3c1cfb84e49f26ec6bbba50050d61da3f3956c983
|
|
BLAKE2b-256 checksum How to use checksums |
668b6bac45e88c5c4573021f49e3722decd96f293e20006abcc97cc9c553ebf6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.
Transparency logRelease files / fluxmeter-2.0.2-py3-none-any.whl
| Download URL | fluxmeter-2.0.2-py3-none-any.whl |
|---|---|
| Size | 12.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
aa95a86ad2d42dde002f53c0bf3395ea8e1dc8f7d8d48f738bb75591ee1c63c2
|
|
BLAKE2b-256 checksum How to use checksums |
436549685c30fbae7cb3f3f9a922558f42e9aed3655ff8cf048b4f954fdcca8d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.
Transparency logSecurity for fluxmeter 2.0.2
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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for fluxmeter-2.0.2.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.
Transparency logA 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.