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.
pip install zlib-ngVerified import paths — ran on the pinned version, not inferred.
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.
Avoid using compression level 1 if optimal compression ratio is critical. Use other levels (e.g., default -1, or 2-9) for improved performance and usually better compression.
If performing type checks, check for `gzip_ng.GzipNGFile` or rely on duck-typing due to API compatibility. Using `import gzip_ng as gzip` helps maintain consistent code behavior.
Ensure that your deployment environment has the necessary build tools if pre-built wheels are not available for your specific platform/architecture.
For files requiring random access or seeking, use `gzip_ng.open()` instead of `gzip_ng_threaded.open()`.
Ensure your project uses Python 3.10 or newer to be compatible with `zlib-ng` version 1.0.0. The `requires_python` metadata is `>=3.9` on PyPI, but documentation clarifies 3.8/3.9 are no longer supported as of 1.0.0.
Install the package using pip: `pip install zlib-ng`
Install the required C/C++ compiler and development tools for your operating system. For example, on Debian/Ubuntu: `sudo apt-get install build-essential`
Import 'zlib_ng' directly: `import zlib_ng`. To use it as a drop-in replacement for the standard 'zlib', use `import zlib_ng as zlib`.
No dependency data recorded yet.