Skip to main content

hyzip

An auto-routing hybrid text compression engine that dynamically combines MoeZip (context mixing), TikMax (BPE tokenization with LEB128 varint packing), and Bzip2 (Burrows-Wheeler block sorting).

It prevents header-driven data expansion on short text (<100 bytes) while retaining high-density macro block compression for larger archives.


Engine Roster

For every input string or byte payload, candidate backends are evaluated concurrently. The smallest output is returned prepended with a 1-byte header flag.

Header Flag Byte Code Engine Workload Scope
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 short inputs (1 B to 500 B).
b'B' 0x42 Bzip2 Burrows-Wheeler block sorting (Level 9). Evaluated when input size >= 256 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 for C/Rust backends:

pip install tiktoken moezip

If optional dependencies are missing, hyzip falls back to its embedded pure-Python implementations.


Usage

Basic API

import hyzip

# Compress text (auto-selects 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 bytes or JSON payload"

# Compress bytes or string
compressed = hyzip.compress(raw_data)

# Decompress and return raw bytes
decompressed_bytes = hyzip.decompress(compressed, return_bytes=True)

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 11,770 dialogue messages (1.73 MB total):

Algorithm 150-Byte Message 1.73 MB Batch Compression Ratio
Gzip (Level 6) Expands (+35%) 1.21 MB (71.5% saved) 3.5x
Bzip2 (Level 9) Expands (+100%) 0.37 MB (78.5% saved) 4.6x
hyzip Compresses (-35%) 0.37 MB (78.58% saved) 4.67x

License

MIT

Metadata

Release files for hyzip 0.2.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.2.7
File Size Uploaded Provenance Actions
hyzip-0.2.7.tar.gz 6.8 kB Without provenance Details for hyzip-0.2.7.tar.gz

Built distribution (wheel)

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

Total release size: 79.0 kB

Release files / hyzip-0.2.7.tar.gz

Download URL hyzip-0.2.7.tar.gz
Size 6.8 kB
Tags Source
SHA-256 checksum
How to use checksums
2fe1a2358b6bc37c73ee7a53b9a1523eab00040821fcb139c6b09833c50b80ea
BLAKE2b-256 checksum
How to use checksums
b2d25fdb02fb96f62c4e3ffc4894ac9aa73e6f7a1ffffcf3b1007b40a8c48986
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.2.7-cp311-cp311-win_amd64.whl

Download URL hyzip-0.2.7-cp311-cp311-win_amd64.whl
Size 72.1 kB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
96342f7c75842c2bc6a470fd90071ff5293ffda3eeba6e94da8e551ede9424f9
BLAKE2b-256 checksum
How to use checksums
f809f3b7bed6f3bb5c016e41cf641b737bbe2c94acf8a89cfc6110ffc01eeafc
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.2.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