Skip to main content

FluxMeter Python SDK

Send AI token usage events to FluxMeter for real-time aggregation and billing.

Website: fluxmeter.dev · GitHub · API reference

Install

pip install fluxmeter

Quick Start (3 lines)

from fluxmeter import FluxMeter

meter = FluxMeter(kafka_brokers="localhost:9094")
meter.track("cust_123", "gpt-4o", input_tokens=500, output_tokens=150)

OpenAI Integration

import time
from openai import OpenAI
from fluxmeter import FluxMeter

client = OpenAI()
meter = FluxMeter(kafka_brokers="localhost:9094", environment="production")

start = time.time()
response = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Hello!"}],
)
latency = int((time.time() - start) * 1000)

# One line to meter the usage
meter.track_openai("cust_123", response, latency_ms=latency)

Anthropic Integration

import anthropic
from fluxmeter import FluxMeter

client = anthropic.Anthropic()
meter = FluxMeter(kafka_brokers="localhost:9094")

response = client.messages.create(
    model="claude-sonnet-4-20250514",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Hello!"}],
)

meter.track_anthropic("cust_123", response)

Manual Tracking (any provider)

meter.track(
    customer_id="cust_123",
    model_id="gemini-1.5-pro",
    provider="google",
    input_tokens=2000,
    output_tokens=500,
    request_id="req_abc123",
    span_id="span_7f3a",          # link to your tracing
    session_id="sess_456",        # group by conversation
    latency_ms=890,
    environment="production",
    metadata={"feature": "code-review", "team": "platform"},
)

Configuration

meter = FluxMeter(
    kafka_brokers="kafka1:9092,kafka2:9092",  # Kafka cluster
    topic="token-events",                       # Topic name (default)
    environment="production",                   # Applied to all events
    producer_config={                           # Extra Kafka producer config
        "security.protocol": "SASL_SSL",
        "sasl.mechanisms": "PLAIN",
        "sasl.username": "...",
        "sasl.password": "...",
    },
)

How It Works

Your App  →  meter.track(...)  →  Kafka  →  Flink (real-time aggregation)  →  Redis
                                                                                 ↓
                                                                           Grafana / API

Events are batched and compressed (lz4) before sending. The SDK flushes automatically on process exit.

Requirements

  • Python 3.9+
  • confluent-kafka (librdkafka-based, high performance)
  • FluxMeter infrastructure running (Kafka + Flink + Redis)

Download files

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

Source Distribution

fluxmeter-1.3.0.tar.gz (10.7 kB view details)

Uploaded Source

Built Distribution

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

fluxmeter-1.3.0-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

Details for the file fluxmeter-1.3.0.tar.gz.

File metadata

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

File hashes

Hashes for fluxmeter-1.3.0.tar.gz
Algorithm Hash digest
SHA256 af344bb5faaad5fbcaa351182bfc907ba7ff620cebe2bde80be8ff4fdea8fa2a
MD5 732ceb9787ad6699c25a0c171b08e0f9
BLAKE2b-256 55ee0354a19f0873cd9c625b82337a1f1b70ffb6b807776bc23af94610a117e1

See more details on using hashes here.

Provenance

The following attestation bundles were made for fluxmeter-1.3.0.tar.gz:

Publisher: pypi-publish.yml on 10kshuaizhang/fluxmeter

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

File details

Details for the file fluxmeter-1.3.0-py3-none-any.whl.

File metadata

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

File hashes

Hashes for fluxmeter-1.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5ad78962ebf31428bddc1867a05090b33cc12f99f6fa07f11ad7d6ebe116dca6
MD5 aa60fcc557221e39e1d84cf56f05c0a7
BLAKE2b-256 0d803b44a4b16887f683ea85c81c3ccb60c184cf6dfb82027e0a15d0707bf315

See more details on using hashes here.

Provenance

The following attestation bundles were made for fluxmeter-1.3.0-py3-none-any.whl:

Publisher: pypi-publish.yml on 10kshuaizhang/fluxmeter

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 Sentry Error logging StatusPage Status page