skillfed

python-logging-loki

Python logging handler for Grafana Loki.

python-logging-loki v0.3.1 1.1M downloads/30d#4,410 on PyPI171
Permissive license MIT DORMANT released

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-loki

uv

uv add python-logging-loki

poetry

poetry add python-logging-loki

Installing 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

Development Status :: 4 - BetaIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3.6Programming Language :: Python :: 3.7Programming Language :: Python :: 3.8Topic :: Internet :: WWW/HTTPTopic :: Software Development :: Libraries :: Python ModulesTopic :: System :: Logging

Tags

loki logging handlergrafana loki pythonsend logs to lokipython logging aggregationloki http log shipper
logginglokiobservability

More Python Modules packages