Registry / serialization / zlib-ng

zlib-ng

JSON →
library1.0.0pypypi✓ verified 85d ago

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-ng
INSTALL
IMPORT
SIG · ZLIB-NG
Z
zlib-ng
serializationpythonv1.0.0
Install
1.6s avg
Import
8ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.0.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.003s · 18.1MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 1.6s · import 0.000s · 19MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

zlib_ng
from zlib_ng import zlib_ng
gzip_ng
from zlib_ng import gzip_ng
gzip_ng_threaded
from zlib_ng import gzip_ng_threaded
For multi-threaded streaming compression/decompression.
zlib
import zlib_ng as zlib
import zlib_ng
For drop-in replacement of the standard library's 'zlib' module, it's common to import 'zlib_ng' and alias it as 'zlib'.
gzip
import gzip_ng as gzip
import gzip_ng
For drop-in replacement of the standard library's 'gzip' module, it's common to import 'gzip_ng' and alias it as 'gzip'.

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!")
Debug
Known issues
gotchaCompression level 1 in `zlib_ng` offers worse compression rates compared to the standard `zlib` module. For most other compression levels (0 or 2-9), `zlib_ng` provides better compression.
fix
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.
affects: All versions
gotchaThe `gzip_ng.open()` function returns a `gzip_ng.GzipNGFile` object, not `gzip.GzipFile` as in the standard library. While `gzip_ng.GzipFile` exists as an alias for compatibility, be aware of the underlying type difference if performing type checks.
fix
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.
affects: All versions
gotchaPre-built wheels for `zlib-ng` are available for common platforms (Linux, Windows, MacOS). For less common or specific system architectures, installation might require building the C `zlib-ng` library from source, which necessitates appropriate build tools (like a C compiler) on the target system.
fix
Ensure that your deployment environment has the necessary build tools if pre-built wheels are not available for your specific platform/architecture.
affects: All versions
gotchaThe `gzip_ng_threaded.open()` function is designed exclusively for streaming operations. Seeking within files opened with `gzip_ng_threaded.open()` is not supported.
fix
For files requiring random access or seeking, use `gzip_ng.open()` instead of `gzip_ng_threaded.open()`.
affects: All versions
breakingVersion 1.0.0 of `zlib-ng` has dropped official support for Python 3.8 and 3.9.
fix
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.
affects: 1.0.0 and later
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'zlib_ng'
The 'zlib-ng' package, which provides the 'zlib_ng' module, is not installed in the current Python environment.
fix
Install the package using pip: `pip install zlib-ng`
Failed building wheel for zlib-ng
The compilation of the underlying C extension fails due to missing C compilers or necessary build tools (e.g., build-essential on Linux, Visual C++ build tools on Windows, or Xcode Command Line Tools on macOS).
fix
Install the required C/C++ compiler and development tools for your operating system. For example, on Debian/Ubuntu: `sudo apt-get install build-essential`
ImportError: cannot import name 'zlib_ng' from 'zlib'
The user is attempting to import the 'zlib_ng' module from Python's standard 'zlib' module, but 'zlib_ng' is a separate top-level module provided by the 'zlib-ng' package.
fix
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`.
Upgrade
Version history
1.0.0latest on PyPI · released Sep 10, 2025
Audit
Dependencies

No dependency data recorded yet.

Agent activity
48 hits · last 30 days
node
40
OpenAI (training)
1
Resources
zlib-ng — pip install zlib-ng · libregistry