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.0b29.tar.gz
(33.6 kB
view details)
Built Distribution
File details
Details for the file openmeter-1.0.0b29.tar.gz
.
File metadata
- Download URL: openmeter-1.0.0b29.tar.gz
- Upload date:
- Size: 33.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.10.12 Linux/6.2.0-1016-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5e2d0f9ee4769b4d7881780254b7aba753183fea0e18bf139a23c287127d1855 |
|
MD5 | 90296c8af4f95a6f8ea58c51647e76ac |
|
BLAKE2b-256 | 6f0c539ff4e88d59476bff26fdfd5ed38af4b62bda066be7ca28a8920bd1094e |
File details
Details for the file openmeter-1.0.0b29-py3-none-any.whl
.
File metadata
- Download URL: openmeter-1.0.0b29-py3-none-any.whl
- Upload date:
- Size: 39.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.10.12 Linux/6.2.0-1016-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 497650c5da3d6d94fa65b07e828ac7e020016d4e9b622210787eb5d30b1270c4 |
|
MD5 | 5e7e416152a3610447fb1e2bea92db07 |
|
BLAKE2b-256 | 5bd853af7b0fe824d55b8f2c9ab8b582ddcb8c6be2492b8dda680768a1dc71b7 |