Skip to main content

A modern, powerful,and extremly fast Python library for reading, writing, and modifying PAGE-XML files.

Project description

pypxml

Python Version License PyPI version

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

[!NOTE] Alternatively install with pip: pip install 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 schema validation
page.save('output.xml', schema='2019')

Command Line Interface

For common analytics and regularization operations, the command line interface (cli) can be installed

Setup

uv tool install pypxml[cli]

[!NOTE] Alternatively install with pip: pip 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

[!NOTE] The experiments where conducted on an Intel 12th Gen i7-12700

Related Projects

  • PAGE-XML - The PAGE-XML format specification
  • OCR-D - OCR framework using PAGE-XML

ZPD

Developed at Centre for Philology and Digitality (ZPD), University of Würzburg.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pypxml-5.1.0.tar.gz (25.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pypxml-5.1.0-py3-none-any.whl (28.4 kB view details)

Uploaded Python 3

File details

Details for the file pypxml-5.1.0.tar.gz.

File metadata

  • Download URL: pypxml-5.1.0.tar.gz
  • Upload date:
  • Size: 25.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for pypxml-5.1.0.tar.gz
Algorithm Hash digest
SHA256 a01f8e82c3e4fdd73070d0c386acb660c5d9cac07e6bdd4218353bf3c5172091
MD5 c87defc6586318e7c61bd24653020d47
BLAKE2b-256 7ecff91ead4e5e09d429e7a203c3b8a0a5d6b955ca5b7b471382649bdf881655

See more details on using hashes here.

File details

Details for the file pypxml-5.1.0-py3-none-any.whl.

File metadata

  • Download URL: pypxml-5.1.0-py3-none-any.whl
  • Upload date:
  • Size: 28.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for pypxml-5.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 160f5762e7adb030ee7402e9b1f5014665f280ac48741c13b447bb88e040feb7
MD5 6174ea4561708ce8b69628264b25e083
BLAKE2b-256 6831a57e0d32d7d9287cc29d170b2e1346d48f18e9cb552b011cf57b2595df79

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page