zlib-ng Python Bindings

1.0.0 · active · verified Wed Apr 15

zlib-ng is a Python library that provides high-performance bindings for the zlib-ng compression library. It serves as a drop-in replacement for Python's standard `zlib` and `gzip` modules, offering significantly faster compression and decompression by utilizing optimized algorithms and CPU intrinsics. The library offers `zlib_ng`, `gzip_ng`, and `gzip_ng_threaded` modules. The current version, 1.0.0, emphasizes stability and performance. It generally aligns its development with the upstream zlib-ng C library, with updates primarily focusing on Python compatibility and performance enhancements.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates basic compression and decompression using the `zlib_ng` module, which mimics the standard `zlib` module's API. It compresses a byte string and then decompresses it, verifying that the original data is recovered.

from zlib_ng import zlib_ng

original_data = b'This is some data that will be compressed using zlib-ng.'

# Compress data
compressed_data = zlib_ng.compress(original_data)
print(f"Original size: {len(original_data)}")
print(f"Compressed size: {len(compressed_data)}")

# Decompress data
decompressed_data = zlib_ng.decompress(compressed_data)
print(f"Decompressed size: {len(decompressed_data)}")

assert original_data == decompressed_data
print("Data compressed and decompressed successfully!")

view raw JSON →