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.1.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.1.0
File Size Uploaded
ocrbychamod-0.1.0.tar.gz 4.8 kB Details

Built distribution (wheel)

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

Total release size: 10.1 kB

Release files / ocrbychamod-0.1.0.tar.gz

Download URL ocrbychamod-0.1.0.tar.gz
Size 4.8 kB
Tags Source
SHA-256 checksum
How to use checksums
6b8091d05f83228d0030c1d7c62b6d2115e8f86d61dc02961eda0c8b4d2c1a21
BLAKE2b-256 checksum
How to use checksums
546d135cd485258f544b42c5854fe67f04629761b0103d1ab28473167bb2eaeb
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.1.0-py3-none-any.whl

Download URL ocrbychamod-0.1.0-py3-none-any.whl
Size 5.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fd149c8b11d257a63d915673143d9478922ee70dfc336867f14b8232fe6e7138
BLAKE2b-256 checksum
How to use checksums
249ceb2d6a5230d465ad333947ffde7d73ce0d8f0e277f58ae85092cf1cb77ef
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

0.2.0

2 release files

This release

0.1.0 This release

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