Skip to main content

Read Carl Zeiss image files (CZI)

Czifile is a Python library for reading image data and metadata from Carl Zeiss Image (CZI) files, the native file format of ZEN by Carl Zeiss Microscopy GmbH.

Czifile is a pure-Python library under the BSD-3-Clause license. It provides single-call array access to scenes and spatial ROIs, xarray DataArray output with physical axis coordinates, multi-scene merging, per-dimension selection by integer, slice, or sequence, chunk-based iteration, and pyramid-level access. It handles Fast Airyscan upsampling and PALM downsampling with optional stored-resolution output, and assembles FCS and line-scan files from T-chunked subblocks. It also supports Zstd, Chunked, JPEG, and JPEG XR compression, pixel type promotion across channels, and direct access to all ZISRAW segments and file-level attachments.

Author:

Christoph Gohlke

License:

BSD-3-Clause

Version:

2026.11.26

DOI:

10.5281/zenodo.14948581

Quickstart

Install the czifile package and all dependencies from the Python Package Index:

python -m pip install -U czifile[all]

See Examples and Documentation for using the programming interface.

Source code, examples, and support are available on GitHub.

Requirements

This revision was tested with the following requirements and dependencies (other versions may work):

Revisions

2026.11.26

  • Add pyramid levels to images of merged scenes.

  • Find pyramid levels on first access.

  • Read SYSTEMRAW subblocks only if data size matches stored size.

2026.11.12

  • Fix reading uncompressed subblocks with bytes after pixels.

  • Fix decoding float JPEG XR with WIC (use JPEG XR codec).

  • Make WIC decoder opt-in via CZIFILE_JPEGXR_DECODER environment variable.

  • Ignore subblocks in other files of multi-file CZI.

  • Fix attachment names and types with bytes after NUL terminator.

  • Raise CziFileError if decoded subblock exceeds stored size or dtype.

2026.11.8

  • Add CziSubBlockSegmentData.datetime property.

  • Fix overflow converting BGR48 and BGR96FLOAT to gray pixel types.

  • Fix BGR channel order of raw data stored with compression field set.

  • Return copy of cached subblock data if copy is true.

  • Read CZI header at start of open file objects.

  • Ignore invalid components in lookup tables.

  • Validate segment sizes.

  • Replace invalid UTF-8 in attachment names.

2026.10.14

  • Precompute more CziDirectoryEntryDV attributes.

  • Sanitize attachment file names to prevent path traversal.

  • Fix infinite loops on negative segment and attachment chunk sizes.

  • Fix chained CziImage views discarding ROI.

  • Do not close caller-owned file handles on failed CziFile construction.

  • Add CziImage.subblock_sizes property.

  • Size chunks decode cache by predominant subblock size.

  • Bound number of pending futures in CziImage.asarray.

2026.8.16

  • …

Refer to the CHANGES file for older revisions.

Notes

The API is not stable yet and might change between revisions.

Carl Zeiss AG is a manufacturer of microscopes and scientific instruments. CZI is a proprietary file format written by Zeiss acquisition software such as ZEN to store microscopy images and metadata.

CZI files are based on the ZISRAW (Zeiss Image Segment Raw) container specification, which is confidential and does not permit writing CZI files:

ZISRAW (CZI) File Format Design Specification Release Version 1.2.2.
“CZI 07-2016/CZI-DOC ZEN 2.3/DS_ZISRAW-FileFormat.pdf”

Additional information can be found in the libCZI documentation.

The ZISRAW format organizes data into typed, length-prefixed segments: a file header, image subblocks, XML metadata, and attachments. Each image subblock carries pixels for one tile or Z-plane across up to ten logical dimensions (X, Y, Z, channel, time, scene, phase, illumination, rotation, and mosaic index). Pixel data may be stored uncompressed or compressed with JPEG, JPEG XR, or Zstd.

Only a subset of the 2016 specification is implemented. Specifically, multi-file images and topography images are not supported. Some features are untested due to lack of sample files.

Czifile relies on the imagecodecs package for decoding LZW, Zstd, CHUNKED, JPEG, and JPEG XR compressed images.

Other libraries for reading CZI files (all GPL or LGPL licensed): libczi, pylibCZIrw, bioio-czi, aicspylibczi, bio-formats, libCZI (deprecated), and pylibczi (deprecated).

Examples

Import functions and classes used in the examples:

>>> from czifile import (
...     CziCompressionType,
...     CziFile,
...     CziImage,
...     CziSegment,
...     CziSegmentId,
...     CziSubBlockDirectorySegmentData,
...     CziSubBlockSegmentData,
...     imread,
... )

Read image data of the first scene from a CZI file as numpy array:

>>> arr = imread('Example.czi')
>>> assert arr.shape == (2, 2, 3, 486, 1178)
>>> assert arr.dtype == 'uint16'

Access scenes, shape, and metadata:

