hdf5plugin

6.0.0 · active · verified Tue Apr 14

hdf5plugin is a Python library that provides additional HDF5 compression filters for use with h5py, enabling reading and writing of compressed datasets with various algorithms like Blosc, Bitshuffle, LZ4, Zstd, and more. It is actively maintained with frequent releases, currently at version 6.0.0, and often updates its embedded compression libraries and introduces new filters.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to write and read a dataset compressed using one of the filters provided by hdf5plugin (LZ4 in this case). The `import hdf5plugin` statement is crucial as it registers the filters with h5py.

import numpy
import h5py
import hdf5plugin

# Create a dummy dataset
data_to_write = numpy.arange(100, dtype='i4')

# Write compressed data to an HDF5 file using an hdf5plugin filter (e.g., LZ4)
file_name = 'test_compressed.h5'
with h5py.File(file_name, 'w') as f:
    dset = f.create_dataset('data', data=data_to_write, compression=hdf5plugin.LZ4())
    print(f"Dataset 'data' written to {file_name} with LZ4 compression.")

# Read the compressed data back
with h5py.File(file_name, 'r') as f:
    read_data = f['data'][()]
    print(f"Data read successfully: {read_data}")
    assert numpy.array_equal(data_to_write, read_data)
print("Original and read data match.")

view raw JSON →