The brotli
module that is in PyPI provides Python bindings to the fast C reference
implementation of RFC 7932, and is the preferred
one to use for most purposes. One limitation to its use is that it requires installation
of a platform-specific shared binary executable.
This library is written all in versions 2 and 3 compatible Python for the special case in
which it is not practical to package or require platform-specific binaries. It includes only
the decompression function, under the assumption that will be the most common use-case that
might have that restriction. It is hundreds of times slower than the reference brotli
.
This code began as a hand port of the decompression portion of the Javascript project that is itself a hand port of the C code of the reference implementation.
Copy the top level file brotlidecpy.py
and the directory brotlidecpy
to a directory
that will be in PYTHONPATH
at runtime.
The following code will take a byte-like object, e.g. a bytearray or byte-string, that contains brotli compressed data, and return one with the uncompressed data
from brotlidecpy import decompress
uncompressed_data = decompress(compressed_data)
With a copy of the entire test
directory, set PYTHONPATH to the directory containing
brotlidecpy.py
(optional if it is the current directory), which may or may not be the same
directory that contains test
, and run the command (suitably modified for the current
directory you are using)
python -m unittest discover test