Python bindings for the native Rust LightOnOCR2-1B inference engine
Project description
fast-lightonocr
⚡ Native Python bindings for the Rust Fast LightOnOCR inference engine.
fast-lightonocr provides high-performance OCR for documents and images using
Baidu's LightOnOCR model. Model inference runs entirely in native Rust,
while the Python package adds automatic Hugging Face downloads and structured
document parsing.
✨ Features
- 🚀 Native Rust inference engine
- 🧠 ONNX Runtime backend
- 📄 OCR for documents and images
- 📝 Structured Markdown output
- 📊 Structured HTML table extraction
- 🎨 Configurable table rendering
- 🎛️ Multiple model presets (
default,fp16,q4)
📦 Installation
Install with pip:
pip install fast-lightonocr
Prebuilt wheels are currently published for Linux x86_64 and macOS arm64.
macOS x86_64/Intel wheels are not published because ONNX Runtime 1.28 does not
provide a compatible Python wheel for that platform. Intel macOS source builds
require a compatible ONNX Runtime library supplied explicitly with
ORT_DYLIB_PATH.
Note
The default build profile targets CPU execution. When installing from source, the build backend automatically discovers a compatible ONNX Runtime. If
ORT_DYLIB_PATHis set, it is used directly; otherwise, the build backend locates (or provisions, in the isolated build environment) a compatible ONNX Runtime, validates compatibility with ONNX Runtime 1.28.x / C API level 27, and configures Cargo accordingly.
If you also want the Python ONNX Runtime package installed into your application environment, install the CPU extra:
pip install "fast-lightonocr[cpu]"
CUDA packaging is available through a separate build profile, although CUDA execution is not yet fully supported:
BUILD_PROFILE=cuda pip install "fast-lightonocr[cuda]"
🚀 Quick Start
from fast_lightonocr import LightOnOCR
model = LightOnOCR.from_pretrained(
"onnx-community/LightOnOCR-2-1B-ONNX",
)
result = model.process("receipt.jpg")
The first call downloads the required model files from Hugging Face and caches them locally.
📄 OCR Results
The raw model output is available through result.text.
print(result.text)
The Python bindings also expose a parsed document representation that extracts embedded HTML tables while preserving the original document structure.
print(result.document)
Tables can be accessed directly:
for table in result.tables:
print(table.text_rows)
📋 Table Rendering
By default, tables are rendered using ASCII borders.
result = model.process(
"receipt.jpg",
table_format="grid",
)
Markdown tables are also supported.
result = model.process(
"receipt.jpg",
table_format="github",
)
Any table format supported by tabulate may be used.
⚙️ Model Presets
from_pretrained() supports three ONNX model presets.
model = LightOnOCR.from_pretrained(
"onnx-community/LightOnOCR-2-1B-ONNX",
preset="q4",
)
Available presets:
defaultfp16q4
The generation length can be overridden:
model = LightOnOCR.from_pretrained(
"...",
max_new_tokens=1024,
)
🛠 Development
Install the project with Poetry:
poetry install --with dev
Install the extension in editable mode:
maturin develop --release --features load-dynamic
Build a wheel:
pip wheel . --wheel-dir dist
Packaged builds use the cpu build profile by default, which does not enable
any Cargo features. The Python build backend locates ONNX Runtime from
ORT_DYLIB_PATH or from the Python onnxruntime package it installs into the
isolated build environment during source builds, and validates ONNX Runtime
1.28.x compatibility, including C API level 27.
The load-dynamic feature is intended for local development only. When using
dynamic ONNX Runtime loading, set:
export ORT_DYLIB_PATH=/path/to/libonnxruntime
The CUDA build profile is wired for future provider support:
BUILD_PROFILE=cuda pip install ".[cuda]"
🙏 Acknowledgements
This package wraps the native Rust Fast LightOnOCR inference engine and uses the open-weight LightOnOCR model released by Baidu.
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 Distributions
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 fast_lightonocr-0.1.0.tar.gz.
File metadata
- Download URL: fast_lightonocr-0.1.0.tar.gz
- Upload date:
- Size: 110.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
86b2e179725e7d4727af28b05af50cdfd350c423609f2e72d5bcd3e9e119ffee
|
|
| MD5 |
9d35cbbd4225cf476d12438413f947f5
|
|
| BLAKE2b-256 |
e9a0147d8d7743d3431d1c0c49e47cf6133b5089658660ca52b9730ecb824e2e
|
Provenance
The following attestation bundles were made for fast_lightonocr-0.1.0.tar.gz:
Publisher:
release.yml on talmago/fast-lightonocr
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fast_lightonocr-0.1.0.tar.gz -
Subject digest:
86b2e179725e7d4727af28b05af50cdfd350c423609f2e72d5bcd3e9e119ffee - Sigstore transparency entry: 2334728441
- Sigstore integration time:
-
Permalink:
talmago/fast-lightonocr@754177a55cc0bd0a0a333b181c7ea9be912877b0 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/talmago
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@754177a55cc0bd0a0a333b181c7ea9be912877b0 -
Trigger Event:
push
-
Statement type:
File details
Details for the file fast_lightonocr-0.1.0-cp39-abi3-manylinux_2_28_x86_64.whl.
File metadata
- Download URL: fast_lightonocr-0.1.0-cp39-abi3-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 12.3 MB
- Tags: CPython 3.9+, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
df68ab0cb582213c8e99cff148d360d75d11e790e0a3ebcab4b879e8c946aa5d
|
|
| MD5 |
d89a70f56001ce2637132f6bdb4dc95b
|
|
| BLAKE2b-256 |
3212f31a143e64b02b119073bfa73e9b0c468ccd3ad1209588c9c740c987c23f
|
Provenance
The following attestation bundles were made for fast_lightonocr-0.1.0-cp39-abi3-manylinux_2_28_x86_64.whl:
Publisher:
release.yml on talmago/fast-lightonocr
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fast_lightonocr-0.1.0-cp39-abi3-manylinux_2_28_x86_64.whl -
Subject digest:
df68ab0cb582213c8e99cff148d360d75d11e790e0a3ebcab4b879e8c946aa5d - Sigstore transparency entry: 2334728455
- Sigstore integration time:
-
Permalink:
talmago/fast-lightonocr@754177a55cc0bd0a0a333b181c7ea9be912877b0 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/talmago
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@754177a55cc0bd0a0a333b181c7ea9be912877b0 -
Trigger Event:
push
-
Statement type:
File details
Details for the file fast_lightonocr-0.1.0-cp39-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: fast_lightonocr-0.1.0-cp39-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 2.7 MB
- Tags: CPython 3.9+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3439b292bc27705037e0ea8c9a056dabefc93c7ce6c502dd4967141db2f33eb4
|
|
| MD5 |
efacc8e047fbf2f93ba101b2bb6a0670
|
|
| BLAKE2b-256 |
65b50d29aa21b04a3e3898622b3ce96633f4734b837e4926e978c48826f6d8c7
|
Provenance
The following attestation bundles were made for fast_lightonocr-0.1.0-cp39-abi3-macosx_11_0_arm64.whl:
Publisher:
release.yml on talmago/fast-lightonocr
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fast_lightonocr-0.1.0-cp39-abi3-macosx_11_0_arm64.whl -
Subject digest:
3439b292bc27705037e0ea8c9a056dabefc93c7ce6c502dd4967141db2f33eb4 - Sigstore transparency entry: 2334728467
- Sigstore integration time:
-
Permalink:
talmago/fast-lightonocr@754177a55cc0bd0a0a333b181c7ea9be912877b0 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/talmago
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@754177a55cc0bd0a0a333b181c7ea9be912877b0 -
Trigger Event:
push
-
Statement type: