A minimal Python wrapper around the PAGE-XML format for OCR output. Can also import ALTO-XML.
pip install pygexml
Requires Python 3.12+.
frompygexmlimportPagepage=Page.from_xml_file("docs/xml_file.xml")
forlineinpage.all_text():
print(line)All dataclasses are serializable with to_dict/from_dict and to_json/from_json via dataclasses-json.
| Class | Import from |
|---|---|
Page | pygexml |
Page, TextRegion, TextLine, Coords | pygexml.page |
Point, Box, Polygon | pygexml.geometry |
Page, TextRegion and TextLine each expose all_text() and all_words() iterators. On Page, these respect the PAGE-XML reading order if present.
Lookups by ID are available via lookup_region() and lookup_textline(). The reading order is also accessible directly via regions_ordered().
Refer to the online API docs for details.
The pygexml.strategies module provides Hypothesis strategies for all pygexml types, ready to use in property-based tests - including downstream projects:
fromhypothesisimportgivenfrompygexml.strategiesimportst_pages@given(st_pages())deftest_my_page_processing(page):
assertprocess(page) isnotNoneRefer to the pygexml.strategies API docs for details.
pip install ".[dev,test,docs]"
black pygexml test# format
mypy pygexml test# type check
pyright pygexml test# type check
pytest -v # tests
pdoc -o .api_docs ./pygexml # API docsCI runs on Python 3.12, 3.13 and 3.14. API documentation is published to GitHub Pages on every push to main.
Bug reports, feature requests and pull requests are welcome. Feel free to open draft pull requests early to invite discussion and collaboration.
Please note that this project has a Code of Conduct.
Copyright (c) 2026 Mirko Westermeier, Katharina Dietz (SCDH, University of Münster)
Released under the MIT License.