LZ4 Tools

raw JSON →
1.3.1.2 verified Fri May 01 auth: no python maintenance

Python bindings and tools for LZ4 compression, providing LZ4Frame compression/decompression utilities. Current version 1.3.1.2, released 2019-10-30. Last uploaded 2020-10-20. Low release cadence, effectively in maintenance mode.

pip install lz4tools
error ImportError: cannot import name 'LZ4Frame' from 'lz4'
cause Installed the wrong package: 'lz4' instead of 'lz4tools'. Or tried to import from 'lz4' package.
fix
Install lz4tools: pip install lz4tools. Then import from lz4tools: from lz4tools import LZ4Frame.
error TypeError: a bytes-like object is required, not 'str'
cause Passing a string to compress/decompress functions which expect bytes.
fix
Encode your string: compress(data.encode('utf-8')).
error ModuleNotFoundError: No module named 'lz4tools'
cause Package not installed or installed in different environment.
fix
Run: pip install lz4tools. Or if using a virtualenv, ensure it is activated.
breaking The package lz4tools is NOT the same as lz4 (python-lz4). Importing from lz4.frame will use a different library with incompatible format.
fix Use 'from lz4tools import LZ4Frame' instead of 'from lz4.frame import LZ4Frame'.
deprecated Library has not been updated since 2019. There is no active development. Consider using 'lz4' (python-lz4) for better performance and maintenance.
fix For new projects, prefer 'pip install lz4' and use 'from lz4.frame import LZ4Frame'.
gotcha The 'compress' and 'decompress' functions work only with bytes, not strings. Passing a str will raise TypeError.
fix Encode strings to bytes before compression: data.encode('utf-8').

Basic compression and decompression using package-level functions and the LZ4Frame class. Ensure you have the data as bytes.

from lz4tools import compress, decompress, LZ4Frame

# Compress bytes
data = b"Hello, LZ4!"
compressed = compress(data)
print(f"Compressed: {compressed}")

# Decompress
decompressed = decompress(compressed)
print(f"Decompressed: {decompressed}")

# Using LZ4Frame context
frame = LZ4Frame()
packed = frame.compress(data)
unpacked = frame.decompress(packed)
print(f"Frame roundtrip: {unpacked}")