Skip to main content

smoloki

PyPI version npm version

Tiny library to push logs to Grafana Loki in logfmt format.

CLI

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

import smoloki


def as_request_completed():
    smoloki.push_sync(
        {'service': 'web'},
        {'level': 'info', 'event': 'request_completed'},
    )

Usage in Python via client

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

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.

Metadata

Release files for smoloki 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for smoloki 0.1.2
File Size Uploaded
smoloki-0.1.2.tar.gz 5.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for smoloki 0.1.2
File Interpreter ABI Platform
smoloki-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 11.0 kB

Release files / smoloki-0.1.2.tar.gz

Download URL smoloki-0.1.2.tar.gz
Size 5.6 kB
Tags Source
SHA-256 checksum
How to use checksums
05831c57e603ab67c14b6e09ebd1c137e72bc28aae13494a3929e113662f1d0e
BLAKE2b-256 checksum
How to use checksums
d801c4f8386a1379e04413d8f8ef3563d6e5eefe46e438924de878ea795c78bc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.13

Release files / smoloki-0.1.2-py3-none-any.whl

Download URL smoloki-0.1.2-py3-none-any.whl
Size 5.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a8b4c2c1eb4be1d927671a1505ebb96434e5d7c5f9f7b617a0880d989825d845
BLAKE2b-256 checksum
How to use checksums
06ec9b5926e7a7645e6cae54d6b5432fd23f74bee21aeeb8a79e894ae13c90af
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.13

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.19

2 release files

0.0.18

2 release files

0.0.17

2 release files

0.0.14

3 release files

0.0.12

3 release files

0.0.11

3 release files

0.0.10

3 release files

0.0.9

3 release files

0.0.8

3 release files

0.0.7

3 release files

0.0.6

3 release files

0.0.5

3 release files

0.0.4

3 release files

0.0.3

3 release files

0.0.2

3 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page