Compress logs for LLM analysis (Rust-powered)
Project description
logzip (Rust)
Compress logs before sending to LLM. Powered by Rust & PyO3.
raw log → [logzip compress] → compressed text → LLM (Claude Code / Cursor / API)
Before / After
Raw Log (Uvicorn):
INFO: 127.0.0.1:45678 - "GET /api/v1/status HTTP/1.1" 200 OK
INFO: 127.0.0.1:45679 - "GET /api/v1/status HTTP/1.1" 200 OK
... (100 similar lines) ...
logzip output:
--- PREFIX ---
INFO: 127.0.0.1:
--- LEGEND ---
#0# = - "GET /api/v1/status HTTP/1.1" 200 OK
--- BODY ---
45678 #0#
45679 #0#
...
Typical savings: 52–58% on structured logs (systemd, uvicorn, docker).
Anomalies and unique lines stay uncompressed — visible at a glance in the BODY.
Why use logzip? (RAG & LLM)
When working with logs in LLMs (Claude, GPT, RAG systems), you face two problems:
- Context Limit: Logs are huge. A 10MB log is ~2.5M tokens.
- Noise: 90% of the log consists of repeating
INFOand identical requests that drown out the real error.
logzip is well-suited for RAG pipelines: it compresses the context before sending it to the model, saving money on tokens and increasing answer accuracy by highlighting anomalies.
Performance (7.96 MB Log, ~2M tokens)
Benchmarked on a real 7.96 MB production log.
logzip modes
| Mode | CLI | Time (ms) | Size (KB) | Saved (%) | Output type |
|---|---|---|---|---|---|
| fast | --quality fast |
~200 | ~4,900 | ~40% | text/LLM |
| balanced | --quality balanced |
404 | 3,928 | 52% | text/LLM |
| balanced + 2 passes ★ | --quality balanced --bpe-passes 2 |
418 | 3,404 | 58% | text/LLM |
| max | --quality max |
507 | 3,511 | 57% | text/LLM |
★ Recommended. A second compression pass finds repeated token sequences in already-compressed text — 14 ms overhead, 7% more savings vs balanced.
--quality max uses a larger legend (512 vs 128 entries) which adds overhead without a second pass benefit. Use --bpe-passes 2 with balanced instead.
vs. binary compressors (for context)
| Tool | Time (ms) | Size (KB) | Saved (%) | LLM-readable? |
|---|---|---|---|---|
| lz4 | 6 | 1,280 | 84% | No |
| zstd (lvl 3) | 14 | 819 | 90% | No |
| zlib (lvl 6) | 69 | 840 | 90% | No |
| logzip (recommended) | 418 | 3,404 | 58% | Yes |
Binary compressors produce opaque binary blobs — LLMs cannot read them. logzip trades ~30% size for fully human- and LLM-readable output.
Token estimation: 1 token ≈ 4 characters (rough estimate for English-like logs).
Economic Impact
┌──────────────────────────────────────────────────────────┐
│ logzip Savings (7.96 MB Production Log) │
├──────────────────────────────────────────────────────────┤
│ Raw Size: 8,151 KB (~1,990,000 tokens) │
│ After balanced: 3,928 KB (~959,000 tokens, -52%) │
│ After 2 passes: 3,404 KB (~831,000 tokens, -58%) │
├──────────────────────────────────────────────────────────┤
│ Cost Before: $5.97 │
│ Cost After: $2.49 (Claude 3.5 Sonnet Input) │
│ LLM Efficiency: 2.4x larger context for the same price │
└──────────────────────────────────────────────────────────┘
Install
Python API + logzip-py CLI:
pip install logzip
Rust CLI + MCP Server:
cargo install logzip
CLI
Two CLIs are available. Both provide compress and decompress subcommands with identical flags.
Rust binary (cargo install logzip → logzip):
# stdin → stdout
logzip compress < app.log
# quality preset (fast|balanced|max)
logzip compress --quality balanced < app.log
# recommended: balanced + second pass
logzip compress --quality balanced --bpe-passes 2 < app.log
# with preamble (LLM decode instructions at the top)
logzip compress --preamble < app.log > compressed.txt
# save + show stats
logzip compress --stats -i app.log -o app.logzip
# decompress
logzip decompress -i app.logzip
Python CLI (pip install logzip → logzip-py):
# same flags as above, plus:
# explicit profile (otherwise auto-detected)
logzip-py compress --profile journalctl < /tmp/syslog.txt
Python API
from logzip import compress, decompress
# compress
result = compress(raw_log_text)
print(result.render(with_preamble=True)) # → for LLM
print(result.stats_str()) # → for logs
# fine-grained control
result = compress(
raw_log_text,
max_legend_entries=128, # legend size
bpe_passes=2, # second-pass compression (compresses repeated token sequences)
do_normalize=True, # collapse timestamps, ANSI, IPs
do_templates=True, # structural template extraction
)
# decompress
original = decompress(result.render())
MCP Server (Claude Desktop / Claude Code)
Requires the Rust binary (cargo install logzip, see Install).
Add to your claude_desktop_config.json:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json
{
"mcpServers": {
"logzip": {
"command": "logzip",
"args": ["mcp", "--allow-dir", "/var/log", "--allow-dir", "/home/user/logs"]
}
}
}
Or add via Claude Code CLI:
claude mcp add logzip -- logzip mcp --allow-dir /var/log
Available tools
| Tool | Description |
|---|---|
get_stats(path) |
File size, token estimate, detected profile — call first to decide strategy |
compress_file(path, quality) |
Compress entire file — for files < 200 K tokens |
compress_tail(path, lines, quality) |
Compress last N lines — efficient for large files |
Available prompts
| Prompt | Description |
|---|---|
analyze_logs |
Compresses the log server-side and prepares an SRE analysis context |
How to use
LLMs don't automatically pick up MCP tools — you need to reference them explicitly. Two ways:
Option A — explicit ask (works everywhere):
"Use logzip to analyze
/var/log/syslog"
Option B — analyze_logs prompt (Claude Code):
/mcp → logzip → analyze_logs → path: /var/log/syslog
This compresses the log server-side and drops an SRE-ready context into the conversation.
Option C — install the log-analysis skill (Claude Code, recommended):
The skill makes Claude automatically reach for logzip whenever you mention a log file — no explicit instruction needed.
# 1. Add the logzip repo as a plugin marketplace
claude plugin marketplace add NailShakurov/logzip
# 2. Install the plugin
claude plugin install logzip@NailShakurov/logzip
After that, asking "what's in /var/log/syslog?" is enough — Claude calls get_stats and compress_tail on its own.
Security
The MCP server only reads files inside directories specified via --allow-dir.
If no --allow-dir is given, defaults to the current working directory.
All paths are canonicalized before comparison to prevent path traversal attacks.
Through the eyes of an LLM
Unlike gzip/zstd which produce binary noise, logzip produces structured text. The model reads the legend once and works with the compressed body directly — it doesn't need to expand every token to understand the log.
Input for LLM:
This is a compressed log. Rules:
#0#is replaced byGET /api/v1/status.--- BODY --- 12:00:01 #0# 200 OK 12:00:02 #0# 500 ERR <-- Boom, anomaly!
The model instantly spots the 500 error without wading through thousands of identical successful requests.
Architecture & Safety
Pipeline: normalize → find patterns → compress → refine → extract templates
- Normalizer: Collapses ANSI, timestamps, IPs, and common prefixes.
- Frequency Analysis: Parallel n-gram counting using
rayon. - Greedy Legend: Optimized selection using a positional index (O(N)).
- Direct Replacement: Fast substitution without re-scanning.
- Second Pass: Compresses repeated token sequences in the already-compressed body.
- Templates: Structural template extraction.
Safety First
- Pure Rust: Core logic is 100% Rust.
- Zero
unsafe: The codebase contains no unsafe blocks, ensuring memory safety within the Python runtime. - Stress-tested: Handled multi-GB logs without memory leaks or crashes.
Reproducibility
Want to verify our benchmarks? Run the included script:
python benchmark.py
Roadmap
Priority:
- Streaming mode for multi-GB logs
Planned:
- MCP server for Claude Code
- Suffix automaton for arbitrary repetition search
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file logzip-2.1.0.tar.gz.
File metadata
- Download URL: logzip-2.1.0.tar.gz
- Upload date:
- Size: 21.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7a7aec010703648cc4cdc1b078ffb06e84dacecb816ef3926861d43555857369
|
|
| MD5 |
66fff64c36619af447597c0290f08078
|
|
| BLAKE2b-256 |
d26c6653c49b51f7afdc3ede7a84f3c5ce5a14e9e412229e211f2f43c56f0bc1
|
Provenance
The following attestation bundles were made for logzip-2.1.0.tar.gz:
Publisher:
publish.yml on NailShakurov/logzip
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
logzip-2.1.0.tar.gz -
Subject digest:
7a7aec010703648cc4cdc1b078ffb06e84dacecb816ef3926861d43555857369 - Sigstore transparency entry: 1368299009
- Sigstore integration time:
-
Permalink:
NailShakurov/logzip@8a15ed44bbd487599c98145533f01668fb35a316 -
Branch / Tag:
refs/tags/v2.1.0 - Owner: https://github.com/NailShakurov
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8a15ed44bbd487599c98145533f01668fb35a316 -
Trigger Event:
push
-
Statement type:
File details
Details for the file logzip-2.1.0-cp39-abi3-win_amd64.whl.
File metadata
- Download URL: logzip-2.1.0-cp39-abi3-win_amd64.whl
- Upload date:
- Size: 839.3 kB
- Tags: CPython 3.9+, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6da9323dd80e16fac44ab03e1891eed2c5479a30cd3db20c842f384ba90e3d13
|
|
| MD5 |
6bb3eb2e4bf03a6cb36a0f57410c3e20
|
|
| BLAKE2b-256 |
affb135fbdf82083d47eb84af5ad654efdfab886625ce6c8707e235976aa365e
|
Provenance
The following attestation bundles were made for logzip-2.1.0-cp39-abi3-win_amd64.whl:
Publisher:
publish.yml on NailShakurov/logzip
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
logzip-2.1.0-cp39-abi3-win_amd64.whl -
Subject digest:
6da9323dd80e16fac44ab03e1891eed2c5479a30cd3db20c842f384ba90e3d13 - Sigstore transparency entry: 1368299024
- Sigstore integration time:
-
Permalink:
NailShakurov/logzip@8a15ed44bbd487599c98145533f01668fb35a316 -
Branch / Tag:
refs/tags/v2.1.0 - Owner: https://github.com/NailShakurov
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8a15ed44bbd487599c98145533f01668fb35a316 -
Trigger Event:
push
-
Statement type:
File details
Details for the file logzip-2.1.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: logzip-2.1.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 919.2 kB
- Tags: CPython 3.9+, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
178cc72593b1050a6199f15df07440e9ed0e5a74dee7bf2a8f02af5ee47062f0
|
|
| MD5 |
a42d30503e3f7278d578b901152f3825
|
|
| BLAKE2b-256 |
fe851687dbb1040b0505f9fa2027a32de2000089a12087db564576f12cfbfcf1
|
Provenance
The following attestation bundles were made for logzip-2.1.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
publish.yml on NailShakurov/logzip
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
logzip-2.1.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
178cc72593b1050a6199f15df07440e9ed0e5a74dee7bf2a8f02af5ee47062f0 - Sigstore transparency entry: 1368299019
- Sigstore integration time:
-
Permalink:
NailShakurov/logzip@8a15ed44bbd487599c98145533f01668fb35a316 -
Branch / Tag:
refs/tags/v2.1.0 - Owner: https://github.com/NailShakurov
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8a15ed44bbd487599c98145533f01668fb35a316 -
Trigger Event:
push
-
Statement type:
File details
Details for the file logzip-2.1.0-cp39-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl.
File metadata
- Download URL: logzip-2.1.0-cp39-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
- Upload date:
- Size: 1.7 MB
- Tags: CPython 3.9+, macOS 10.12+ universal2 (ARM64, x86-64), macOS 10.12+ x86-64, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f2057a405c8d1f73fd76a0c7bffb4867464a0d31837e7be5bdda4d20e51f451f
|
|
| MD5 |
529ab10921f184ac3bfec738daa85333
|
|
| BLAKE2b-256 |
c580471c9c5cd5a54b6787f7dc693e35db57972a3e21e4715b04e95203eca480
|
Provenance
The following attestation bundles were made for logzip-2.1.0-cp39-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl:
Publisher:
publish.yml on NailShakurov/logzip
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
logzip-2.1.0-cp39-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl -
Subject digest:
f2057a405c8d1f73fd76a0c7bffb4867464a0d31837e7be5bdda4d20e51f451f - Sigstore transparency entry: 1368299031
- Sigstore integration time:
-
Permalink:
NailShakurov/logzip@8a15ed44bbd487599c98145533f01668fb35a316 -
Branch / Tag:
refs/tags/v2.1.0 - Owner: https://github.com/NailShakurov
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8a15ed44bbd487599c98145533f01668fb35a316 -
Trigger Event:
push
-
Statement type: