Convert between OCR output formats via a neutral intermediate model.
Project description
ocronverter
Convert between OCR output formats through a single neutral intermediate model.
<provider data> --parse--> Document (neutral) --emit--> <provider data>
Instead of writing an N×N matrix of direct converters, every format has one
parser (provider → Document) and one emitter (Document → provider).
Any source can then be converted to any target.
Installation
pip install ocronverter
Requires Python 3.10+. The library is pure Python with no runtime dependencies.
Supported formats
| Engine | Canonical name | Aliases | Data shape |
|---|---|---|---|
| Google Cloud Vision | google_vision |
google, googlevision, vision, gcv |
JSON |
| AWS Textract | textract |
aws, aws_textract |
JSON |
Tesseract (image_to_data) |
tesseract |
tess, tsv |
JSON dict / TSV |
| Azure AI Document Intelligence | azure |
azure_di, document_intelligence, form_recognizer, di |
JSON |
| hOCR | hocr |
ocr_html |
XHTML string |
EasyOCR (readtext) |
easyocr |
easy_ocr, easy |
list of detections |
Format names are case-insensitive and -/_ interchangeable.
ocronverter.list_formats() returns the canonical list at runtime.
Usage
import ocronverter
# Parse provider output into the neutral Document
doc = ocronverter.parse(data, "google_vision")
# Emit the neutral Document as another provider's format
out = ocronverter.emit(doc, "textract")
# Or do both in one step
out = ocronverter.convert(data, "google_vision", "textract")
out = ocronverter.convert(data, "gcv", "hocr", as_json=False) # aliases OK
data may be a dict, a JSON string, a Python list (EasyOCR's native
detections shape), or an hOCR/XHTML string. convert returns a dict (or a
list for EasyOCR, or a str for hOCR); pass as_json=True for a JSON string
where the target is JSON-based.
Line synthesis (split_lines)
Google Vision groups by paragraph and has no real line level, while
line-oriented targets (Textract, Tesseract, Azure, hOCR, EasyOCR) read best with
one entry per visual line. convert(..., split_lines=...) controls this:
"auto"(default) — split only when going from a paragraph source to a line-oriented target.True/False— force on or off.
The neutral model
Document
└─ Page[] size + rotation; the coordinate anchor
└─ Block[] ~ paragraph / region
└─ Line[]
└─ Word[]
└─ Symbol[] (optional; char/glyph level)
Conventions:
- Every level is optional. Parsers fill only what the source provides; the
library never invents levels on parse. Missing levels are synthesized on
demand via
synth.py(opt-in). - Geometry is stored normalized (0.0–1.0 of the page) as both an
axis-aligned bbox and a polygon, kept in sync.
Page.width/height/unitanchor denormalization back to provider pixels (or Azure inches). - Confidence is always stored 0.0–1.0 internally; parsers rescale.
provider_metaon every node carries source-specific fields verbatim, so a same-format round-trip is best-effort lossless.
Format-specific notes
- Tesseract / hOCR have a paragraph level the model lacks; it is carried on
Line.provider_meta(par_num/par_id) and regrouped on emit. - Azure uses flat per-page
words[]/lines[]lists whose nesting is reconstructed from character span offsets, and may useinchpage units. - hOCR is an XHTML string: geometry and confidence live in each element's
titleattribute (bbox,x_wconf). Optional char-levelocrx_cinfois not modeled (no glyph level). - EasyOCR is a flat
[polygon, text, confidence]list with no hierarchy and no page dimensions. Each detection becomes aLine+ singleWord; page dims are inferred from the max extent of all polygons (pass a{"width", "height", "results"}wrapper to supply true dims).
Tests
python -m pytest tests/
Each format has a round-trip test (provider → Document → provider) plus
cross-format bridge tests. Tests are stdlib-only and need no OCR binaries,
except test_real_tesseract, which runs only if the tesseract binary and PIL
are installed.
License
MIT — see LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ocronverter-0.1.1.tar.gz.
File metadata
- Download URL: ocronverter-0.1.1.tar.gz
- Upload date:
- Size: 134.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5dbbb123c48e2b89028fa3c335743c29854252d33c712d57b0e3c8bc4afe3a6f
|
|
| MD5 |
0b205f140df5f6a19907fc03f81dc789
|
|
| BLAKE2b-256 |
29a5f273ecabb798e5b6625a380f24a13ad49cda044c0a4d892fe6f4f45c27bd
|
Provenance
The following attestation bundles were made for ocronverter-0.1.1.tar.gz:
Publisher:
publish.yml on gxlarson/ocronverter
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ocronverter-0.1.1.tar.gz -
Subject digest:
5dbbb123c48e2b89028fa3c335743c29854252d33c712d57b0e3c8bc4afe3a6f - Sigstore transparency entry: 2237758278
- Sigstore integration time:
-
Permalink:
gxlarson/ocronverter@c644767329cdcd7c092873ab088a1b3a08a4ff0a -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/gxlarson
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@c644767329cdcd7c092873ab088a1b3a08a4ff0a -
Trigger Event:
push
-
Statement type:
File details
Details for the file ocronverter-0.1.1-py3-none-any.whl.
File metadata
- Download URL: ocronverter-0.1.1-py3-none-any.whl
- Upload date:
- Size: 35.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
43b849d323d3d4743b428f952cd06842432fee60acd90d21a634314e1c5f8cd7
|
|
| MD5 |
23bab940749ce234c68e0d10a489f2c7
|
|
| BLAKE2b-256 |
b2e6947482edd487eb2b7fade22bb538111059b14db50dac13c0d0e00d203238
|
Provenance
The following attestation bundles were made for ocronverter-0.1.1-py3-none-any.whl:
Publisher:
publish.yml on gxlarson/ocronverter
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ocronverter-0.1.1-py3-none-any.whl -
Subject digest:
43b849d323d3d4743b428f952cd06842432fee60acd90d21a634314e1c5f8cd7 - Sigstore transparency entry: 2237758911
- Sigstore integration time:
-
Permalink:
gxlarson/ocronverter@c644767329cdcd7c092873ab088a1b3a08a4ff0a -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/gxlarson
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@c644767329cdcd7c092873ab088a1b3a08a4ff0a -
Trigger Event:
push
-
Statement type: