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:
>>>
>>> =
>>>
b
Where the API is cramjam.<compression-variant>.compress/decompress
and accepts
both bytes
and bytearray
objects.
de/compress_into
Additionally, all variants except for lz4, support decompress_into
and compress_into
.
If you have a numpy array preallocated, that can be used as the output location for de/compression.
Ex.
>>>
>>>
>>> # some data that we know the size of when decompressed
>>> =
>>> # returns number of bytes decoded
<<: >>
This is very fast, as it avoids any buffer allocations on the rust side.
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.
For snappy
with bytearray
s, it's only a mild improvement
as we currently are able to estimate the buffer size and can
resize the resulting bytearray
to the correct size.