Skip to main content

hyzip

An auto-routing hybrid text compression engine that dynamically evaluates MoeZip (32-Expert MoE router with 2nd-order Markov context prediction and ANS range coding), TikMax (BPE tokenization with LEB128 varint packing), LZMA2 Extreme (7-Zip Preset 9 Extreme), 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 & Architecture
b'R' 0x52 Raw Fallback Uncompressed passthrough. Guarantees payload size never exceeds input length + 1 byte header.
b'T' 0x54 TikMax BPE subword tokenization (cl100k_base) with LEB128 varint packing for micro inputs (1 B to 500 B).
b'M' 0x4D MoeZip 32-Expert MoE router + 2nd-order Markov context prediction + ANS (Asymmetric Numeral Systems) range coding for text streams (32 B to 50 MB).
b'B' 0x42 Bzip2 Burrows-Wheeler block sorting (Level 9). Evaluated when input size >= 512 bytes.
b'X' 0x58 LZMA2 Extreme 64 MB sliding dictionary (Preset 9 + Extreme). Evaluated for payloads >= 512 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 Dependencies

Install optional high-performance backends for maximum compression ratios:

pip install tiktoken moezip
  • If tiktoken is installed, hyzip uses C-accelerated BPE encoding.
  • If optional dependencies are missing, hyzip automatically falls back to embedded pure-Python implementations or skips unsupported engines 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:

  1. If all compressed engine outputs exceed len(input) + 1, hyzip selects FLAG_RAW.
  2. 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

Benchmark evaluation conducted on a natural language text dataset containing 677,336 dialogue messages (149.86 MB original corpus, 108.38 MB test evaluation suite across 756 generated payloads).

Overall Reduction Summary (v0.4.7)

  • Raw Input Processed: 108.38 MB
  • Compressed Output: 27.89 MB
  • Overall Space Saved: 74.26% (3.88x compression ratio)
  • Decompression Verification: 100% Roundtrip Match (0 errors)

Workload Zone Performance

Workload Zone Size Range Samples Avg Raw Size Avg Space Saved Avg Processing Time
Micro Payloads < 64 B 400 33.1 B 44.57% 0.41 ms
Medium Payloads 64 B - 512 B 300 697.4 B 57.58% 6.54 ms
Large Payloads > 512 B 55 1,013.7 KB 73.04% 1,475.22 ms
Massive Streams > 50 MB 1 57.67 MB 75.51% 40,327.11 ms

Engine Selection Breakdown

Engine Header Flag Wins Distribution Primary Workload Scope
TikMax b'T' 509 67.3% Micro text and ultra-short dialogue (< 64 B)
MoeZip b'M' 190 25.1% Medium text, short paragraphs, and dialogue turns (64 B - 512 B)
Bzip2 b'B' 32 4.2% Medium-large block sorting fallback
LZMA2 Extreme b'X' 21 2.8% Large concatenated blocks and megabyte streams (> 512 B to > 50 MB)
Raw Passthrough b'R' 4 0.5% Micro strings where overhead exceeds uncompressed byte count

License

MIT

Metadata

Release files for hyzip 0.4.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for hyzip 0.4.7
File Size Uploaded Provenance Actions
hyzip-0.4.7.tar.gz 8.8 kB Without provenance Details for hyzip-0.4.7.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for hyzip 0.4.7
File Interpreter ABI Platform Actions
hyzip-0.4.7-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details for hyzip-0.4.7-cp311-cp311-win_amd64.whl

Total release size: 82.5 kB

Release files / hyzip-0.4.7.tar.gz

Download URL hyzip-0.4.7.tar.gz
Size 8.8 kB
Tags Source
SHA-256 checksum
How to use checksums
c30117729fe7cd7f93d723bf2a771d70b7c4bd9ecc3f42795afc72dc41ce02e3
BLAKE2b-256 checksum
How to use checksums
1d2270dd598bf4a487b9341e914434206f517b9ae0576aa9b746df1b6e088e6e
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.7-cp311-cp311-win_amd64.whl

Download URL hyzip-0.4.7-cp311-cp311-win_amd64.whl
Size 73.6 kB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
751f6e0203501beeaad84f14d60c1e49cd705d0fca7645b50abfae0645b21be0
BLAKE2b-256 checksum
How to use checksums
3d1f831abddd13d0539d31ba3dc7a610b7fa0bee8f3b36111e525cb8018fd8ab
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.7

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page