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.11.tar.gz (82.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.11-py3-none-any.whl (87.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: kiri_ocr-0.2.11.tar.gz
  • Upload date:
  • Size: 82.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.11.tar.gz
Algorithm Hash digest
SHA256 60d7476739966db8a2dfc6faafd979b769335cb9a03b687ee3bdf153d33fa3b2
MD5 d3afa75fe0d6553ff17d395603faa124
BLAKE2b-256 78a3b9b13717f42fea359e967322df3b9b8e6de89d33ef5b54c241c329a2598d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kiri_ocr-0.2.11-py3-none-any.whl
  • Upload date:
  • Size: 87.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.11-py3-none-any.whl
Algorithm Hash digest
SHA256 95535d59d6b5a74826b9cb9d6793c02ce2592997858c62afee45d818f4983926
MD5 9aaf4ded8297616592b01d5168422a9c
BLAKE2b-256 7871d80e78412e5afefb0f63cc0775d27308b73dbacd7224c78030f2bba1aa6f

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