MonOCR (Python SDK)
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.3.0"
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.
- One API for images and PDFs: the same call shape for a line, a page and a document.
- Line segmentation: adaptive thresholding, with padding relative to each line's height.
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.
CLI Usage
# Recognize an image
monocr image input.jpg
# Process a PDF
monocr pdf document.pdf
# Batch directory processing
monocr batch ./input
# Pre-fetch the model and charset
monocr 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 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.3.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| monocr_onnx-0.3.2.tar.gz | 55.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| monocr_onnx-0.3.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 82.9 kB
Release files / monocr_onnx-0.3.2.tar.gz
| Download URL | monocr_onnx-0.3.2.tar.gz |
|---|---|
| Size | 55.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3bfbcaa87f7ecb4ffb53c3b747c17f52b0ce8e4022abb65e66597b9547810574
|
|
BLAKE2b-256 checksum How to use checksums |
7ec9bbe42235f34f0955be2eab68eeddc70d270b56d3bdde818c2d85d03abedc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.9 {"installer":{"name":"uv","version":"0.12.9","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.3.2-py3-none-any.whl
| Download URL | monocr_onnx-0.3.2-py3-none-any.whl |
|---|---|
| Size | 27.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
419c16665249077e76a65216fa20d7d9d4235e9525943dbe2a6326f104ba8d09
|
|
BLAKE2b-256 checksum How to use checksums |
a0b01698c9a8b5d38c802b0b75b93b8ef9adf48efaa36f8441bbc029bf379dda
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.9 {"installer":{"name":"uv","version":"0.12.9","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}
|