LZ4 Bindings for Python providing high-performance lossless data compression with frame and block format support
npx @tessl/cli install tessl/pypi-lz4@4.4.0LZ4 Bindings for Python providing high-performance lossless data compression with both frame format and block format specifications. This library delivers a drop-in alternative to Python's standard library compression modules (zlib, gzip, bzip2, LZMA) with a compatible API that includes context managers and file handler support.
pip install lz4import lz4For frame format compression (recommended):
import lz4.frameFor block format compression (low-level):
import lz4.blockFor experimental stream format:
import lz4.streamimport lz4.frame
# Simple compression and decompression
data = b"Hello, World!" * 1000
compressed = lz4.frame.compress(data)
decompressed = lz4.frame.decompress(compressed)
# File handling with context manager
with lz4.frame.open('data.lz4', 'wb') as f:
f.write(b"Large amounts of data...")
with lz4.frame.open('data.lz4', 'rb') as f:
content = f.read()The lz4 package provides three compression approaches:
All operations are thread-safe with GIL-releasing implementations optimized for performance. The library follows Python's standard compression module patterns for compatibility.
Access to package and library version information.
lz4.__version__: str
lz4.VERSION: str
def lz4.library_version_number() -> int: ...
def lz4.library_version_string() -> str: ...Production-ready compression using the LZ4 frame format with full interoperability, metadata support, and extensive configuration options. This is the recommended interface for most use cases.
def lz4.frame.compress(data, **kwargs) -> bytes: ...
def lz4.frame.decompress(data, **kwargs) -> bytes: ...
def lz4.frame.open(filename, mode, **kwargs) -> LZ4FrameFile: ...
class lz4.frame.LZ4FrameCompressor: ...
class lz4.frame.LZ4FrameDecompressor: ...
class lz4.frame.LZ4FrameFile: ...Low-level block compression without container format overhead. Provides direct access to LZ4 block compression with support for dictionaries and flexible compression modes.
def lz4.block.compress(data, **kwargs) -> bytes: ...
def lz4.block.decompress(data, **kwargs) -> bytes: ...
class lz4.block.LZ4BlockError(Exception): ...Experimental streaming compression interface with double-buffer strategy. Warning: This module is unmaintained and not included in distributed wheels.
class lz4.stream.LZ4StreamCompressor: ...
class lz4.stream.LZ4StreamDecompressor: ...
class lz4.stream.LZ4StreamError(Exception): ...