drain3
Persistent & streaming log template miner
What it is and what it does
Drain3 is an online log template miner that continuously learns from a stream of raw log messages and groups them into clusters based on structural similarity. It uses a fixed-depth parse tree to efficiently guide the search process, avoiding the deep, unbalanced trees that plague naive clustering approaches. The core idea is to extract recurring patterns—templates—from logs by identifying which parts vary and which are constant, then replace variable portions with configurable masks (e.g., IP addresses become <:IP:>, integers become <:NUM:>).
The package supports both training and inference modes, persistence to file, Redis, or Kafka, and parameter extraction—pulling out the actual values that matched each variable slot in a template. It is designed for use in log aggregation, anomaly detection, and operational intelligence pipelines where you need to reduce noise and identify structural patterns in unstructured log data.
Use it for:
- Reduce log volume by grouping similar messages into templates before storage or alerting.
- Extract structured fields (IPs, user IDs, error codes) from free-text logs for downstream analysis.
- Detect anomalies by identifying when a log message does not match any known template.
- Monitor for network or system outages by tracking changes in template frequency or emergence of new templates.
- Build a baseline of normal log patterns, then flag deviations as potential security or operational incidents.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Drain3 extracts recurring patterns (templates) from streams of log messages, grouping similar logs and identifying variable parts with configurable masking rules.
Yes, if you need online log template mining and can tolerate dormant maintenance. The package is stable, has no known vulnerabilities, and solves a real problem in log analysis pipelines. However, do not expect active support or updates—treat it as a mature, feature-complete tool rather than an actively developed library. High install friction (source-only) is a minor friction point but not a blocker for most environments.
Install
drain3 on PyPI
pip
pip install drain3uv
uv add drain3poetry
poetry add drain3Installing drain3
Before you install
High install friction due to source distribution only. Maintenance is dormant—last release was 2022-07-17 and no commits since 2025-02-04, so expect no active bug fixes or feature updates.
License in practice
MIT license is permissive; you may use, modify, and distribute this package freely in commercial or private projects with minimal restrictions.
Quickstart
pip install drain3
from drain3 import TemplateMiner
miner = TemplateMiner()
result = miner.add_log_message('user alice logged in')
print(result['template_mined'])
Requires Python 3.6 or later; no external runtime dependencies, but source-only distribution may require a C compiler on some platforms.
Verify before relying
- Performance characteristics (throughput, latency) on typical log volumes and message sizes.
- Memory consumption and scalability limits when handling very large numbers of distinct templates.
- Compatibility with Python versions beyond 3.7 (classifiers list 3.6 and 3.7 only).
Package facts
| License | MIT (permissive) |
| Python support | not specified |
| Install friction | high — source build required |
| Runtime dependencies | none |
| Maintenance | dormant — 1,489 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 556,376/month — #6,021 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: drain3-0.9.11.tar.gz
Keywords: drain, log, parser, IBM, template, logs, miner
Tags
More Libraries packages
urllib3 is an HTTP client library that provides…
permissive · top 100 on PyPI
requestsRequests is a Python HTTP library that…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
python-dateutilProvides parsing, arithmetic, and recurrence…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
pytestpytest is a testing framework that lets you…
permissive · top 100 on PyPI
microsoft-security-utilities-secret-maskerDetects and masks sensitive data in text using…
permissive · top 5,000 on PyPI
riverRiver provides online machine learning…
permissive · top 15,000 on PyPI
regionmaskregionmask creates spatial masks for gridded…
permissive · top 15,000 on PyPI
rushrush provides rate-limiting algorithms…
permissive · top 15,000 on PyPI
drf-api-loggerCaptures and logs Django REST Framework API…
permissive · top 15,000 on PyPI
mozleakExtracts memory leaks from leak log files,…
copyleft · top 15,000 on PyPI
slurm-usageCollects and preserves SLURM job efficiency…
permissive · top 15,000 on PyPI
mo-logsProvides structured JSON logging with…
copyleft · top 15,000 on PyPI
commonregexExtracts dates, times, emails, phone numbers,…
permissive · top 15,000 on PyPI
pygrokParses strings and extracts structured data…
permissive · top 15,000 on PyPI