# 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/35/00/410469156e380847892f9d4573f72d0c57e923e901c40cece267762a5e05/openmeter-1.0.0b188.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.0b188",
"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": "bcf09e8f33b80732755aac4fdecf2a99fdf9df9b80846bc2894a1805743249bb",
"md5": "ba3c16b6ce7372dd311d69c24b0de1f5",
"sha256": "948b6947321f06f90f61fe685473328e2ee389505f2e36c7d65799d559febf59"
},
"downloads": -1,
"filename": "openmeter-1.0.0b188-py3-none-any.whl",
"has_sig": false,
"md5_digest": "ba3c16b6ce7372dd311d69c24b0de1f5",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.9",
"size": 75801,
"upload_time": "2025-02-11T11:20:40",
"upload_time_iso_8601": "2025-02-11T11:20:40.156724Z",
"url": "https://files.pythonhosted.org/packages/bc/f0/9e8f33b80732755aac4fdecf2a99fdf9df9b80846bc2894a1805743249bb/openmeter-1.0.0b188-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "3500410469156e380847892f9d4573f72d0c57e923e901c40cece267762a5e05",
"md5": "c4bb982b923eeae44d8da0914379b23a",
"sha256": "92bc288eb59862f10c7ab19b587f0e793a85f8851cbcc854e8e904e1981c8385"
},
"downloads": -1,
"filename": "openmeter-1.0.0b188.tar.gz",
"has_sig": false,
"md5_digest": "c4bb982b923eeae44d8da0914379b23a",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.9",
"size": 67985,
"upload_time": "2025-02-11T11:20:42",
"upload_time_iso_8601": "2025-02-11T11:20:42.093572Z",
"url": "https://files.pythonhosted.org/packages/35/00/410469156e380847892f9d4573f72d0c57e923e901c40cece267762a5e05/openmeter-1.0.0b188.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-02-11 11:20:42",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "openmeter",
"github_project": "openmeter",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "openmeter"
}