>>> with CziFile('Example.czi') as czi:
...     assert len(czi.scenes) == 3
...     image = czi.scenes[0]  # 0 is the absolute coordinate of first scene
...     assert image.shape == (2, 2, 3, 486, 1178)
...     assert image.dims == ('T', 'C', 'Z', 'Y', 'X')
...     assert image.dtype == 'uint16'
...     assert image.compression.name == 'ZSTDHDR'
...     assert list(image.channels) == ['DAPI', 'EGFP']
...     assert czi.metadata().startswith('<ImageDocument>')
...

Select dimensions and read as numpy array:

>>> with CziFile('Example.czi') as czi:
...     image = czi.scenes[0]
...     assert image.sizes == {'T': 2, 'C': 2, 'Z': 3, 'Y': 486, 'X': 1178}
...
...     # integer selection: fix T=0 and C=0; result has Z, but no T or C axis
...     volume = image(T=0, C=0).asarray()
...     assert volume.shape == (3, 486, 1178)
...
...     # None selection: keep all values but reorder dimensions
...     # dims order follows the kwargs order, then spatial dims
...     # T (unspecified) comes first, then C, Z (in kwargs order), then Y X
...     tczyx = image(C=None, Z=None).asarray()
...     assert tczyx.shape == (2, 2, 3, 486, 1178)
...
...     # read in C-outer, Z-inner, T-innermost order with parallelism
...     arr = image(C=None, Z=None, T=None).asarray(maxworkers=8)
...     assert arr.shape == (2, 3, 2, 486, 1178)  # 'C', 'Z', 'T', 'Y', 'X'
...
...     # image.bbox gives (x, y, width, height) in global CZI coordinates
...     x0, y0, *_ = image.bbox
...     plane_roi = image(T=0, C=0, roi=(x0, y0, 128, 128)).asarray()
...     assert plane_roi.shape == (3, 128, 128)  # 'Z', 'Y', 'X'
...
...     # fill pixels outside subblock coverage with a specific value
...     padded = image(C=0, roi=(0, 0, 2048, 2048)).asarray(fillvalue=0)
...     assert padded.shape == (2, 3, 2048, 2048)  # 'T', 'Z', 'Y', 'X'
...

Iterate image chunks:

>>> with CziFile('Example.czi') as czi:
...     image = czi.scenes[0]
...
...     # iterate individual Y/X planes as CziImage views
...     # by default, all non-spatial dims are iterated one-at-a-time
...     for chunk in image.chunks():
...         assert isinstance(chunk, CziImage)
...         assert chunk.asarray().shape == (486, 1178)
...
...     # keep C in each chunk: iterate T and Z only
...     for chunk in image.chunks(C=None):
...         assert chunk.asarray().shape == (2, 486, 1178)
...
...     # batch Z into groups of 3; last chunk may be smaller if Z indivisible
...     for chunk in image.chunks(Z=3):
...         assert chunk.sizes['Z'] <= 3
...
...     # spatial tiling: iterate T x C x Z x grid
...     for chunk in image.chunks(Y=256, X=256):
...         assert chunk.shape[-2] <= 256
...         assert chunk.shape[-1] <= 256
...
...     # keep C, tile spatially
...     for chunk in image.chunks(C=None, Y=256, X=256):
...         assert chunk.dims[0] == 'C'
...
...     # align spatial chunks with stored subblocks
...     assert image.subblock_sizes == {'Y': 256, 'X': 256}
...     chunks = image.chunks(**image.subblock_sizes)
...

Read image as xarray DataArray with physical coordinates and attributes:

>>> with CziFile('Example.czi') as czi:
...     xarr = czi.scenes[0].asxarray()
...     assert xarr.name == 'Scene 0'
...     assert xarr.sizes == {'T': 2, 'C': 2, 'Z': 3, 'Y': 486, 'X': 1178}
...     assert xarr.coords['X'].size == 1178  # physical axis coordinates
...

Access multiple scenes:

>>> with CziFile('Example.czi') as czi:
...     # iterate scenes individually and read as arrays
...     for image in czi.scenes.values():
...         arr = image.asarray()
...
...     # query which scenes (indices) are available
...     assert list(czi.scenes.keys()) == [0, 1, 2]
...
...     # select the second scene
...     assert czi.scenes[1].sizes == {
...         'T': 2,
...         'C': 2,
...         'Z': 3,
...         'Y': 256,
...         'X': 256,
...     }
...
...     # merge selected scenes into one
...     image = czi.scenes(scene=[0, 1])  # first 2 scenes
...     assert image.sizes == {'T': 2, 'C': 2, 'Z': 3, 'Y': 1109, 'X': 1760}
...
...     # merge all scenes into one
...     image = czi.scenes()
...     assert image.sizes == {'T': 2, 'C': 2, 'Z': 3, 'Y': 2055, 'X': 2581}
...

Access pyramid levels (scene -> level -> plane):

