Skip to main content

A lightweight OCR library for Khmer and English documents

Project description

Kiri OCR 📄

PyPI version License Python Versions Downloads Hugging Face Model Hugging Face Spaces

Kiri OCR is a lightweight OCR library for English and Khmer documents. It provides document-level text detection, recognition, and rendering capabilities.

🚀 Try the Live Demo | 📚 Full Documentation

Kiri OCR

✨ Key Features

  • High Accuracy: Transformer model with hybrid CTC + attention decoder
  • Bi-lingual: Native support for English and Khmer (and mixed text)
  • Document Processing: Automatic text line and word detection
  • Streaming: Real-time character-by-character output (like LLM streaming)
  • Easy to Use: Simple Python API and CLI

📦 Installation

pip install kiri-ocr

💻 Quick Start

CLI Tool

kiri-ocr document.jpg

Python API

from kiri_ocr import OCR

# Initialize (auto-downloads from Hugging Face)
ocr = OCR()

# Extract text from document
text, results = ocr.extract_text('document.jpg')
print(text)

# Get detailed box-by-box results
for line in results:
    print(f"{line['text']} (confidence: {line['confidence']:.1%})")

Decoding Methods

Choose the decoding method based on your speed/quality tradeoff:

# Fast (CTC) - Fastest, good for batch processing
ocr = OCR(decode_method="fast")

# Accurate (Decoder) - Balanced speed and quality (default)
ocr = OCR(decode_method="accurate")

# Beam Search - Best quality, slowest
ocr = OCR(decode_method="beam")

Streaming Recognition

Get character-by-character output like LLM streaming:

from kiri_ocr import OCR

ocr = OCR(decode_method="accurate")

# Stream characters as they're decoded
for chunk in ocr.extract_text_stream_chars('document.jpg'):
    print(chunk['token'], end='', flush=True)
    if chunk['document_finished']:
        print()  # Done!

📚 Documentation

Full documentation is available on the Wiki:

📊 Benchmark

Results on synthetic test images (10 popular fonts):

Benchmark Graph

📁 Project Structure

kiri_ocr/
├── core.py               # OCR class
├── model.py              # Transformer model
├── training.py           # Training code
├── cli.py                # Command-line interface
└── detector/             # Text detection
    ├── db/               # DB detector
    └── craft/            # CRAFT detector

☕ Support

If you find this project useful:

⚖️ License

Apache License 2.0

📚 Citation

@software{kiri_ocr,
  author = {mrrtmob},
  title = {Kiri OCR: Lightweight Khmer and English OCR},
  year = {2026},
  url = {https://github.com/mrrtmob/kiri-ocr}
}

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

kiri_ocr-0.2.12.tar.gz (83.5 kB view details)

Uploaded Source

Built Distribution

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

kiri_ocr-0.2.12-py3-none-any.whl (88.8 kB view details)

Uploaded Python 3

File details

Details for the file kiri_ocr-0.2.12.tar.gz.

File metadata

  • Download URL: kiri_ocr-0.2.12.tar.gz
  • Upload date:
  • Size: 83.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for kiri_ocr-0.2.12.tar.gz
Algorithm Hash digest
SHA256 bd4ffbd844c43d1ecdf9bf8ce861855f357958dc9decb556f473a525f4e82461
MD5 f122dc0dac0a3b9bed0dc49434c264ca
BLAKE2b-256 272734348b0c2f109a30a078fa89a3b03d6db30eb1c4f54246af0bdd4ad4886e

See more details on using hashes here.

File details

Details for the file kiri_ocr-0.2.12-py3-none-any.whl.

File metadata

  • Download URL: kiri_ocr-0.2.12-py3-none-any.whl
  • Upload date:
  • Size: 88.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for kiri_ocr-0.2.12-py3-none-any.whl
Algorithm Hash digest
SHA256 9a6f3c66171d86394b076db0b095e4362d11d18b921082d215c60b87bb701284
MD5 1aaa2cc1e55f0ee4fbf3b99a635ebaf1
BLAKE2b-256 8225882971a3bdf14eb76ac4ce87b2863be51aa2462a773e3ea06ef01e86580c

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