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.0b87.tar.gz
(48.8 kB
view details)
Built Distribution
File details
Details for the file openmeter-1.0.0b87.tar.gz
.
File metadata
- Download URL: openmeter-1.0.0b87.tar.gz
- Upload date:
- Size: 48.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 PyPy/7.3.16 Linux/6.5.0-1021-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | be79567b938839dc061cdf62d28e727fdb28477b84671d7495cdff811035f48c |
|
MD5 | 9685c29d7559061cef5124aac3744999 |
|
BLAKE2b-256 | 875c0b60da1eb821e46f38123925d21384585958f181ca75e2b7a765b55f44fb |
File details
Details for the file openmeter-1.0.0b87-py3-none-any.whl
.
File metadata
- Download URL: openmeter-1.0.0b87-py3-none-any.whl
- Upload date:
- Size: 55.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 PyPy/7.3.16 Linux/6.5.0-1021-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bd3c755f877ded075f99076b040d1a768ba19abe1006df23d167c5c2b2cda603 |
|
MD5 | d3ce2cb34cf0e132412d856ff9c0ca2d |
|
BLAKE2b-256 | b4f881e5112a40d43c751225025a381dc0cf07d559fc6fa347349f2eba02841d |