# 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/90/d3/106883340c4eefe1ebd0abf3d43ed6522d55d8ea662bcf2e9320c4834d47/openmeter-1.0.0b72.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.0b72",
"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": "4cd27f01687a4742ca7a073da6b7b7167ec398e28a58100491df7e9e6a921cb2",
"md5": "95c3cf5ca514af04f1eb365c292db505",
"sha256": "80a96ae3d7ea5d6ca56a2a28e457caa52ca4aafcf645b369104c35edc3566081"
},
"downloads": -1,
"filename": "openmeter-1.0.0b72-py3-none-any.whl",
"has_sig": false,
"md5_digest": "95c3cf5ca514af04f1eb365c292db505",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.9",
"size": 53204,
"upload_time": "2024-05-07T23:20:00",
"upload_time_iso_8601": "2024-05-07T23:20:00.576112Z",
"url": "https://files.pythonhosted.org/packages/4c/d2/7f01687a4742ca7a073da6b7b7167ec398e28a58100491df7e9e6a921cb2/openmeter-1.0.0b72-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "90d3106883340c4eefe1ebd0abf3d43ed6522d55d8ea662bcf2e9320c4834d47",
"md5": "59c9e48d958c4c8b2c434c69858ae10f",
"sha256": "fe6ab1a8a269b504fd92f18b37923154aa587e264cda1b682823bd2cfb171ffe"
},
"downloads": -1,
"filename": "openmeter-1.0.0b72.tar.gz",
"has_sig": false,
"md5_digest": "59c9e48d958c4c8b2c434c69858ae10f",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.9",
"size": 46701,
"upload_time": "2024-05-07T23:20:03",
"upload_time_iso_8601": "2024-05-07T23:20:03.554673Z",
"url": "https://files.pythonhosted.org/packages/90/d3/106883340c4eefe1ebd0abf3d43ed6522d55d8ea662bcf2e9320c4834d47/openmeter-1.0.0b72.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-05-07 23:20:03",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "openmeter",
"github_project": "openmeter",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "openmeter"
}