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.0b116.tar.gz
(56.0 kB
view details)
Built Distribution
File details
Details for the file openmeter-1.0.0b116.tar.gz
.
File metadata
- Download URL: openmeter-1.0.0b116.tar.gz
- Upload date:
- Size: 56.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 PyPy/7.3.16 Linux/6.5.0-1022-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 25fc9529240fc4e1336775c339fae0073c25dd201d51be2459828fa8c40cb021 |
|
MD5 | 7e37fa89b1931c00fc70b3032f15eabc |
|
BLAKE2b-256 | 6b2c9cea4aacb2c2f09d49c9ee1c5515b48018341e14302053159d144ae1131b |
File details
Details for the file openmeter-1.0.0b116-py3-none-any.whl
.
File metadata
- Download URL: openmeter-1.0.0b116-py3-none-any.whl
- Upload date:
- Size: 62.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 PyPy/7.3.16 Linux/6.5.0-1022-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7f021116d1d385e94809bcc1c63795f509883be04cc556f55693104a4d5bdbc3 |
|
MD5 | 4b0eeae17d698ca4a94f25c4752193b4 |
|
BLAKE2b-256 | aca21ac99180ae4fc3ab9b0c2c99fd5f5f3ad37f4909262260244e0d8e6c192a |