MedBlosc2
A standardized Blosc2 image reader and writer for medical images. The MedBlosc2 file format (".mb2nd") is a Blosc2-compressed container with standardized metadata support for N-dimensional medical images. Plain ".b2nd" files are also supported, but they do not participate in the MedBlosc2 metadata standard.
Installation
You can install med-blosc2 via pip:
pip install med-blosc2
API
See API.md for the full MedBlosc2 api, including argument descriptions and types.
Metadata schema
See SCHEMA.md for the full MedBlosc2 metadata schema, including field descriptions and types.
Usage
Below are common usage patterns for loading, saving, and working with metadata.
Default usage
import numpy as np
from med_blosc2 import MedBlosc2, Meta
array = np.random.random((128, 256, 256)).astype(np.float32)
image = MedBlosc2(array)
image.save("sample.mb2nd")
Memory-mapped loading
from med_blosc2 import MedBlosc2
image = MedBlosc2("sample.mb2nd", mmap=True)
# image.array is a blosc2.ndarray.NDArray when mmap=True, otherwise a np.ndarray
Loading and saving
from med_blosc2 import MedBlosc2
image = MedBlosc2("sample.mb2nd")
image.save("copy.mb2nd")
Metadata inspection and manipulation
import numpy as np
from med_blosc2 import MedBlosc2
array = np.random.random((64, 128, 128)).astype(np.float32)
image = MedBlosc2(
array,
spacing=(1.0, 1.0, 1.5),
origin=(10.0, 10.0, 30.0),
direction=[[1, 0, 0], [0, 1, 0], [0, 0, 1]],
meta=Meta(image={"patient_id": "123", "modality": "CT"}, is_seg=False),
)
print(image.spacing) # [1.0, 1.0, 1.5]
print(image.origin) # [10.0, 10.0, 30.0]
print(image.meta.image) # {"patient_id": "123", "modality": "CT"}
image.spacing[1] = 5.3
image.meta.image["study_id"] = "study-001"
image.save("with-metadata.mb2nd")
Copy metadata with overrides
import numpy as np
from med_blosc2 import MedBlosc2
base = MedBlosc2("sample.mb2nd")
array = np.random.random(base.shape).astype(np.float32)
image = MedBlosc2(
array,
spacing=(0.8, 0.8, 1.0),
copy=base, # Copies all non-explicitly set arguments from base
)
image.save("copied-metadata.mb2nd")
Patch size variants
Default patch size (192):
from med_blosc2 import MedBlosc2
image = MedBlosc2("sample.mb2nd")
image.save("default-patch.mb2nd")
Custom isotropic patch size (512):
from med_blosc2 import MedBlosc2
image = MedBlosc2("sample.mb2nd")
image.save("patch-512.mb2nd", patch_size=512)
Custom non-isotropic patch size:
from med_blosc2 import MedBlosc2
image = MedBlosc2("sample.mb2nd")
image.save("patch-non-iso.mb2nd", patch_size=(128, 192, 256))
Manual chunk/block size:
from med_blosc2 import MedBlosc2
image = MedBlosc2("sample.mb2nd")
image.save("manual-chunk-block.mb2nd", patch_size=None,
chunk_size=(1, 128, 128), block_size=(1, 32, 32))
Contributing
Contributions are welcome! Please open a pull request with clear changes and add tests when appropriate.
Issues
Found a bug or have a request? Open an issue at https://github.com/Karol-G/med-blosc2/issues.
License
Distributed under the MIT license. See LICENSE for details.
Metadata
Release files for med-blosc2 0.0.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| med_blosc2-0.0.5.tar.gz | 18.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| med_blosc2-0.0.5-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 32.0 kB
Release files / med_blosc2-0.0.5.tar.gz
| Download URL | med_blosc2-0.0.5.tar.gz |
|---|---|
| Size | 18.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f8d6bb3f72392ad75911dd0daa6dee00f79d10f8db79182dd18b0f1829bfcd48
|
|
BLAKE2b-256 checksum How to use checksums |
da462c7441e16e7414f17ca9648da2c2c8312cfb3d2dc82dc1d8ac5dc2210925
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jan 15, 2026.
Transparency logRelease files / med_blosc2-0.0.5-py3-none-any.whl
| Download URL | med_blosc2-0.0.5-py3-none-any.whl |
|---|---|
| Size | 13.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3966c4e92eddcd4b018cb522c50940a0869bc5343fa2522a2d764d34cab0fc0a
|
|
BLAKE2b-256 checksum How to use checksums |
f26151b70e3599e1fa8f11fb2e6d1bc896a0a9f7bf62801f4511f42318181407
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jan 15, 2026.
Transparency log