Blosc Data Compressor

1.11.4 · active · verified Wed Apr 15

Blosc is a high-performance Python wrapper for the C-Blosc meta-compressor library. It's designed for compressing and decompressing numerical datasets, especially those used with NumPy, offering fast, multi-threaded operations. The current version is 1.11.4, and it maintains a regular release cadence, primarily updating its vendored C-Blosc library and supporting newer Python versions.

Warnings

Install

Imports

Quickstart

Compress and decompress a bytes object. For optimal compression of structured data (e.g., NumPy arrays), ensure `typesize` is set to the item size (e.g., `array.itemsize`).

import blosc

data_bytes = b"This is a test string that will be compressed by blosc." * 10

# Compress data
# For byte strings, typesize=1 is appropriate.
# For NumPy arrays, use typesize=array.itemsize
compressed_data = blosc.compress(data_bytes, typesize=1)
print(f"Original size: {len(data_bytes)} bytes")
print(f"Compressed size: {len(compressed_data)} bytes")

# Decompress data
decompressed_data = blosc.decompress(compressed_data)

# Verify
assert data_bytes == decompressed_data
print("Decompression successful!")

view raw JSON →