Registry / serialization / ome-types

ome-types

JSON →
library0.6.3pypypi✓ verified 84d ago

Python dataclasses for the OME (Open Microscopy Environment) data model. Provides type-annotated Python objects for OME-XML metadata, enabling type-safe construction and serialization of OME metadata. Current version 0.6.3, supports Python >=3.9. Maintained by tlambert03, regular releases.

pip install ome-types
INSTALL
IMPORT
SIG · OME-TYPES
O
ome-types
serializationpythonv0.6.3
Install
3.5s avg
Import
1371ms
Disk
31MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.6.3 · 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.95 runs
installs and imports cleanly · install 0.0s · import 1.408s · 33.2MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 3.5s · import 1.334s · 33MB
31MB installed
● package 31MB
Code
Verified usage

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

OME
from ome_types import OME
Image
from ome_types.model import Image
Pixels
from ome_types.model import Pixels
OME as model
from ome_types.model import OME
from ome_types import OME (this is also correct for the top-level OME, but if you want the model specifically use the model submodule)
Both imports work for OME, but model submodule is explicit for internal model classes.

Create an OME object programmatically with required fields and serialize to XML.

from ome_types import OME from ome_types.model import Image, Pixels # Create minimal OME object ome = OME(images=[Image(id='Image:0', name='test', pixels=Pixels(id='Pixels:0', dimension_order='XYZCT', size_x=10, size_y=10, size_c=1, size_z=1, size_t=1, type='uint8'))]) print(ome.to_xml())
Debug
Known issues
gotchaOME model fields are validated at construction; missing required fields raise pydantic ValidationError. Always check required fields (e.g., id, dimension_order, size_x, etc.) for Images and Pixels.
fix
Refer to OME schema documentation for required attributes. Use pydantic's model_dump(mode='python') to debug.
affects: all
deprecatedIn version 0.6.0, the OME class was moved from ome_types.model to ome_types directly. Importing from the old path still works but may be deprecated.
fix
Use 'from ome_types import OME' instead of 'from ome_types.model import OME'.
affects: >=0.6.0
gotchaSerializing to XML with to_xml() will produce a string with default namespaces. If you need custom namespaces or formatting, use to_xml(nsmap=...) but those are not fully documented.
fix
Read the source or use the underlying pydantic XML serialization if needed.
affects: all
gotchaWhen parsing XML with from_xml(), ensure the XML is valid OME-XML. Invalid XML raises ParseError without clear message. Use lxml's parser for better error messages.
fix
Use lxml.etree.parse() to validate XML before passing to from_xml().
affects: all
Errors
Common errors & fixes
pydantic_core._pydantic_core.ValidationError: 1 validation error for OME
Missing required field when constructing OME or model objects.
fix
Check all required fields in the OME schema. For OME object, images is required (list of Image). For Image, id and name are required. For Pixels, id, dimension_order, size_x, size_y, size_c, size_z, size_t, type are required.
ModuleNotFoundError: No module named 'ome_types.model.OME'
Trying to import OME from wrong submodule; in older versions OME was in ome_types.model, newer versions it is in ome_types directly.
fix
Use 'from ome_types import OME' (top-level import) for current versions (>=0.6.0).
AttributeError: 'dict' object has no attribute 'to_xml'
Calling to_xml() on a dict instead of an OME model instance, often happens when using .model_dump() incorrectly.
fix
Ensure you have an OME object, not a dict. Use .model_dump(mode='python') to get dict representation, but to_xml() is only on the model object.
Upgrade
Version history
0.6.3latest on PyPI · released Nov 26, 2025
Audit
Dependencies
pydanticrequiredome-types uses pydantic BaseModel for its dataclasses, required for validation and serialization.
Agent activity
16 hits · last 30 days
node
16
Resources
ome-types — pip install ome-types · libregistry