Skip to main content

loki-sdk

Loki-compatible logging SDK. Plain key=value wire format, per-service typed schemas, async-safe context propagation, auto-injected exception summary. Built on stdlib logging — no structlog/loguru.

Install

pip install loki-sdk

Usage

import logging
from loki_sdk import FieldSpec, LogSchema, LoggingConfig, bound, configure

SCHEMA = LogSchema(
    service_name="my-service",
    fields=(FieldSpec("status_code"), FieldSpec("duration_ms")),
)
configure(LoggingConfig.from_env(SCHEMA))
logger = logging.getLogger(__name__)

with bound(request_id="abc-123", endpoint="POST /clean-text"):
    logger.info("request_completed", extra={"status_code": 200, "duration_ms": 12.4})

Output:

2026-04-29T10:00:00Z [INFO] [my-service] [POST /clean-text] request_completed | status_code=200 duration_ms=12.4 request_id=abc-123

On exceptions, error="ClassName: msg" and caller=<module>:<func>:<lineno> are injected automatically.

Configuration

Read by LoggingConfig.from_env:

Variable Default Effect
LOG_LEVEL INFO Root log level.
LOG_FORMAT plain Wire format. Only plain is supported in v0.1.
LOG_CALLER_ON_ERROR 1 Inject caller= on records with levelno >= ERROR or exc_info.

Public API

Symbol Purpose
LogSchema Per-service field declaration.
FieldSpec One field in a LogSchema.
LoggingConfig Args for configure(). Prefer from_env(SCHEMA).
configure Wires the SDK into stdlib logging.
bind / reset Token-based contextvar binding.
bound Context-manager flavor of bind.
clear Reset the current logging context.
get_context Read-only snapshot of the current context dict.
get_logger Re-export of logging.getLogger.

License

Apache-2.0. See LICENSE.

Metadata

Release files for loki-sdk 0.1.1

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

Source distribution (sdist)

Source distribution for loki-sdk 0.1.1
File Size Uploaded Provenance
loki_sdk-0.1.1.tar.gz 11.4 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for loki-sdk 0.1.1
File Interpreter ABI Platform
loki_sdk-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 27.5 kB

Release files / loki_sdk-0.1.1.tar.gz

Download URL loki_sdk-0.1.1.tar.gz
Size 11.4 kB
Tags Source
SHA-256 checksum
How to use checksums
827c7332eb73d8d71f6e0b31815a41675706578c723bef49a836dfce9a66e955
BLAKE2b-256 checksum
How to use checksums
3fe9905ddd6137a594d1fb607e59c73b574964cc13fe809a7b36b0f469000220
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.0

Release files / loki_sdk-0.1.1-py3-none-any.whl

Download URL loki_sdk-0.1.1-py3-none-any.whl
Size 16.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4c066f94d74bd0fb30841ff971854f0af93f97b9215cd82028e524a09b1b37ad
BLAKE2b-256 checksum
How to use checksums
5a8d35c3fdee378b01b3d3467f2bf0f00633a51e868162228599f28b374f9527
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.0

Security for loki-sdk 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

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