Thin Python bindings to de/compression algorithms in Rust
Project Links
Meta
Author: Miles Granger <miles59923@gmail.com>
Requires Python: >=3.8
Classifiers
cramjam
Install (Python)
pip install --upgrade cramjam # Requires no Python or system dependencies!
Install (JavaScript / TypeScript)
npm install cramjam
CLI
A CLI interface is available as cramjam-cli
libcramjam
A Rust crate and C friendly library available at libcramjam
Extremely thin and easy-to-install Python bindings to de/compression algorithms in Rust. Allows for using algorithms such as Snappy, without any system or other python dependencies.
Benchmarks
Some basic benchmarks are available in the benchmarks directory
Available algorithms:
- Snappy
cramjam.snappy
- Brotli
cramjam.brotli
- Bzip2
cramjam.bzip2
- Lz4
cramjam.lz4
- Gzip
cramjam.gzip
- Zlib
cramjam.zlib
- Deflate
cramjam.deflate
- ZSTD
cramjam.zstd
- XZ / LZMA
cramjam.xz
Experimental (Requires build from source enabling each feature):
- Blosc2
cramjam.experimental.blosc2
- ISA-L backend (only on 64-bit targets)
- igzip
cramjam.experimental.igzip
- ideflate
cramjam.experimental.ideflate
- izlib
cramjam.experimental.izlib
- igzip
All available for use as:
>>> import cramjam
>>> import numpy as np
>>> compressed = cramjam.snappy.compress(b"bytes here")
>>> decompressed = cramjam.snappy.decompress(compressed)
>>> decompressed
cramjam.Buffer(len=10) # an object which implements the buffer protocol
>>> bytes(decompressed)
b"bytes here"
>>> np.frombuffer(decompressed, dtype=np.uint8)
array([ 98, 121, 116, 101, 115, 32, 104, 101, 114, 101], dtype=uint8)
Where the API is cramjam.<compression-variant>.compress/decompress
and accepts
bytes
/bytearray
/numpy.array
/cramjam.File
/cramjam.Buffer
/ memoryview
objects.
de/compress_into
Additionally, all variants support decompress_into
and compress_into
.
Ex.
>>> import numpy as np
>>> from cramjam import snappy, Buffer
>>>
>>> data = np.frombuffer(b'some bytes here', dtype=np.uint8)
>>> data
array([115, 111, 109, 101, 32, 98, 121, 116, 101, 115, 32, 104, 101,
114, 101], dtype=uint8)
>>>
>>> compressed = Buffer()
>>> snappy.compress_into(data, compressed)
33 # 33 bytes written to compressed buffer
>>>
>>> compressed.tell() # Where is the buffer position?
33 # goodie!
>>>
>>> compressed.seek(0) # Go back to the start of the buffer so we can prepare to decompress
>>> decompressed = b'0' * len(data) # let's write to `bytes` as output
>>> decompressed
b'000000000000000'
>>>
>>> snappy.decompress_into(compressed, decompressed)
15 # 15 bytes written to decompressed
>>> decompressed
b'some bytes here'
import {Compress, Decompress} from 'cramjam';
const decoder = new TextDecoder();
const encoder = new TextEncoder();
const str = 'hello, world';
const encoded = encoder.encode(str);
const compressed = Compress.brotli(encoded);
const decompressed = Decompress.brotli(compressed);
const decoded = decoder.decode(decompressed);
Jul 27, 2025
2.11.0
Jul 27, 2025
2.11.0rc4
Jun 01, 2025
2.11.0rc3
Apr 25, 2025
2.11.0rc2
Apr 24, 2025
2.11.0rc1
Apr 12, 2025
2.10.0
Mar 01, 2025
2.10.0rc1
Dec 12, 2024
2.9.1
Oct 16, 2024
2.9.0
Oct 05, 2024
2.9.0rc1
Sep 24, 2024
2.8.4
Sep 24, 2024
2.8.4rc4
Sep 05, 2024
2.8.4rc3
May 03, 2024
2.8.4rc2
Apr 28, 2024
2.8.4rc1
Mar 21, 2024
2.8.3
Mar 09, 2024
2.8.3rc1
Mar 02, 2024
2.8.2
Jan 26, 2024
2.8.1
Jan 22, 2024
2.8.1.dev1
Jan 15, 2024
2.8.0
Jul 29, 2023
2.7.0
May 07, 2023
2.7.0rc3
Apr 29, 2023
2.7.0rc2
Apr 26, 2023
2.7.0rc1
Nov 09, 2022
2.6.2
Oct 29, 2022
2.6.1
Oct 28, 2022
2.6.0
Nov 07, 2021
2.5.0
Sep 10, 2021
2.4.0
Sep 08, 2021
2.4.0rc2
Sep 06, 2021
2.4.0rc1
May 31, 2021
2.3.2
May 16, 2021
2.3.1
Apr 14, 2021
2.3.0
Mar 30, 2021
2.2.0
Mar 18, 2021
2.1.0
Feb 22, 2021
2.0.2
Feb 19, 2021
2.0.1
Feb 18, 2021
2.0.0
Feb 18, 2021
2.0.0rc2
Feb 15, 2021
2.0.0rc1
Jan 10, 2021
1.3.2
Jul 18, 2020
1.3.0
Jun 25, 2020
1.2.0
May 03, 2020
1.1.0
Mar 08, 2020
1.0.1
Mar 08, 2020
1.0.0