Skip to main content

stache-tools-ocr

OCR support for stache-tools CLI. Automatically detects and processes scanned PDFs and images using Tesseract.

Quick Start

# 1. Install system dependencies (one-time)
# Ubuntu/Debian:
sudo apt install ocrmypdf tesseract-ocr

# macOS:
brew install ocrmypdf

# Windows:
choco install ocrmypdf

# 2. Install Python package
pip install stache-tools-ocr

# 3. Use it automatically
stache ingest scanned.pdf
stache ingest *.jpg *.png

That's it! OCR loaders automatically register with the CLI.

Architecture

stache-tools-ocr is a thin adapter that wraps stache-ai-ocr to provide OCR capabilities for the stache-tools CLI.

Design: This package adapts stache-ai-ocr's file path interface to stache-tools' BinaryIO interface, enabling seamless integration with the stache ingest command.

Benefits:

  • Single source of truth for OCR logic (in stache-ai-ocr)
  • Simplified installation (dependencies pulled automatically)
  • Rich metadata from OCR operations
  • Works with all stache-tools features (--parallel, --dry-run, --namespace)

Installation

Python Package

pip install stache-tools-ocr

This automatically installs stache-ai-ocr>=0.2.0 and all required dependencies (pdfplumber, ocrmypdf, tesseract bindings).

System Dependencies

You still need to install Tesseract OCR separately:

Ubuntu/Debian:

sudo apt install ocrmypdf tesseract-ocr

macOS:

brew install ocrmypdf

Windows:

choco install ocrmypdf

Development

cd stache-tools-ocr
pip install -e .

Usage

Once installed, OCR loaders automatically register and activate:

# Scanned PDFs automatically use OCR
stache ingest scanned.pdf

# Image OCR (requires pytesseract)
stache ingest photo.jpg screenshot.png

# Works with all CLI features
stache ingest *.pdf *.jpg --parallel 4 --namespace books

# Dry run to preview processing
stache ingest scanned.pdf image.jpg --dry-run

How It Works

PDF Loader

  • Priority: 10 (overrides BasicPDFLoader at priority 0)
  • Smart Detection: Attempts text extraction first, falls back to OCR if document appears scanned
  • Method: ocrmypdf CLI tool
  • Metadata: Provides ocr_used, ocr_failed, page_count, chars_per_page, and ocr_method
  • Graceful Fallback: Returns empty text with warning if ocrmypdf not installed
  • Thread Safe: Works with --parallel mode

Image Loader

  • Priority: 5 (standard)
  • Formats: JPG, JPEG, PNG, TIFF, TIF, BMP, GIF
  • Method: pytesseract (Tesseract OCR)
  • Metadata: Provides ocr_used, ocr_method, image_format, image_size
  • Graceful Fallback: Returns empty text with warning if pytesseract not installed
  • Thread Safe: Works with --parallel mode

OCR Behavior

For details on OCR heuristics, timeout configuration, and complete metadata fields, see the stache-ai-ocr documentation.

Configuration

Environment Variables:

Variable Default Purpose
STACHE_OCR_TIMEOUT 300 OCR timeout in seconds

Override Loaders:

# Force use of OCR loader
export STACHE_LOADER_PDF=OcrPdfLoader
stache ingest document.pdf

# Use basic loader (skip OCR)
export STACHE_LOADER_PDF=BasicPDFLoader
stache ingest document.pdf

System Requirements

  • Python: 3.10+
  • ocrmypdf: System binary (for PDF OCR)
  • tesseract-ocr: System binary (for image OCR)
  • pdfplumber, pytesseract, pillow: Installed via pip

Cost & Performance

  • Free - no API costs
  • Offline - works without internet
  • Speed: ~1-3 seconds per page (CPU-bound)
  • Quality: 99% accuracy for clean scans, 70-90% for poor quality

Troubleshooting

"ocrmypdf not found" error:

# Verify installation
which ocrmypdf
tesseract --version

# Reinstall if needed
sudo apt install --reinstall ocrmypdf tesseract-ocr

Tesseract not found (image OCR):

# Install tesseract
# Ubuntu/Debian:
sudo apt install tesseract-ocr

# macOS:
brew install tesseract

# Windows:
choco install tesseract

OCR timeout on large PDFs:

# Increase timeout to 10 minutes
export STACHE_OCR_TIMEOUT=600
stache ingest large-document.pdf

Poor OCR quality:

  • Ensure scan is at least 300 DPI
  • Try pre-processing with image tools (deskew, denoise)
  • See stache-ai-ocr docs for advanced OCR tuning

License

MIT

Metadata

Release files for stache-tools-ocr 0.1.1

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

Source distribution (sdist)

Source distribution for stache-tools-ocr 0.1.1
File Size Uploaded Provenance Actions
stache_tools_ocr-0.1.1.tar.gz 11.6 kB Without provenance Details for stache_tools_ocr-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for stache-tools-ocr 0.1.1
File Interpreter ABI Platform Actions
stache_tools_ocr-0.1.1-py3-none-any.whl Python 3 none any Details for stache_tools_ocr-0.1.1-py3-none-any.whl

Total release size: 17.8 kB

Release files / stache_tools_ocr-0.1.1.tar.gz

Download URL stache_tools_ocr-0.1.1.tar.gz
Size 11.6 kB
Tags Source
SHA-256 checksum
How to use checksums
3a3aa93b2d214b917988e8c3bad758016f87c09e948b51f252933d5097ddc601
BLAKE2b-256 checksum
How to use checksums
06f71822963ffaf6add6335b9edb01b1168fee23411dfb551448ca5351d6eed7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release files / stache_tools_ocr-0.1.1-py3-none-any.whl

Download URL stache_tools_ocr-0.1.1-py3-none-any.whl
Size 6.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
af75c8adfb4f57ab32a50b846dc744cbc28db12a32152183b7125c74155a056e
BLAKE2b-256 checksum
How to use checksums
b68bd43c9ae552d5e056161e6b2960c08e9ae792d7e4ef0512ec494315b73590
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Security for stache-tools-ocr 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

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