hyzip
An auto-routing hybrid text compression engine that dynamically evaluates Brotli, MoeZip (context mixing), TikMax (BPE tokenization with LEB128 varint packing), Bzip2 (Burrows-Wheeler block sorting), and Raw Passthrough.
It guarantees zero data expansion on uncompressible or micro-text inputs while maintaining high-density block compression for larger archives.
Engine Roster
For every input string or byte payload, candidate backends are evaluated concurrently. The engine selecting the absolute smallest byte count is returned prepended with a 1-byte header flag.
| Header Flag | Byte Code | Engine | Workload Scope |
|---|---|---|---|
b'R' |
0x52 |
Raw Fallback | Uncompressed passthrough. Guarantees payload size never exceeds input length + 1 byte header. |
b'L' |
0x4C |
Brotli | LZ77 + Huffman + 2nd-order context modeling (Quality 11). Optimized for web/text content. |
b'M' |
0x4D |
MoeZip | Second-order context mixing for text streams (500 B to 50 KB). |
b'T' |
0x54 |
TikMax | BPE token packing (cl100k_base) with LEB128 varints for micro inputs (1 B to 500 B). |
b'B' |
0x42 |
Bzip2 | Burrows-Wheeler block sorting (Level 9). Evaluated when input size >= 32 bytes. |
Decompression reads the 1-byte header flag in $O(1)$ time and routes the body directly to the corresponding decoder.
Installation
pip install hyzip
Optional C/Rust Accelerators
Install optional high-performance backends for maximum compression ratios:
pip install brotli tiktoken moezip
- If
brotliis installed,hyzipevaluates Brotli Quality 11 candidates. - If
tiktokenis installed,hyzipuses C-accelerated BPE encoding. - If optional dependencies are missing,
hyzipautomatically falls back to embedded pure-Python implementations without failing.
Usage
Basic API
import hyzip
# Compress text (auto-selects absolute smallest payload)
compressed = hyzip.compress("Hello world! Do you like rock music?")
# Decompress back to string
text = hyzip.decompress(compressed)
Byte Stream Input and Output
import hyzip
raw_data = b"Raw binary bytes or compact JSON payload"
# Compress bytes or string
compressed = hyzip.compress(raw_data)
# Decompress and return raw bytes
decompressed_bytes = hyzip.decompress(compressed, return_bytes=True)
Zero Payload Expansion Guarantee
Standard algorithms (gzip, bzip2, zstd) often inflate small payloads due to fixed dictionary header overhead (e.g., compressing a 5-byte string results in a 40-byte output).
hyzip includes FLAG_RAW (b'R') in candidate evaluations:
- If all compressed engine outputs exceed
len(input) + 1,hyzipselectsFLAG_RAW. - Total payload overhead is strictly capped at input length + 1 byte.
TikMax Varint Encoding
Fixed 24-bit integer allocations waste space on small token IDs (e.g., token ID 68 stored as 0x000044).
TikMax uses LEB128 variable-length integer encoding:
- Token IDs < 128: 1 byte
- Token IDs < 16,384: 2 bytes
- Token IDs >= 16,384: 3 bytes
Because high-frequency tokens in BPE vocabularies map to low integer IDs, token streams are packed without requiring metadata headers.
Benchmarks
Results on a dataset of 188,378 dialogue messages (27.9 MB total):
| Algorithm | 150-Byte Micro Message | 27.9 MB Stream Batch | Compression Ratio |
|---|---|---|---|
| Gzip (Level 6) | Expands (+35%) | 8.21 MB (70.5% saved) | 3.4x |
| Bzip2 (Level 9) | Expands (+100%) | 5.92 MB (78.7% saved) | 4.71x |
| hyzip (v0.4.0) | Compresses (-35%) | 5.71 MB (79.08% saved) | 4.78x |
License
MIT
Metadata
Release files for hyzip 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| hyzip-0.4.0.tar.gz | 7.3 kB | Without provenance | Details for hyzip-0.4.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| hyzip-0.4.0-cp311-cp311-win_amd64.whl | CPython 3.11 | CPython 3.11 | Windows x86-64 | Details for hyzip-0.4.0-cp311-cp311-win_amd64.whl |
Total release size: 79.9 kB
Release files / hyzip-0.4.0.tar.gz
| Download URL | hyzip-0.4.0.tar.gz |
|---|---|
| Size | 7.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0f71751157f4fffa5286c152dff7dfc46bb32c38ceb3f2728103ba773aaf9124
|
|
BLAKE2b-256 checksum How to use checksums |
eefc08f67cec2d4cadfcee400d5fc1219bc37cabfebd057b666e2caa3a3792cd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.9
|
Release files / hyzip-0.4.0-cp311-cp311-win_amd64.whl
| Download URL | hyzip-0.4.0-cp311-cp311-win_amd64.whl |
|---|---|
| Size | 72.6 kB |
| Tags | CPython 3.11 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
1f6f4d5f1a6cc2bcc5da0760c71e202ba0a218835ff27cb984c36c886896f479
|
|
BLAKE2b-256 checksum How to use checksums |
1b19429340e49f160d6fa1c33899ee1b1c801747b1849be37e603fa3f3934f61
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.9
|
Security for hyzip 0.4.0
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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.