# OpenMeter Python SDK
[https://pypi.org/project/openmeter](On PyPI)
## Prerequisites
Python version: >= 3.9
## Install
> The Python SDK is in preview mode.
```sh
pip install openmeter
```
## Quickstart
The client can be initialized with `openmeter.Client()`:
```python
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:
```python
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:
```sh
poetry config pypi-token.pypi {your_pypi_api_token}
poetry publish --build
```
Raw data
{
"_id": null,
"home_page": "https://openmeter.io",
"name": "openmeter",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.9",
"maintainer_email": null,
"keywords": "openmeter, api, client, usage, usage-based, metering, ai, aggregation, real-time, billing, cloud",
"author": "Andras Toth",
"author_email": "4157749+tothandras@users.noreply.github.com",
"download_url": "https://files.pythonhosted.org/packages/45/72/2b154a1285d230771dc35907e8cb31ad9b63af6e94a5e3af96b02275f9d2/openmeter-1.0.0b80.tar.gz",
"platform": null,
"description": "# OpenMeter Python SDK\n\n[https://pypi.org/project/openmeter](On PyPI)\n\n## Prerequisites\n\nPython version: >= 3.9\n\n## Install\n\n> The Python SDK is in preview mode.\n\n```sh\npip install openmeter\n```\n\n## Quickstart\n\nThe client can be initialized with `openmeter.Client()`:\n\n```python\nfrom os import environ\nfrom openmeter import Client\n\nENDPOINT = environ.get(\"OPENMETER_ENDPOINT\") or \"http://localhost:8888\"\n\n# it's recommended to also set the Accept header at the client level\nclient = Client(\n endpoint=ENDPOINT,\n headers={\"Accept\": \"application/json\"},\n)\n```\n\n**Async** client can be initialized by importing the `Client` from `openmeter.aio`.\n\nIngest events:\n\n```python\nfrom cloudevents.http import CloudEvent\nfrom cloudevents.conversion import to_dict\n\nevent = CloudEvent(\n attributes={\n \"type\": \"tokens\",\n \"source\": \"openmeter-python\",\n \"subject\": \"user-id\",\n },\n data={\n \"prompt_tokens\": 5,\n \"completion_tokens\": 10,\n \"total_tokens\": 15,\n \"model\": \"gpt-3.5-turbo\",\n },\n)\n\nresp = client.ingest_events(to_dict(event))\n```\n\n## Publish\n\nUpdate version number in `pyproject.toml`.\nRun the following commands:\n\n```sh\npoetry config pypi-token.pypi {your_pypi_api_token}\npoetry publish --build\n```\n",
"bugtrack_url": null,
"license": "Apache-2.0",
"summary": "Client for OpenMeter: Real-Time and Scalable Usage Metering",
"version": "1.0.0b80",
"project_urls": {
"Homepage": "https://openmeter.io",
"Repository": "https://github.com/openmeter/openmeter"
},
"split_keywords": [
"openmeter",
" api",
" client",
" usage",
" usage-based",
" metering",
" ai",
" aggregation",
" real-time",
" billing",
" cloud"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "b40d1d3f7a814c2b9c1a7368c989224da7bc079f924c2b80e7555fa448940910",
"md5": "7edf2209c48e17cf42e22985531c5107",
"sha256": "94e455ff62b9da3c7c81bc06f06e68236bbe11a0f5f7e9cef22790fa7a38ea18"
},
"downloads": -1,
"filename": "openmeter-1.0.0b80-py3-none-any.whl",
"has_sig": false,
"md5_digest": "7edf2209c48e17cf42e22985531c5107",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.9",
"size": 53772,
"upload_time": "2024-05-17T13:34:29",
"upload_time_iso_8601": "2024-05-17T13:34:29.808068Z",
"url": "https://files.pythonhosted.org/packages/b4/0d/1d3f7a814c2b9c1a7368c989224da7bc079f924c2b80e7555fa448940910/openmeter-1.0.0b80-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "45722b154a1285d230771dc35907e8cb31ad9b63af6e94a5e3af96b02275f9d2",
"md5": "c074bc0caf172040e44f401e0d9f6fd8",
"sha256": "4720d12ccc877f436191ec65274e38b4d3a886252d64ade12bb7a6f9b79fffd9"
},
"downloads": -1,
"filename": "openmeter-1.0.0b80.tar.gz",
"has_sig": false,
"md5_digest": "c074bc0caf172040e44f401e0d9f6fd8",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.9",
"size": 47307,
"upload_time": "2024-05-17T13:34:31",
"upload_time_iso_8601": "2024-05-17T13:34:31.708362Z",
"url": "https://files.pythonhosted.org/packages/45/72/2b154a1285d230771dc35907e8cb31ad9b63af6e94a5e3af96b02275f9d2/openmeter-1.0.0b80.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-05-17 13:34:31",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "openmeter",
"github_project": "openmeter",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "openmeter"
}