Registry / data / numcodecs

numcodecs

JSON →
library0.16.5pypypi✓ verified 24d ago

Numcodecs is a Python package providing a diverse set of buffer compression and transformation codecs. It is widely used in data storage and communication applications, especially as a dependency for the Zarr N-dimensional array store. The current version is 0.16.5, with frequent patch and minor releases, typically on a monthly or bi-monthly cadence.

pip install numcodecs
INSTALL
IMPORT
SIG · NUMCODECS
N
numcodecs
datapythonv0.16.5
Install
4.0s avg
Import
371ms
Disk
121MB
Pass rate
5/ 10
Env Coverage5 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.13.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
build_error
glibc
py 3.103.910 runs
installs and imports cleanly · install 4.0s · import 0.371s · 119MB
121MB installed
● package 121MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

numcodecs
import numcodecs
Blosc
from numcodecs.blosc import Blosc
from numcodecs import Blosc
Specific codecs like Blosc, Zstd, GZip reside in their own submodules, not directly under the top-level numcodecs namespace.
Zstd
from numcodecs.zstd import Zstd
from numcodecs import Zstd
Specific codecs like Blosc, Zstd, GZip reside in their own submodules, not directly under the top-level numcodecs namespace.
GZip
from numcodecs.gzip import GZip
from numcodecs import GZip
Specific codecs like Blosc, Zstd, GZip reside in their own submodules, not directly under the top-level numcodecs namespace.

This quickstart demonstrates how to instantiate a codec (Blosc or GZip as a fallback), encode a NumPy array into bytes, and then decode it back. It also shows how to globally register and retrieve codecs, which is often used in frameworks like Zarr.

