Skip to main content

Client for OpenMeter: Real-Time and Scalable Usage Metering

Project description

OpenMeter Python SDK

[https://pypi.org/project/openmeter](On PyPI)

Prerequisites

Python version: >= 3.9

Install

The Python SDK is in preview mode.

pip install openmeter

Quickstart

The client can be initialized with openmeter.Client():

from os import environ
from openmeter import Client

ENDPOINT = environ.get("OPENMETER_ENDPOINT") or "http://localhost:8888"

# it's recommended to also set the Accept header at the client level
client = Client(
    endpoint=ENDPOINT,
    headers={"Accept": "application/json"},
)

Async client can be initialized by importing the Client from openmeter.aio.

Ingest events:

from cloudevents.http import CloudEvent
from cloudevents.conversion import to_dict

event = CloudEvent(
    attributes={
        "type": "tokens",
        "source": "openmeter-python",
        "subject": "user-id",
    },
    data={
        "prompt_tokens": 5,
        "completion_tokens": 10,
        "total_tokens": 15,
        "model": "gpt-3.5-turbo",
    },
)

resp = client.ingest_events(to_dict(event))

Publish

Update version number in pyproject.toml. Run the following commands:

poetry config pypi-token.pypi {your_pypi_api_token}
poetry publish --build

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

openmeter-1.0.0b108.tar.gz (50.0 kB view hashes)

Uploaded Source

Built Distribution

openmeter-1.0.0b108-py3-none-any.whl (56.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page