Skip to main content

ome-types

License Version CondaVersion Python Version CI Docs codecov Benchmarks

A pure-python implementation of the OME data model

ome_types provides a set of python dataclasses and utility functions for parsing the OME-XML format into fully-typed python objects for interactive or programmatic access in python. It can also take these python objects and output them into valid OME-XML. ome_types is a pure python library and does not require a Java virtual machine.

Note: The generated python code can be seen in the built branch. (Read the code generation section for details).

📖   documentation

Installation

from pip

pip install ome-types

With all optional dependencies:

# lxml => if you ...
#           - want to use lxml as the XML parser
#           - want to validate XML against the ome.xsd schema
#           - want to use XML documents older than the 2016-06 schema
# pint      => if you want to use object.<field>_quantity properties
# xmlschema => if you want to validate XML but DON'T want lxml

pip install ome-types[lxml,pint]

from conda

conda install -c conda-forge ome-types

from github (bleeding edge dev version)

pip install git+https://github.com/imaging-formats/ome-types.git

Usage

convert an XML string or filepath into an instance of ome_types.model.OME

(The XML string/file will be validated against the ome.xsd schema)

from ome_types import from_xml

ome = from_xml("tests/data/hcs.ome.xml")

extract OME metadata from an OME-TIFF

from ome_types import from_tiff

ome2 = from_tiff("tests/data/ome.tiff")

manipulate the metadata via python objects

Both from_xml and from_tiff return an instance of ome_types.model.OME. All classes in ome_types.model follow the naming conventions of the OME data model, but use snake_case attribute names instead of CamelCase, to be consistent with the python ecosystem.

In [2]: ome = from_xml('tests/data/hcs.ome.xml')

In [3]: ome
Out[3]:
OME(
    images=[<1 Images>],
    plates=[<1 Plates>],
)

In [4]: ome.plates[0]
Out[4]:
Plate(
    id='Plate:1',
    name='Control Plate',
    column_naming_convention='letter',
    columns=12,
    row_naming_convention='number',
    rows=8,
    wells=[<1 Wells>],
)


In [5]: ome.images[0]
Out[5]:
Image(
    id='Image:0',
    name='Series 1',
    pixels=Pixels(
        id='Pixels:0',
        dimension_order='XYCZT',
        size_c=3,
        size_t=16,
        size_x=1024,
        size_y=1024,
        size_z=1,
        type='uint16',
        bin_data=[<1 Bin_Data>],
        channels=[<3 Channels>],
        physical_size_x=0.207,
        physical_size_y=0.207,
        time_increment=120.1302,
    ),
    acquisition_date=datetime.fromisoformat('2008-02-06T13:43:19'),
    description='An example OME compliant file, based on Olympus.oib',
)

Objects can be removed, or changed

In [6]: from ome_types.model.simple_types import UnitsLength

In [7]: from ome_types.model.channel import AcquisitionMode

In [8]: ome.images[0].description = "This is the new description."

In [9]: ome.images[0].pixels.physical_size_x = 350.0

In [10]: ome.images[0].pixels.physical_size_x_unit = UnitsLength.NANOMETER

In [11]: for c in ome.images[0].pixels.channels:
             c.acquisition_mode = AcquisitionMode.SPINNING_DISK_CONFOCAL

Elements can be added by constructing new OME model objects

In [12]: from ome_types.model import Instrument, Microscope, Objective, InstrumentRef

In [13]: microscope_mk4 = Microscope(
             manufacturer='OME Instruments',
             model='Lab Mk4',
             serial_number='L4-5678',
         )

In [14]: objective_40x = Objective(
             manufacturer='OME Objectives',
             model='40xAir',
             nominal_magnification=40.0,
         )

In [15]: instrument = Instrument(
             microscope=microscope_mk4,
             objectives=[objective_40x],
         )

In [16]: ome.instruments.append(instrument)

In [17]: ome.images[0].instrument_ref = InstrumentRef(id=instrument.id)