import numpy as np import numcodecs # Define some data to encode data = np.arange(10000, dtype='i4').reshape(100, 100) # Choose a codec. Blosc is common, but requires 'pip install "numcodecs[blosc]"'. # If Blosc isn't installed, GZip is a good fallback. try: codec = numcodecs.blosc.Blosc(cname='lz4', clevel=5, shuffle=numcodecs.blosc.SHUFFLE) print("Using Blosc codec.") except ImportError: print("Blosc not installed. Falling back to GZip codec.") codec = numcodecs.gzip.GZip(level=5) # Encode the data encoded_data = codec.encode(data.tobytes()) print(f"Original data shape: {data.shape}, dtype: {data.dtype}") print(f"Original bytes: {data.nbytes}") print(f"Encoded bytes: {len(encoded_data)}") # Decode the data decoded_bytes = codec.decode(encoded_data) # Reconstruct the numpy array decoded_data = np.frombuffer(decoded_bytes, dtype=data.dtype).reshape(data.shape) # Verify that the decoded data matches the original assert np.array_equal(data, decoded_data) print("Data successfully encoded and decoded!") # You can also register codecs globally for retrieval by ID numcodecs.register_codec(codec) retrieved_codec = numcodecs.get_codec({'id': codec.codec_id, **codec.get_config()}) assert retrieved_codec.codec_id == codec.codec_id print(f"Codec '{retrieved_codec.codec_id}' registered and retrieved successfully.")
Debug
Known issues
breakingNumcodecs versions 0.16.x and higher require Python 3.11 or newer. Installations on older Python versions will fail.
fix
Upgrade your Python environment to 3.11 or later, or pin numcodecs to an older compatible version (e.g., `<0.16.0`).
affects: >=0.16.0
gotchaMany high-performance codecs (e.g., Blosc, Zstd, LZ4, Snappy) are implemented as optional dependencies. If you try to use them without their respective packages installed, an `ImportError` or `ValueError` will occur.
fix
Install numcodecs with the required extras, for example, `pip install "numcodecs[blosc]"` for Blosc, or `pip install "numcodecs[all]"` to include all optional codecs.
affects: All
breakingCompatibility with Zarr v3 has evolved across recent numcodecs versions. Changes in Zarr3 configuration serialization (v0.15.1) and handling for Zarr 3.1.0 (v0.16.2) may affect users relying on specific Zarr3 features or metadata structures.
fix
Ensure you are using a numcodecs version compatible with your Zarr-Python version. Refer to the Zarr-Python documentation and numcodecs changelog for specific compatibility matrices. Update numcodecs to the latest stable version for the best Zarr v3 compatibility.
affects: >=0.15.0
gotchaPrior to v0.16.3, there was a known issue with Zstd decompression leading to negative size errors on 32-bit platforms.
fix
Upgrade numcodecs to version 0.16.3 or newer if you are using Zstd compression on a 32-bit system.
affects: <0.16.3
Errors
Common errors & fixes
ERROR: Failed building wheel for numcodecs
This error typically occurs during `pip install numcodecs` when the C extensions (e.g., for Blosc) fail to compile due to missing build tools (like a C compiler on Windows or specific `glibc` versions on Linux) or environment issues.
fix
Ensure you have the necessary build tools installed for your operating system (e.g., 'Build Tools for Visual Studio' on Windows, or `gcc` on Linux). Alternatively, install `numcodecs` via `conda`, which provides pre-compiled binaries: `conda install -c conda-forge numcodecs`.
ImportError: cannot import name 'blosc'
This error indicates that the Blosc C extension for `numcodecs` failed to compile or load correctly during installation, often when using `pip` without the necessary build environment, resulting in the `blosc` module not being available.
fix
Install `numcodecs` using `conda` (`conda install -c conda-forge numcodecs`) to get pre-compiled binaries, or ensure your `pip` installation environment has a working C compiler (e.g., by installing `build-essential` on Debian/Ubuntu or Xcode Command Line Tools on macOS) and try `pip install numcodecs -v --no-cache-dir --no-binary numcodecs numcodecs` to force a rebuild with verbose output.
ImportError: cannot import name 'cbuffer_sizes' from 'numcodecs.blosc'
This error occurs when an older version of Zarr (specifically `zarr<3`) attempts to import functions like `cbuffer_sizes` or `cbuffer_metainfo` from `numcodecs.blosc`, but these functions have been deprecated and removed in `numcodecs` versions 0.16.0 and later.
fix
Upgrade your Zarr library to version 3 or newer (`pip install --upgrade zarr`) which is compatible with recent `numcodecs` versions, or downgrade `numcodecs` to a version prior to 0.16.0 (e.g., `pip install numcodecs<0.16.0`) to maintain compatibility with `zarr<3`.
RuntimeError: error during blosc decompression: -1
This runtime error often points to an issue during the decompression of Blosc-compressed data. It can be caused by incompatibility between the `glibc` version where `numcodecs` (specifically its Blosc extension) was built and the `glibc` version on the system where the code is being run (common in HPC environments) or data corruption.
fix
Try installing `numcodecs` using `conda` from `conda-forge` (`conda install -c conda-forge numcodecs`) on the target machine, as `conda-forge` packages are often built with broader `glibc` compatibility. If the issue persists, verify data integrity or check for environment inconsistencies between where the data was created and where it's being accessed.
numcodecs.errors.UnknownCodecError: codec not available: 'zfpy'
This error means you are trying to use an optional codec (like ZFPY, PCodec, or CRC32C) whose underlying Python dependency is not installed. `numcodecs` will not define the codec class if its required external library is missing.
fix
Install the missing dependency for the specific codec you wish to use. For 'zfpy', install `zfpy` (`pip install zfpy` or `conda install -c conda-forge zfpy`). Similarly, for 'pcodec' you would install `pcodec` (`pip install pcodec`).
Upgrade
Version history
0.16.5latest on PyPI · released Nov 21, 2025
Audit
Dependencies
numpyrequiredMost codecs operate on NumPy arrays; while not a strict install_requires, it's a de-facto dependency for practical use.
zarroptionalOften used in conjunction with Zarr for array compression and serialization.
bloscoptionalProvides the highly optimized Blosc compression codec.
python-lz4optionalProvides the fast LZ4 compression codec.
python-snappyoptionalProvides the Snappy compression codec.
python-zstdoptionalProvides the Zstd compression codec.
Agent activity
17 hits · last 30 days
node
14
Resources
numcodecs — pip install numcodecs · libregistry