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.0b122.tar.gz
(60.5 kB
view details)
Built Distribution
File details
Details for the file openmeter-1.0.0b122.tar.gz
.
File metadata
- Download URL: openmeter-1.0.0b122.tar.gz
- Upload date:
- Size: 60.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 PyPy/7.3.16 Linux/6.5.0-1023-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0d6bd7a6a8f22e9b12274dae6f17308684ef542fc6278fd6bf93fd61fbceeda0 |
|
MD5 | 61cc2453fa3738550408852606f91b8e |
|
BLAKE2b-256 | 7a9682c1c2e5e658818e82f50a8d8e1818e26c175d591065a679ce0791db4680 |
File details
Details for the file openmeter-1.0.0b122-py3-none-any.whl
.
File metadata
- Download URL: openmeter-1.0.0b122-py3-none-any.whl
- Upload date:
- Size: 67.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 PyPy/7.3.16 Linux/6.5.0-1023-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 797f73eee8e5fab6f21e20d026fe880db8d582ba0decda25f93d83df9047d409 |
|
MD5 | 83b5ff8c4258eccead66c05ff1a1337b |
|
BLAKE2b-256 | 509a3abfd4c9c522e5337a2061a2d2f6ee35c2c7b984ee7e98be5369af39ef00 |