Skip to main content

MonOCR (Python SDK)

PyPI

The official Python SDK for Mon language OCR, powered by ONNX Runtime. Optimized for high-throughput batch processing and production server environments.

Installation

pip install "monocr-onnx>=0.4.1"

Features

  • Pinned to one network: the v3.5 recogniser at revision d3d9d5e, with 160px input height, 276 characters, 277 CTC classes. No accuracy figure is claimed here; see the model card for the held-out result and its caveats.
  • Parallel Processing: Native support for multithreaded batch OCR.
  • Pinned Model: Weights and charset are fetched from one immutable Hugging Face revision, checksummed, and cached per revision.
  • Images and PDFs: images through MonOCR, PDFs through read_pdf. These are different calls, not one polymorphic one — see the API reference below.
  • Line segmentation: adaptive thresholding, with padding relative to each line's height.

What to know before you start

  • First run downloads the model. Roughly 46 MB, fetched from the pinned Hugging Face revision and cached per revision. Nothing works offline until that has happened once.
  • PDFs need poppler on the PATH, on every platform. read_pdf goes through pdf2image, which shells out to pdftoppm. Without it the call raises a RuntimeError naming poppler; it does not fail quietly. Images need nothing extra. See Platforms below.
  • MonOCR.predict does not accept a PDF. It opens the path as an image and raises PIL.UnidentifiedImageError on a PDF. Use read_pdf.
  • The CLI is monocr-onnx, not monocr. It was monocr up to 0.3.2, which collided with the command installed by the separate monocr package; in an environment holding both, install order decided which one you got.
  • Throughput. On an Apple M5, a typeset page is about 2 s and a 10-page scanned PDF about 78 s, model already cached. CPU only; no GPU path here.
  • No accuracy figure is claimed by this package. The model card reports a held-out CER of 0.0100 on 150 unseen rendered lines in a typeface the model never trained on, with a 95% interval of [0.0056, 0.0147]. Those lines come from the same synthetic generator as the training data, so nothing on the card is measured on photographed pages. Read its caveats before quoting the number.

Platforms

The wheel is pure Python (py3-none-any) and every native dependency — onnxruntime, opencv-python-headless, numpy, Pillow — publishes wheels for Linux, macOS and Windows, so pip install needs no compiler on any of them.

Only poppler is manual, and only for PDFs.

macOS

brew install poppler

Linux

sudo apt-get install poppler-utils   # Debian, Ubuntu

Other distributions package the same binaries, usually as poppler-utils or poppler.

Windows

Not shipped with Windows and there is no single official installer. Any of these works:

scoop install poppler
choco install poppler
conda install -c conda-forge poppler

Or take the prebuilt binaries from oschwartz10612/poppler-windows, unzip, and add the Library\bin directory to PATH — that release is what pdf2image's own documentation points Windows users at. pdf2image also accepts a poppler_path argument, but read_pdf does not forward one, so PATH is the route here.

Check with pdfinfo -v in a new shell before calling read_pdf.

Quick Start

from monocr_onnx import MonOCR

# Initialize engine (downloads model automatically on first run)
engine = MonOCR()

# Recognize single image
text = engine.predict("document.png")
print(text)

# Recognize single line (for custom layout analysis)
line_text = engine.predict_line("line_crop.png")

API Reference

MonOCR(model_path=None, charset_path=None)

Initialize the OCR engine. If paths are omitted, the pinned model and its charset are downloaded on first use.

Loading refuses a model whose output class count or input height disagrees with the charset — a mismatched pair still runs and still returns text, it is just the wrong text.

predict(image_path) -> str

Recognize text from a single image file or page. Alias for predict_page.

predict_line(image) -> str

Recognize text from a single cropped text line image (PIL).

predict_page(image_path) -> str

Segment an image into lines and recognize each.

read_pdf(pdf_path, model_path=None, charset_path=None) -> list[str]

Module-level, not a method. Renders every page through poppler and returns one string per page. This is the only PDF entry point.

from monocr_onnx import read_pdf

pages = read_pdf("book.pdf")
print(len(pages), "pages")
print(pages[0])

read_pdfs(paths, ...) -> list[list[str]]

The same over several files.

CLI Usage

# Recognize an image
monocr-onnx image input.jpg

# Process a PDF
monocr-onnx pdf document.pdf

# Batch directory processing
monocr-onnx batch ./input

# Pre-fetch the model and charset
monocr-onnx download

Model artifact

The model and its charset are pinned to janakhpon/monocr@d3d9d5e (v3.5: 160px input height, 276 characters, 277 CTC classes) and verified by sha256 after download. They are never fetched from main — that ref has already moved under this package once, replacing a 64px / 225-class network with the current one.

The cache lives at ~/.monocr/models/<revision>/, so bumping the pin misses the cache rather than silently reusing old weights.

If you installed 0.1.0, a stale ~/.monocr/models/monocr.onnx may still be on disk. Nothing reads it any more; monocr-onnx download will point it out and it is safe to delete.

Requirements

  • Python 3.11+ — onnxruntime 1.24.1 ships no wheel below cp311 and no sdist, so 3.10 and below have nothing to install
  • opencv-python-headless (line segmentation)
  • onnxruntime 1.24.1 (CPU or GPU), pinned in uv.lock

Maintenance

Maintained by MonDevHub.

License

MIT

Release files for monocr-onnx 0.4.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for monocr-onnx 0.4.2
File Size Uploaded
monocr_onnx-0.4.2.tar.gz 57.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for monocr-onnx 0.4.2
File Interpreter ABI Platform
monocr_onnx-0.4.2-py3-none-any.whl Python 3 none any Details

Total release size: 86.1 kB

Release files / monocr_onnx-0.4.2.tar.gz

Download URL monocr_onnx-0.4.2.tar.gz
Size 57.0 kB
Tags Source
SHA-256 checksum
How to use checksums
e6f66df22cdf35d10f88ab67e44a15dcbedc83fe70c316909b923ba08a02bebf
BLAKE2b-256 checksum
How to use checksums
3f3bed20cd9d4c323180fdbe4e2d9f69525b1a19a0fe9fd3dbcae6828475bbbe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.18 {"installer":{"name":"uv","version":"0.12.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / monocr_onnx-0.4.2-py3-none-any.whl

Download URL monocr_onnx-0.4.2-py3-none-any.whl
Size 29.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e4384790958edb9b90cc62b95eb7fe8b5e8f5d171aa41301117da8c7c0c8c549
BLAKE2b-256 checksum
How to use checksums
68f8f59b31483cdebda85c2d284ebd8a7ac23be4499f64a8833ec09ddbef2643
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.18 {"installer":{"name":"uv","version":"0.12.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

This release

0.4.2 This release

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.2

2 release files

0.3.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page