python-logging-loki
Python logging handler for Grafana Loki.
What it is and what it does
python-logging-loki is a Python logging handler that integrates with Grafana Loki, a log aggregation system. It captures log records from Python's standard logging module and ships them to a Loki instance via HTTP POST requests, attaching custom labels to organize and filter logs. The handler supports basic authentication and can operate in blocking mode or asynchronously via Python's built-in QueueHandler and QueueListener to avoid blocking application threads.
The package depends on requests for HTTP communication and rfc3339 for timestamp handling. It is designed for developers running Loki as their log backend who want to centralize Python application logs. The handler automatically includes message severity, logger name, and custom tags in each log entry sent to Loki.
Use it for:
- Centralize Python application logs into Grafana Loki for unified log aggregation and querying.
- Send application error and warning logs to Loki with custom labels for service identification.
- Integrate Python services with a Loki-based observability stack without external log shipping agents.
- Asynchronously forward logs to Loki using QueueHandler to avoid blocking application performance.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
A Python logging handler that sends log records to Grafana Loki via HTTP with support for custom labels and authentication.
Yes, if you run Grafana Loki and need to ship Python logs to it. The package is straightforward, has low dependencies, and carries no known vulnerabilities. However, maintenance is dormant since 2019-11-28, so compatibility with recent Loki API changes or Python versions beyond 3.8 is unverified. For active projects, confirm the handler works with your Loki version before relying on it in production.
Install
python-logging-loki on PyPI
pip
pip install python-logging-lokiuv
uv add python-logging-lokipoetry
poetry add python-logging-lokiInstalling python-logging-loki
Before you install
Low install friction with only 2 runtime dependencies (rfc3339, requests). Maintenance is dormant—last release was 2019-11-28 and last commit 2024-05-14—but the repository remains unarchived with 171 stars.
License in practice
MIT license is permissive; you can use, modify, and distribute this package freely with minimal restrictions.
Quickstart
pip install python-logging-loki
import logging
import python_logging_loki
handler = python_logging_loki.LokiHandler(
url="https://my-loki-instance/loki/api/v1/push",
tags={"application": "my-app"},
auth=("username", "password"),
version="1"
)
logger = logging.getLogger("my-logger")
logger.addHandler(handler)
logger.error("Something happened")
Requires a reachable Loki instance endpoint and network connectivity to push logs.
Verify before relying
- Whether the package works with Python versions beyond 3.8, given classifiers list only up to 3.8.
- Current compatibility with recent Loki API versions, given the gap since last release in 2019-11-28.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.6) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 2 — rfc3339, requests |
| Maintenance | dormant — 2,451 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 1,067,188/month — #4,410 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: python_logging_loki-0.3.1-py3-none-any.whl
Tags
More Python Modules packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
PyYAMLPyYAML parses and emits YAML 1.1 data format,…
permissive · top 100 on PyPI
pydanticPydantic validates Python data structures…
permissive · top 100 on PyPI
annotated-typesProvides reusable metadata objects for use with…
permissive · top 100 on PyPI
typing-inspectionProvides runtime tools to inspect and…
permissive · top 100 on PyPI
loki-logger-handlerA logging handler that sends Python log…
permissive · top 15,000 on PyPI
orchestra-sdkA lightweight SDK for self-hosted tasks to send…
permissive · top 15,000 on PyPI
splunk-hec-handlerIntegrates Python logging with Splunk's HTTP…
permissive · top 15,000 on PyPI
aws-logging-handlersRoutes Python logging records to AWS S3 and…
permissive · top 15,000 on PyPI
logging-treeVisualizes the hierarchy of loggers, handlers,…
permissive · top 15,000 on PyPI
pygelfProvides Python logging handlers that send log…
permissive · top 15,000 on PyPI
logzio-python-handlerA Python logging handler that sends logs in…
permissive · top 5,000 on PyPI
grafanalibGenerates Grafana dashboards from Python code,…
permissive · top 15,000 on PyPI
r7insight-pythonSends Python application logs and performance…
permissive · top 15,000 on PyPI
datadog-loggerSends Python log messages to Datadog as Events…
permissive · top 15,000 on PyPI