pyrus-cramjam
Install
pip install --upgrade cramjam # Requires no Python or system dependencies!
Extremely thin Python bindings to de/compression algorithms in Rust. Allows for using algorithms such as Snappy, without any system dependencies.
This is handy when being used in environments like AWS Lambda, where installing
packages like python-snappy becomes difficult because of system level dependencies.
Benchmarks
Some basic benchmarks are available in the benchmarks directory
Available algorithms:
- Snappy
- Brotli
- Lz4
- Gzip
- Deflate
- ZSTD
All available for use as:
>>>
>>>
>>> =
>>> =
>>>
# an object which implements the buffer protocol
>>>
b
>>>
Where the API is cramjam.<compression-variant>.compress/decompress and accepts
bytes/bytearray/numpy.array/cramjam.File/cramjam.Buffer objects.
de/compress_into
Additionally, all variants support decompress_into and compress_into.
Ex.
>>>
>>>
>>>
>>> =
>>>
>>>
>>> =
>>>
33 # 33 bytes written to compressed buffer
>>>
>>> # Where is the buffer position?
33 # goodie!
>>>
>>> # Go back to the start of the buffer so we can prepare to decompress
>>> = b * # let's write to `bytes` as output
>>>
b
>>>
>>>
15 # 15 bytes written to decompressed
>>>
b
Special note!
If you know the length of the de/compress output, you
can provide output_len=<<some int>> to any de/compress
to get ~1.5-3x performance increase as this allows single
buffer allocation; doesn't really apply if you're using cramjam.Buffer
or cramjam.File objects.