In [18]: ome.instruments
Out[18]:
[Instrument(
    id='Instrument:1',
    microscope=Microscope(
       manufacturer='OME Instruments',
       model='Lab Mk4',
       serial_number='L4-5678',
    ),
    objectives=[<1 Objectives>],
 )]

export to an OME-XML string

Finally, you can generate the OME-XML representation of the OME model object, for writing to a standalone .ome.xml file or inserting into the header of an OME-TIFF file:

In [19]: from ome_types import to_xml

In [20]: print(to_xml(ome))
<OME ...>
    <Plate ColumnNamingConvention="letter" Columns="12" ID="Plate:1" ...>
        ...
    </Plate>
    <Instrument ID="Instrument:1">
        <Microscope Manufacturer="OME Instruments" Model="Lab Mk4" SerialNumber="L4-5678" />
        <Objective Manufacturer="OME Objectives" Model="40xAir" ID="Objective:1"
        NominalMagnification="40.0" />
    </Instrument>
    <Image ID="Image:0" Name="Series 1">
        <AcquisitionDate>2008-02-06T13:43:19</AcquisitionDate>
        <Description>This is the new description.</Description>
        <InstrumentRef ID="Instrument:1" />
        <Pixels ... PhysicalSizeX="350.0" PhysicalSizeXUnit="nm" ...>
            <Channel AcquisitionMode="SpinningDiskConfocal" ...>
             ...
        </Pixels>
    </Image>
</OME>

Code generation

The bulk of this library (namely, modules inside ome_types._autogenerated) is generated at install time, and is therefore not checked into source (or visible in the main branch of this repo).

You can see the code generated by the main branch in the built branch

The package at src/ome_autogen converts the ome.xsd schema into valid python code. To run the code generation script in a development environment, clone this repository and run:

python -m src.ome_autogen

The documentation and types for the full model can be in the API Reference

Contributing

To clone and install this repository locally:

git clone https://github.com/imaging-formats/ome-types.git
cd ome-types
pip install -e .[test,dev]

We use pre-commit to run various code-quality checks during continuous integration. If you'd like to make sure that your code will pass these checks before you commit your code, you should install pre-commit after cloning this repository:

pre-commit install

regenerating the models

If you modify anything in src/ome_autogen, you may need to regenerate the model with:

python -m src.ome_autogen

Running tests

To run tests:

pytest

Metadata

Release files for ome-types 0.7.0

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

Source distribution (sdist)

Source distribution for ome-types 0.7.0
File Size Uploaded
ome_types-0.7.0.tar.gz 121.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ome-types 0.7.0
File Interpreter ABI Platform
ome_types-0.7.0-py3-none-any.whl Python 3 none any Details

Total release size: 367.7 kB

Release files / ome_types-0.7.0.tar.gz

Download URL ome_types-0.7.0.tar.gz
Size 121.8 kB
Tags Source
SHA-256 checksum
How to use checksums
50730f90dd17c3fe4305f15ff0990d2b431df684bb1551312d4cd3f0bc35e584
BLAKE2b-256 checksum
How to use checksums
f987f955e16dbc39299d8debcc2e04f81d15c881e470087387ffde7b631ec0c7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 16, 2026.

Transparency log

Release files / ome_types-0.7.0-py3-none-any.whl

Download URL ome_types-0.7.0-py3-none-any.whl
Size 245.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5922396aae4832355d25d9d1ece1615206a39e52e377efe80da4767eac070635
BLAKE2b-256 checksum
How to use checksums
70b0c9df0b9cbf3bd36480c10693fe532b109f2c1d1cafaa4633dbbba5e68588
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 16, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.7.0 This release

2 release files

0.6.3

2 release files

0.6.2

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.3

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.5

2 release files

0.4.3

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.4

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.10

2 release files

0.2.9

2 release files

0.2.8

2 release files

0.2.7

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.0

2 release files

0.0.1

2 release files

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