pypxml
A modern, powerful,and extremly fast Python library for reading, writing, and modifying PAGE-XML files.
PAGE-XML is the standard format for storing layout and text information from OCR and document analysis systems.
Python API
pypxml provides an intuitive Python API to interact with PAGE-XML files.
Install
uv add pypxml
Example
from pypxml import PageXML, PageType, PageUtil
# Open an existing PAGE-XML file
page = PageXML.open('document.xml')
# Access page metadata and attributes
print(f'Creator: {page.creator}')
print(f'Image: {page["imageFilename"]}')
# Find all text regions of type marginalia and extract their text
for region in page.find_all(PageType.TextRegion, type='marginalia'):
print(f'\nRegion {region["id"]}:')
# Get all text lines in this region
for line in region.find_all(PageType.TextLine, depth=-1):
text = PageUtil.find_text(line)
if text:
print(f'\t{text}')
# Sort regions by their position
PageUtil.sort_regions(page, direction='top-bottom')
# Save with custom schema version
page.save('output.xml', schema='2024')
Command Line Interface
For common analytics and regularization operations, the command line interface (cli) can be installed
Setup
uv tool install pypxml[cli]
Usage
$ pypxml --help
Usage: pypxml [OPTIONS] COMMAND [ARGS]...
A modern, powerful,and extremly fast Python library for reading, writing,
and modifying PAGE-XML files
Options:
--help Show this message and exit.
--version Show the version and exit.
--logging [ERROR|WARNING|INFO] Set logging level. [default: ERROR]
Commands:
get-codec Extract character set from PAGE-XML files.
get-regions Extract region types from PAGE-XML files.
get-text Extract text from a PAGE-XML file.
regularize-codec Regularize character encodings in PAGE-XML files.
regularize-regions Regularize region types in PAGE-XML files.
Developed at Centre for Philology and Digitality (ZPD), University of
Würzburg
Benchmarks
Benchmarks were aggregated over 100 randomly selected PAGE-XML files representing common book pages. Below, the average time is listed for each operation and OCR granularity.
| Operation | Lines | Words | Glyphs | Description |
|---|---|---|---|---|
open |
0.8ms | 3.6ms | 20.6ms | Average time to open (and parse) a PAGE-XML file with OCR on TextLine, Word, or Glyph level |
search |
0.1ms | 0.5ms | 2.9ms | Average time to search for all TextLine, Word, or Glyph elements |
write |
1.6ms | 3.6ms | 13.6ms | Average time to write a PAGE-XML file with OCR on TextLine, Word, or Glyph level |
Related Projects
ZPD
Developed at Centre for Philology and Digitality (ZPD), University of Würzburg.
Metadata
Release files for pypxml 5.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pypxml-5.2.0.tar.gz | 25.6 kB | Without provenance | Details for pypxml-5.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pypxml-5.2.0-py3-none-any.whl | Python 3 | none | any | Details for pypxml-5.2.0-py3-none-any.whl |
Total release size: 54.0 kB
Release files / pypxml-5.2.0.tar.gz
| Download URL | pypxml-5.2.0.tar.gz |
|---|---|
| Size | 25.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2192c946bb7b08ea880f37ce7a19d01161ad8e096e1838f200b2eff5082467f9
|
|
BLAKE2b-256 checksum How to use checksums |
542912b00949b6434db89e227078cb0c75489b6714e40c995b3f0829bd381dc8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.3
|
Release files / pypxml-5.2.0-py3-none-any.whl
| Download URL | pypxml-5.2.0-py3-none-any.whl |
|---|---|
| Size | 28.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
58552f5cc14edd4732b9f817a5ec88d00891312cc6bc2bb5606a8ef0692f4e59
|
|
BLAKE2b-256 checksum How to use checksums |
ff36169baafb344b49a27b8f90adf5ff7f67ffc8175517ca5bc39b90bdd79dcd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.3
|
Security for pypxml 5.2.0
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.