Faster zlib and gzip compatible compression and decompression by providing Python bindings for the zlib-ng library.
This package provides Python bindings for the zlib-ng library.
python-zlib-ng
provides the bindings by offering three modules:
zlib_ng
: A drop-in replacement for the zlib module that uses zlib-ng to accelerate its performance.gzip_ng
: A drop-in replacement for the gzip module that useszlib_ng
instead ofzlib
to perform its compression and checksum tasks, which improves performance.gzip_ng_threaded
offers anopen
function which returns buffered read or write streams that can be used to read and write large files while escaping the GIL using one or multiple threads. This functionality only works for streaming, seeking is not supported.
zlib_ng
and gzip_ng
are almost fully compatible with zlib
and
gzip
from the Python standard library. There are some minor differences
see: differences-with-zlib-and-gzip-modules.
The python-zlib-ng modules can be imported as follows
from zlib_ng import zlib_ng
from zlib_ng import gzip_ng
from zlib_ng import gzip_ng_threaded
zlib_ng
and gzip_ng
are meant to be used as drop in replacements so
their api and functions are the same as the stdlib's modules.
A full API documentation can be found on our readthedocs page.
python -m zlib_ng.gzip_ng
implements a fully featured gzip-like command line
application (just like python -m gzip
, but better). Full usage documentation can be
found on our readthedocs page.
- with pip:
pip install zlib-ng
- with conda:
conda install python-zlib-ng
Installation is supported on Linux, Windows and MacOS. For more advanced installation options check the documentation.
zlib-ng supports numerous platforms but not all of these have pre-built wheels available. To prevent your users from running into issues when installing your project please list a python-zlib-ng dependency as follows.
setup.cfg
:
install_requires = zlib-ng; platform.machine == "x86_64" or platform.machine == "AMD64"
setup.py
:
extras_require={ ":platform.machine == 'x86_64' or platform.machine == 'AMD64'": ['zlib-ng'] },
- Compression level 1 zlib_ng has a worse compression rate than that in zlib. For other compression levels zlib_ng compresses better.
gzip_ng.open
returns a classGzipNGFile
instead ofGzipFile
. Since there are differences between the compressed ratios between levels, a difference in naming was chosen to reflect this.gzip_ng.GzipFile
does exist as an alias ofgzip_ng.GzipNGFile
for compatibility reasons.
Please make a PR or issue if you feel anything can be improved. Bug reports are also very welcome. Please report them on the github issue tracker.
This project builds upon the software and experience of many. Many thanks to:
- The zlib-ng contributors for making the zlib-ng library.
- The CPython contributors.
Python-zlib-ng mimicks
zlibmodule.c
andgzip.py
from the standard library to make it easier for python users to adopt it. - The github actions team for creating the actions CI service that enables building and testing on all three major operating systems.