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.14.tar.gz (84.3 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.14-py3-none-any.whl (89.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: kiri_ocr-0.2.14.tar.gz
  • Upload date:
  • Size: 84.3 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.14.tar.gz
Algorithm Hash digest
SHA256 06b0346fead76299c41bf67260511db224ad45d9c454cea6068d6be33dd099d4
MD5 6236ea6d251018b44125b55d1718cf38
BLAKE2b-256 34258767c05b362830bfa6791288d176104c066ffd1a696b3eda2d79fb6f16a7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kiri_ocr-0.2.14-py3-none-any.whl
  • Upload date:
  • Size: 89.7 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.14-py3-none-any.whl
Algorithm Hash digest
SHA256 ef1289a104bc4db623a14b6e912fdeeaf95718a6d0e91ec92ef6f4397c29d1d3
MD5 e91413c7281430f1d42758f230d2052c
BLAKE2b-256 5be238abc89a26252101eb5973dd63b678e40e869a5ad0e211fbb971d2471125

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