# smoloki
[](https://badge.fury.io/py/smoloki)
[](https://badge.fury.io/js/smoloki)
Tiny library to push logs to `Grafana Loki` in `logfmt` format.
## CLI
```text
usage: smoloki [-h] [-b BASE_ENDPOINT] [-H HEADERS] labels information
cli for pushing to loki
positional arguments:
labels json-encoded string with labels
information json-encoded string with information
optional arguments:
-h, --help show this help message and exit
-b BASE_ENDPOINT base address of loki server
-H HEADERS json-encoded string with headers for request to loki server
```
## Usage in Python
```py
import smoloki
def as_request_completed():
smoloki.push_sync(
{'service': 'web'},
{'level': 'info', 'event': 'request_completed'},
)
```
## Usage in Python via client
```py
from smoloki import SmolokiAsyncClient
async def push_via_client():
async with SmolokiAsyncClient(
base_endpoint = 'https://example.com',
headers = {...}
) as client:
await client.push(
{'service': 'web'},
{'level': 'info', 'event': 'request_completed'},
)
# or push in background
await client.push_in_background(
{'service': 'web'},
{'level': 'info', 'event': 'request_completed'},
)
```
## Usage in NodeJS
```js
const smoloki = require('smoloki');
async function as_request_completed() {
await smoloki.push({ service: 'web' }, { level: 'info', event: 'request_completed' });
}
```
## Implementation details
- Calls to `push` method will never throw. Any exception will just be
logged using `logging`.
- Keys in labels and information must be strings. If `None` is provided as
value in case of python, it will be serialized as empty string.
- Values in labels and information must be string, integers or floats.
- If no `base_endpoint` provided (using parameter or env), nothing will happen.
- When using SmolokiAsyncClient, the context manager waits for all background
tasks to be completed when exiting.
## Configuration
- `SMOLOKI_BASE_ENDPOINT` – base address of loki server.
- `SMOLOKI_HEADERS` - headers for request to loki server (can be used for authorization).
- `SMOLOKI_BASE_LABELS` - base labels that will be added to logs.
- `SMOLOKI_BASE_INFORMATION` - base information that will be added to logs.
Raw data
{
"_id": null,
"home_page": "https://github.com/michaelkryukov/smoloki",
"name": "smoloki",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": null,
"keywords": "library, loki",
"author": "Michael Krukov",
"author_email": "krukov.michael@ya.ru",
"download_url": "https://files.pythonhosted.org/packages/d9/7e/23227aec1948059504a4a258fb4616a5100a15db2eda61cc6bf038a4f38c/smoloki-0.1.1.tar.gz",
"platform": null,
"description": "# smoloki\n\n[](https://badge.fury.io/py/smoloki)\n[](https://badge.fury.io/js/smoloki)\n\nTiny library to push logs to `Grafana Loki` in `logfmt` format.\n\n## CLI\n\n```text\nusage: smoloki [-h] [-b BASE_ENDPOINT] [-H HEADERS] labels information\n\ncli for pushing to loki\n\npositional arguments:\n labels json-encoded string with labels\n information json-encoded string with information\n\noptional arguments:\n -h, --help show this help message and exit\n -b BASE_ENDPOINT base address of loki server\n -H HEADERS json-encoded string with headers for request to loki server\n```\n\n## Usage in Python\n\n```py\nimport smoloki\n\n\ndef as_request_completed():\n smoloki.push_sync(\n {'service': 'web'},\n {'level': 'info', 'event': 'request_completed'},\n )\n```\n\n## Usage in Python via client\n\n```py\nfrom smoloki import SmolokiAsyncClient\n\n\nasync def push_via_client():\n async with SmolokiAsyncClient(\n base_endpoint = 'https://example.com',\n headers = {...}\n ) as client:\n await client.push(\n {'service': 'web'},\n {'level': 'info', 'event': 'request_completed'},\n )\n \n # or push in background\n await client.push_in_background(\n {'service': 'web'},\n {'level': 'info', 'event': 'request_completed'},\n )\n\n```\n\n## Usage in NodeJS\n\n```js\nconst smoloki = require('smoloki');\n\nasync function as_request_completed() {\n await smoloki.push({ service: 'web' }, { level: 'info', event: 'request_completed' });\n}\n```\n\n## Implementation details\n\n- Calls to `push` method will never throw. Any exception will just be\n logged using `logging`.\n- Keys in labels and information must be strings. If `None` is provided as\n value in case of python, it will be serialized as empty string.\n- Values in labels and information must be string, integers or floats.\n- If no `base_endpoint` provided (using parameter or env), nothing will happen.\n- When using SmolokiAsyncClient, the context manager waits for all background\n tasks to be completed when exiting.\n\n## Configuration\n\n- `SMOLOKI_BASE_ENDPOINT` \u2013 base address of loki server.\n- `SMOLOKI_HEADERS` - headers for request to loki server (can be used for authorization).\n- `SMOLOKI_BASE_LABELS` - base labels that will be added to logs.\n- `SMOLOKI_BASE_INFORMATION` - base information that will be added to logs.\n",
"bugtrack_url": null,
"license": null,
"summary": "Tiny library to push logs to `Grafana Loki` in `logfmt` format.",
"version": "0.1.1",
"project_urls": {
"Homepage": "https://github.com/michaelkryukov/smoloki"
},
"split_keywords": [
"library",
" loki"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "88fc131a610c21146d5841226bc1256f855b63c7a864f1466e0c468418ddf27b",
"md5": "72270135b7bbedd4ca89425eb6b81791",
"sha256": "b45e3e202effdeef8a75e0a7b45f2d9c7fc73589e6aae3c77d02a1692ea5ebe9"
},
"downloads": -1,
"filename": "smoloki-0.1.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "72270135b7bbedd4ca89425eb6b81791",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 5376,
"upload_time": "2025-09-17T14:45:06",
"upload_time_iso_8601": "2025-09-17T14:45:06.368434Z",
"url": "https://files.pythonhosted.org/packages/88/fc/131a610c21146d5841226bc1256f855b63c7a864f1466e0c468418ddf27b/smoloki-0.1.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "d97e23227aec1948059504a4a258fb4616a5100a15db2eda61cc6bf038a4f38c",
"md5": "80baf19fc404d9308beefbc91465ff18",
"sha256": "c9a531b946f7d56c6a94d03d758e84b10e397c94980484dcc7ab05028113a4f5"
},
"downloads": -1,
"filename": "smoloki-0.1.1.tar.gz",
"has_sig": false,
"md5_digest": "80baf19fc404d9308beefbc91465ff18",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 5633,
"upload_time": "2025-09-17T14:45:07",
"upload_time_iso_8601": "2025-09-17T14:45:07.461307Z",
"url": "https://files.pythonhosted.org/packages/d9/7e/23227aec1948059504a4a258fb4616a5100a15db2eda61cc6bf038a4f38c/smoloki-0.1.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-09-17 14:45:07",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "michaelkryukov",
"github_project": "smoloki",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "smoloki"
}