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.0b80.tar.gz
(47.3 kB
view details)
Built Distribution
File details
Details for the file openmeter-1.0.0b80.tar.gz
.
File metadata
- Download URL: openmeter-1.0.0b80.tar.gz
- Upload date:
- Size: 47.3 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 | 4720d12ccc877f436191ec65274e38b4d3a886252d64ade12bb7a6f9b79fffd9 |
|
MD5 | c074bc0caf172040e44f401e0d9f6fd8 |
|
BLAKE2b-256 | 45722b154a1285d230771dc35907e8cb31ad9b63af6e94a5e3af96b02275f9d2 |
File details
Details for the file openmeter-1.0.0b80-py3-none-any.whl
.
File metadata
- Download URL: openmeter-1.0.0b80-py3-none-any.whl
- Upload date:
- Size: 53.8 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 | 94e455ff62b9da3c7c81bc06f06e68236bbe11a0f5f7e9cef22790fa7a38ea18 |
|
MD5 | 7edf2209c48e17cf42e22985531c5107 |
|
BLAKE2b-256 | b40d1d3f7a814c2b9c1a7368c989224da7bc079f924c2b80e7555fa448940910 |