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 md,json               # multiple formats to stdout
ocr myfile.pdf --format md,txt,json --out results/  # one file per format
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.

--format accepts md, txt, json, or comma-separated combinations. all remains shorthand for md,txt,json. With multiple formats, --out is treated as a directory and files are named from the input stem. Multiple inputs also use directory mode; duplicate input stems are rejected to prevent overwrites. JSON output for multiple inputs requires --out, and --searchable-pdf accepts only one input.

--json-report was removed in 0.4.0. Use --format json --out report.json for JSON-only output or --format md,json --out results/ for multiple files. One invocation no longer mixes a stdout format with an independently named JSON sidecar.

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.4.0.tar.gz (49.2 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.4.0-py3-none-any.whl (30.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pro_ledin_ocr-0.4.0.tar.gz
  • Upload date:
  • Size: 49.2 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.4.0.tar.gz
Algorithm Hash digest
SHA256 5ab31e56f8dbca311e6fb222db3f06ffe316570674c741d09ef9fbdbe9fa391d
MD5 0abdd75f24cf4ec23bcea5f724281b4b
BLAKE2b-256 905ac324d2c4cc17cba2ca31dbf38e5da88553c5a93d8b3d9e8b595bb5aab5d0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pro_ledin_ocr-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 30.8 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.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 68bc84163a6b1b24f4971f0e714d6c439c0089b89db15ba63a81717f91162069
MD5 03ffd9f027fad3c67159d4994e3e485f
BLAKE2b-256 52d65db5ee9d5dcb3908512425065dfd5b7f2a675f25af4d8df1499bd5fa45bd

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