>>> with CziFile('Example.czi') as czi:
...     image = czi.scenes[0]
...     assert image.is_pyramid
...     assert len(image.levels) == 2  # full resolution + 1 downsampled level
...     assert image.levels[0] is image  # full resolution level is image
...     level = image.levels[-1]  # lowest-res level
...     assert level.sizes == {'T': 2, 'C': 2, 'Z': 3, 'Y': 243, 'X': 589}
...     arr = level.asarray()  # full level image as array
...     plane = level(T=0, C=0, Z=0).asarray()  # single plane as array
...     assert plane.shape == (243, 589)
...

Iterate directory entries as CziImage views:

>>> with CziFile('Example.czi') as czi:
...     for entry in czi.scenes[0].directory_entries:
...         chunk = entry.asimage(czi)
...         arr = chunk.asarray()
...         assert arr.shape == (256, 256)
...

Access attachments:

>>> with CziFile('Example.czi') as czi:
...     for attachment in czi.attachments():
...         name = attachment.attachment_entry.name
...         data = attachment.data()  # decoded (ndarray, tuple, bytes...)
...         raw = attachment.data(raw=True)  # bytes; may be written to file
...
...     # convenience shortcut for TimeStamps attachment data
...     assert czi.timestamps.shape == (2,)
...

Low-level access to CZI file segments:

>>> with CziFile('Example.czi') as czi:
...     # file header: version, GUIDs, and segment offsets
...     header = czi.header
...     assert header.version == (1, 0)
...     assert str(header.file_guid) == 'f8a61493-053e-c94e-bae0-bc7e96d18997'
...     assert not header.update_pending
...
...     # iterate all subblock segments sequentially via the directory
...     for segdata in czi.subblocks():
...         entry = segdata.directory_entry
...         assert entry.dims == ('H', 'T', 'C', 'Z', 'Y', 'X', 'S')
...         assert entry.start == (0, 0, 0, 0, 0, 582, 0)
...         assert entry.shape == (1, 1, 1, 1, 486, 1178, 1)
...         assert entry.stored_shape == (1, 1, 1, 1, 243, 589, 1)
...         assert entry.compression == CziCompressionType.ZSTDHDR
...         assert segdata.data_offset == 661865  # offset of image data
...         assert segdata.data_size == 183875  # size of compressed image data
...         tile = segdata.data()  # decompressed image data as numpy array
...         assert tile.shape == entry.stored_shape
...         assert tile.dtype == entry.pixel_type.dtype
...         assert isinstance(segdata.data(raw=True), bytes)  # compressed data
...         assert segdata.metadata().startswith('<METADATA>')
...         mask = segdata.mask()  # optional validity mask
...         break  # just the first subblock segment for demonstration
...
...     # iterate only image tiles in a selected image view
...     image = czi.scenes[0](T=0, C=0, Z=0)
...     for entry in image.directory_entries:
...         segdata = entry.read_segment_data(czi)
...         assert isinstance(segdata, CziSubBlockSegmentData)
...         tile = segdata.data()
...         assert tile.shape == entry.stored_shape
...         break  # just the first filtered directory entry
...
...     # walk all file segments by type using their ZISRAW segment IDs
...     for segdata in czi.segments(CziSegmentId.ZISRAWSUBBLOCK):
...         assert isinstance(segdata, CziSubBlockSegmentData)
...
...     # direct low-level segment header at a known file offset
...     seg = CziSegment(czi, czi.header.directory_position)
...     assert seg.sid == CziSegmentId.ZISRAWDIRECTORY
...     assert seg.used_size == 68768
...     seg_data = seg.data()
...     assert isinstance(seg_data, CziSubBlockDirectorySegmentData)
...

View the images and metadata in a CZI file from the console:

$ python -m czifile Example.czi

Metadata

Release files for czifile 2026.11.26

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for czifile 2026.11.26
File Size Uploaded Provenance Actions
czifile-2026.11.26.tar.gz 113.4 kB Without provenance Details for czifile-2026.11.26.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for czifile 2026.11.26
File Interpreter ABI Platform Actions
czifile-2026.11.26-py3-none-any.whl Python 3 none any Details for czifile-2026.11.26-py3-none-any.whl

Total release size: 183.2 kB

Release files / czifile-2026.11.26.tar.gz

Download URL czifile-2026.11.26.tar.gz
Size 113.4 kB
Tags Source
SHA-256 checksum
How to use checksums
17cefaba43f8a4a1cc416d823fedb7ea7e6a2d6085c1ae2b74bd09f794dfaad3
BLAKE2b-256 checksum
How to use checksums
d41ecbb5ab2753f6e545d717787d9b60e4bcc01c0c54edb0b4fce1d7025d5a9a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.10

Release files / czifile-2026.11.26-py3-none-any.whl

Download URL czifile-2026.11.26-py3-none-any.whl
Size 69.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
faadb682d079b4585e217f5b04d57e754512b0c98e5bc073a102fa353e7eb46c
BLAKE2b-256 checksum
How to use checksums
0731072be81fc02c9a9a8f7e2a22711b8cce4070014e106b04c9fd21d8fdcedc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.10

Security for czifile 2026.11.26

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

2026.11.26 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page