Skip to main content

Read Leica image files (LIF, LOF, XLIF, XLEF, XLCF, XLLF, and LIFEXT)

Liffile is a Python library to read image and metadata from Leica image files: LIF (Leica Image File), LOF (Leica Object File), XLIF (XML Image File), XLCF (XML Collection File), XLEF (XML Experiment File), XLLF (XML Folder View File), and LIFEXT (Leica Image File Extension). These files are written by LAS X software to store collections of images and metadata from microscopy experiments.

Author:

Christoph Gohlke

License:

BSD-3-Clause

Version:

2026.11.12

DOI:

10.5281/zenodo.14740657

Quickstart

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

python -m pip install -U liffile[all]

See Examples and Documentation for using the programming interface.

Source code and support are available on GitHub.

Requirements

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

  • CPython 3.12.10, 3.13.17, 3.14.10, 3.15.2 64-bit

  • Numpy 2.5.4

  • Imagecodecs 2026.11.11 (required for decoding TIFF, JPEG, PNG, and BMP)

  • Tifffile 2026.11.12 (required for reading multi-page TIFF)

  • Xarray 2026.9.0 (recommended)

  • Matplotlib 3.11.2 (optional)

Revisions

2026.11.12

  • Fix infinite recursion on cyclic references in XLEF, XLCF, and XLLF files.

  • Fix images of all but first parent missing in LIFEXT files.

  • Fix BGR channel order and names of XLIF images referencing external files.

  • Raise LifFileError for dimensions with zero BytesInc.

2026.11.8

  • Fix reading stride-aligned RGB images and frames.

  • Fix LifFile.xml_header truncated for memory-mapped XML files.

  • Fix LifChannel.is_lut_inverted always True.

  • Fix images with duplicate paths in child files overwritten.

  • Fix parent_image and child_images with regex characters in paths.

  • Fix reading frames of images with multiple channel axes.

  • Fix child files not closed when opening child fails.

  • Fix old-style LOF files with XML special characters in file name.

  • Raise LifFileError instead of KeyError or AssertionError for corrupted files.

2026.10.14

  • Fix child files not closed when LifFile is opened from binary stream.

  • Fix zero-length frame selections squeezed like singleton dimensions.

  • Fix missing index validation for frames in XLIF referencing OME/AIVIA TIFF.

2026.10.8

  • Support XLLF (folder view) files.

2026.10.3

  • Do not remove images with duplicate paths (bioio-lif issue 55).

2026.7.14

  • Add option to memory-map LIF files.

  • Drop support for numpy 2.0 (SPEC0).

  • Support Python 3.15.

2026.4.11

  • …

Refer to the CHANGES file for older revisions.

Notes

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

Leica Microsystems GmbH is a manufacturer of microscopes and scientific instruments. Leica image files are proprietary formats written by Leica acquisition software such as LAS X and LAS AF to store microscopy images and metadata.

The Leica Image File (LIF) begins with a magic number followed by a UTF-16 XML header that describes images and metadata, then stores the raw pixel data for each image in contiguous data blocks. Images may be multi-dimensional (X, Y, Z, T, C, …) with multiple channels, and a single file can contain many independent image series. Related formats include LOF (single-object variant), XLIF, XLEF, and XLCF (XML-based containers), XLLF (folder-view), and LIFEXT (optional image data extensions).

This library is not feature-complete. Unsupported features currently include image mosaics and pyramids, bit increments, heterogeneous channel dtypes, and non-image data such as raw FLIM/TCSPC histogram data.

The library has been tested with only a limited number of version 2 files.

The Leica image file formats are documented in:

  • Leica Image File Formats - LIF, XLEF, XLLF, LOF. Version 3.2. Leica Microsystems GmbH. 21 September 2016.

  • Annotations to Leica Image File Formats for LAS X Version 3.x. Version 1.4. Leica Microsystems GmbH. 24 August 2016.

  • TSC SP8 FALCON File Format Description. LAS X Version 3.5.0.

Other implementations for reading Leica image files are readlif and Bio-Formats.

Examples

Import functions and classes used in these examples:

>>> from liffile import LifFile

Read a FLIM lifetime image and metadata from a LIF file:

>>> with LifFile('tests/data/FLIM.lif') as lif:
...     for image in lif.images:
...         _ = image.name
...     image = lif.images['Fast Flim']  # by name
...     assert image.dtype == 'float16'
...     assert image.sizes == {'Y': 1024, 'X': 1024}
...     lifetimes = image.asxarray()
...
>>> lifetimes
<xarray.DataArray 'Fast Flim' (Y: 1024, X: 1024)> Size: 2MB
array([[...]],
      shape=(1024, 1024), dtype=float16)
Coordinates:
  * Y        (Y) float64... 0.0005564
  * X        (X) float64... 0.0005564
Attributes...
    path:           FLIM_testdata.lif/sample1_slice1/FLIM Compressed/Fast Flim
    UniqueID:       694efd02-95a9-436e-0fa6-f146120b1e15
    F16:            {'Name': 'F16',...
    TileScanInfo:   {'Tile': {'FieldX': 0,...
    ViewerScaling:  {'ChannelScalingInfo': {...

Iterate over selected XLEF image frames in ZTM dimension order:

>>> with LifFile('tests/data/XYZCST/XYZCST.xlef') as lif:
...     image = lif.images[0]  # by index
...     image.sizes
...     frames = image.frames(C=1, Z=slice(1, 3), T=[1, 0], M=None)
...     frames.sizes
...     for index, frame in frames.items():
...         index, frame.shape
...
{'T': 2, 'M': 4, 'C': 3, 'Z': 5, 'Y': 1200, 'X': 1600}
{'Z': 2, 'T': 2, 'M': 4, 'Y': 1200, 'X': 1600}
((0, 0, 0), (1200, 1600))
((0, 0, 1), (1200, 1600))
...
((1, 1, 2), (1200, 1600))
((1, 1, 3), (1200, 1600))

View image and metadata in a LIF file from the console:

$ python -m liffile tests/data/FLIM.lif

Metadata

Release files for liffile 2026.11.12

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

Source distribution (sdist)

Source distribution for liffile 2026.11.12
File Size Uploaded Provenance Actions
liffile-2026.11.12.tar.gz 63.3 kB Without provenance Details for liffile-2026.11.12.tar.gz

Built distribution (wheel)

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

Total release size: 104.6 kB

Release files / liffile-2026.11.12.tar.gz

Download URL liffile-2026.11.12.tar.gz
Size 63.3 kB
Tags Source
SHA-256 checksum
How to use checksums
a405c45a04f38150a7f3631076715943708164f1e9140ac5fb3dbb1a88363484
BLAKE2b-256 checksum
How to use checksums
fa8908570df209ed44f20912388ab276967f61c8a546222fea762ed72dbdb49d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.10

Release files / liffile-2026.11.12-py3-none-any.whl

Download URL liffile-2026.11.12-py3-none-any.whl
Size 41.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c2cfbe5a5ec6d9ed708a027c9d19d49fc87cb6a6c7c2584664e2d2f045f47bca
BLAKE2b-256 checksum
How to use checksums
fb0b8a5d3393aec943666acd9678f19ef94e4db2d22646a75a71750cfc06ffb3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.10

Security for liffile 2026.11.12

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

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