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.
pip install bloscVerified import paths — ran on the pinned version, not inferred.
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`).
Upgrade your Python environment to 3.9 or higher. For projects requiring Python 3.7/3.8, pin `blosc<1.11.0` or `blosc<1.11.2` respectively.
Always pass `typesize=array.itemsize` (e.g., `blosc.compress(arr, typesize=arr.itemsize)`) when compressing NumPy arrays or similar structured data.
After `decompressed_bytes = blosc.decompress(compressed_data)`, convert using `np.frombuffer(decompressed_bytes, dtype=original_array_dtype)`.
Upgrade to `blosc` version 1.11.4 or newer to ensure full compatibility and avoid warnings with recent NumPy versions.
Ensure you have the necessary C/C++ compilers and build tools installed for your operating system (e.g., `sudo apt-get install build-essential` on Debian/Ubuntu, or Visual Studio Build Tools on Windows). Then, uninstall and reinstall `blosc` using `pip install --no-cache-dir --force-reinstall blosc`. Alternatively, use `conda install -c conda-forge python-blosc` to install pre-compiled binaries if using Anaconda/Miniconda.
First, verify the integrity of the compressed data. If the issue is intermittent, consider checking memory allocation and usage in your environment. Ensure that `blosc` and related libraries (like `numcodecs`, `zarr`) are updated to compatible versions, ideally by installing from `conda-forge` for consistent binaries. If using `blosc` directly, ensure the input `src` buffer for `decompress` is valid and the `dst` buffer (if provided) has sufficient capacity.
To enable Snappy support, you may need to rebuild `blosc` from source with explicit Snappy inclusion or use a pre-compiled version that includes it. For `pip` installations, ensure you have a C++ compiler. If building manually with `setuptools`, check environment variables like `INCLUDE_SNAPPY`. For `conda` users, `conda install -c conda-forge python-blosc` often provides builds with broader codec support. If working with `h5py` or `PyTables`, consider installing `hdf5plugin` from `conda-forge` as it may provide the necessary Blosc with Snappy.