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.0b60.tar.gz
(38.2 kB
view details)
Built Distribution
File details
Details for the file openmeter-1.0.0b60.tar.gz
.
File metadata
- Download URL: openmeter-1.0.0b60.tar.gz
- Upload date:
- Size: 38.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.10.12 Linux/6.5.0-1016-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 50140f7ecf8697aa8de0a0ba319b9ba779c93a846c7692c4b0bffce071e95f9c |
|
MD5 | 830522cb3cb7767bc0c805d8c5e34ae3 |
|
BLAKE2b-256 | a0b7f050a5e507d96c22e5849b7e5176592df92d11322bfba03620194fab9664 |
File details
Details for the file openmeter-1.0.0b60-py3-none-any.whl
.
File metadata
- Download URL: openmeter-1.0.0b60-py3-none-any.whl
- Upload date:
- Size: 44.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.10.12 Linux/6.5.0-1016-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cf7400450736638e54dd188e99cabe6a975aad7742ad7a02283ced7577f69450 |
|
MD5 | ee373f6a420ddc4c0e744b720136c0aa |
|
BLAKE2b-256 | 117d7cf741e09bc6f77bcb27fdda2890d61a1a77b092396a5e06a3b8e51a4ba3 |