Skip to main content

Layered OCR workhorse: extract text from scanned PDFs and images (tesseract, PyMuPDF, easyocr, paddleocr, vision-api).

Project description

pro-ledin-ocr

skills.sh

Layered OCR workhorse: extract text from scanned PDFs and images (PNG/JPG/TIFF/ HEIC/WEBP) using a tiered engine stack. The baseline path (poppler + tesseract) needs zero extra Python installs; heavier engines are opt-in extras.

  • Import name: pro.ledin.ocr
  • Console scripts: ocr, ocr-probe, peepshow-sink-ocr
  • PyPI: pro-ledin-ocr

Install

pip install pro-ledin-ocr            # baseline
pip install "pro-ledin-ocr[vision]"  # + OpenAI-compatible vision-api engine
pip install "pro-ledin-ocr[all]"     # + pymupdf, opencv, easyocr, paddleocr

System binaries required for the local path: poppler (pdftoppm, pdftotext, pdfinfo) and tesseract (with language packs).

brew install poppler tesseract tesseract-lang      # macOS
sudo apt install poppler-utils tesseract-ocr-all   # Debian/Ubuntu

CLI

ocr-probe myfile.pdf                          # triage: does it need OCR?
ocr myfile.pdf --format all                   # md + txt + json
ocr scan.png --format md
ocr russian_doc.pdf --lang rus+eng --format md
ocr scan.pdf --preprocess full                # deskew + denoise
ocr slides.pdf --engine vision --pages 9,12   # hand pages to a multimodal agent
ocr table.png --engine vision \
  --vision-prompt "Extract only table rows and preserve empty cells"
ocr slides.pdf --engine vision-api \
  --vision-api-url https://api.example.com/v1 \
  --vision-api-key "$KEY" --vision-model my-vision-model \
  --vision-prompt-file prompts/faithful-ocr.txt

See ocr --help for the full flag reference.

Peepshow sink

peepshow-sink-ocr reads peepshow's JSON payload from stdin, recognizes each primary frame, and atomically writes <outputDir>/ocr.json:

peepshow video.mp4 --sink ocr
peepshow video.mp4 \
  --sink-cmd 'peepshow-sink-ocr --engine tesseract --lang rus+eng'

No extra Python dependency is required for the sink interface. Peepshow only needs the installed peepshow-sink-ocr executable on PATH. The default local engine still requires Tesseract; vision-api requires pip install "pro-ledin-ocr[vision]".

Configure named sink runs through PEEPSHOW_SINK_OCR_* variables:

export PEEPSHOW_SINK_OCR_ENGINE=vision-api
export PEEPSHOW_SINK_OCR_VISION_API_URL=https://api.example.com/v1
export PEEPSHOW_SINK_OCR_VISION_API_KEY="$KEY"
export PEEPSHOW_SINK_OCR_VISION_MODEL=my-vision-model
export PEEPSHOW_SINK_OCR_TIMEOUT=120
peepshow video.mp4 --sink ocr

The sink never changes peepshow's manifest or frames and prints no OCR content to stdout. vision-api sends frame images to the configured external endpoint. Protect both API credentials and output directories containing recognized text.

Library

from pro.ledin import ocr

pages = ocr.recognize(
    "scan.pdf",
    ocr.RecognizeOptions(
        engine="vision-api",
        vision_api_key="key",
        vision_model="model",
        vision_prompt="Preserve checkbox states and labels.",
    ),
)
markdown = ocr.to_markdown(pages, "scan.pdf")

recognize() never calls sys.exit(); catch ocr.OcrError for recoverable failures (unsupported input, missing binaries/packages, vision-api config).

Engine tiers

Tier Engine Best for Cost
0 pdftotext / PyMuPDF Real text layers Free, instant
1 tesseract (default) Clean scans, typed text, 160+ languages Free
2 easyocr Handwriting, degraded scans Free, heavy
2.5 paddleocr CJK, multilingual, angled text Free
3 vision (agent reads PNGs) Tables, charts, complex layouts Agent tokens
3.5 vision-api (OpenAI-compatible) Headless batch, complex layouts API cost

Full docs: skills/ocr/SKILL.md, skills/ocr/references/engines.md, skills/ocr/references/peepshow-sinks.md, and skills/ocr/references/troubleshooting.md.

Development

uv sync --extra dev
uv run --extra dev pytest
uv build

License

MIT

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

pro_ledin_ocr-0.3.0.tar.gz (46.8 kB view details)

Uploaded Source

Built Distribution

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

pro_ledin_ocr-0.3.0-py3-none-any.whl (30.0 kB view details)

Uploaded Python 3

File details

Details for the file pro_ledin_ocr-0.3.0.tar.gz.

File metadata

  • Download URL: pro_ledin_ocr-0.3.0.tar.gz
  • Upload date:
  • Size: 46.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for pro_ledin_ocr-0.3.0.tar.gz
Algorithm Hash digest
SHA256 27fc6ef0c0775a04f997f32ab2fae75ce013a967f07e13c44d3acbc686a04fb3
MD5 cc0826d04df842e38a5138321518d9f1
BLAKE2b-256 3b5bd9ff4653dfeef0c9ef893521c5e998ff778bec44e9ae16687cceae2853c3

See more details on using hashes here.

File details

Details for the file pro_ledin_ocr-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: pro_ledin_ocr-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 30.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for pro_ledin_ocr-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ba46c9be053e7addce232330b65370ca3a817ac4abbdba80ce805125e917a882
MD5 76689401e4c85d41ebf0cdf07f85736f
BLAKE2b-256 d18767edd2268070d9393941ed66a0ae6a3a9adb13a805e61a865aab49370703

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