cramjam

Thin Python bindings to de/compression algorithms in Rust

MIT 49 个版本 Python >=3.8
Miles Granger <miles59923@gmail.com> <Miles Granger <miles59923@gmail.com>>
安装
pip install cramjam
poetry add cramjam
pipenv install cramjam
conda install cramjam
描述

cramjam

Code Style CI PyPI Anaconda-Server Badge Downloads NPM Version

API Documentation

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

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'

TypeScript:


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);

版本列表
2.12.0rc1 2026-04-13
2.11.0 2025-07-27
2.11.0rc4 2025-07-27
2.11.0rc3 2025-06-01
2.11.0rc2 2025-04-25
2.11.0rc1 2025-04-24
2.10.0 2025-04-12
2.10.0rc1 2025-03-01
2.9.1 2024-12-12
2.9.0 2024-10-16
2.9.0rc1 2024-10-05
2.8.4 2024-09-24
2.8.3 2024-03-21
2.8.2 2024-03-02
2.8.1 2024-01-26
2.8.1.dev1 2024-01-22
2.8.0 2024-01-15
2.8.4rc4 2024-09-24
2.8.4rc3 2024-09-05
2.8.4rc2 2024-05-03
2.8.4rc1 2024-04-28
2.8.3rc1 2024-03-09
2.7.0 2023-07-29
2.7.0rc3 2023-05-07
2.7.0rc2 2023-04-29
2.7.0rc1 2023-04-26
2.6.2 2022-11-09
2.6.1 2022-10-29
2.6.0 2022-10-28
2.5.0 2021-11-07
2.4.0 2021-09-10
2.4.0_rc2 2021-09-08
2.4.0_rc1 2021-09-06
2.3.2 2021-05-31
2.3.1 2021-05-16
2.3.0 2021-04-14
2.2.0 2021-03-30
2.1.0 2021-03-18
2.0.2 2021-02-22
2.0.1 2021-02-19
2.0.0 2021-02-18
2.0.0_rc2 2021-02-18
2.0.0-rc1 2021-02-15
1.3.2 2021-01-10
1.3.0 2020-07-18
1.2.0 2020-06-25
1.1.0 2020-05-03
1.0.1 2020-03-08
1.0.0 2020-03-08