Skip to main content

ocrbychamod

Extract text from PNG and JPEG images using swappable OCR engines. Tesseract is the first built-in engine.

Prerequisites

The Tesseract OCR program must be installed on your machine. pip cannot install it for you.

  • Windows: install the UB Mannheim build, then add C:\Program Files\Tesseract-OCR to your PATH
  • macOS: brew install tesseract
  • Ubuntu/Debian: sudo apt-get install tesseract-ocr

Check it works:

tesseract --version

Installation

pip install "ocrbychamod[tesseract]"

Usage

from ocrbychamod import extract_text

text = extract_text("receipt.png")
print(text)

If Tesseract is not on your PATH, or you want another language:

text = extract_text(
    "receipt.jpg",
    engine="tesseract",
    lang="eng",
    tesseract_cmd=r"C:\Program Files\Tesseract-OCR\tesseract.exe",
)

Supported formats: .png, .jpg, .jpeg.

Swappable engines

The core never depends on a specific OCR tool. Every engine implements the OCREngine interface, so you can plug in your own:

from ocrbychamod import OCREngine, extract_text, register_engine

class MyEngine(OCREngine):
    name = "my-engine"

    def extract_text(self, image):
        # image is a PIL.Image.Image
        return "recognized text"

# Option 1: pass an instance directly
extract_text("img.png", engine=MyEngine())

# Option 2: register it and select it by name
register_engine("my-engine", MyEngine)
extract_text("img.png", engine="my-engine")

List the registered engines:

from ocrbychamod import available_engines
print(available_engines())  # ['tesseract', ...]

Development

git clone https://github.com/Chamodpw2000/ocr_extract_pip.git
cd ocrbychamod
python -m venv .venv
.venv\Scripts\activate
pip install -e ".[tesseract]" pytest
pytest

License

MIT. See LICENSE.

Metadata

Release files for ocrbychamod 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ocrbychamod 0.2.0
File Size Uploaded
ocrbychamod-0.2.0.tar.gz 9.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ocrbychamod 0.2.0
File Interpreter ABI Platform
ocrbychamod-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 18.2 kB

Release files / ocrbychamod-0.2.0.tar.gz

Download URL ocrbychamod-0.2.0.tar.gz
Size 9.3 kB
Tags Source
SHA-256 checksum
How to use checksums
04973808775f26b885c078637f673cc1dbed75b88b13001966aa9e4b318d36e5
BLAKE2b-256 checksum
How to use checksums
65010afe56c207da4a48efd13cedfe1dabc1a7112d128979bcb6f65cc193f77f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.15

Release files / ocrbychamod-0.2.0-py3-none-any.whl

Download URL ocrbychamod-0.2.0-py3-none-any.whl
Size 8.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e17c29945d9ee621c505dbd3a4aaa3d21b06dd1df3f59905f81162004b73d69c
BLAKE2b-256 checksum
How to use checksums
60bfaf333b374eb3903d1b856f4720132b150118b4bbfdfa63aafe26786db0bb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.15

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page