Production-ready text extraction for PDFs and images with a quality-aware fallback pipeline.
Built for agent workflows first: one package gives you a CLI, Python API, and MCP server.
Most extractors are good at one thing: either fast digital PDFs, or OCR-heavy scans. This project does both by routing each file through the right backend and escalating only when quality drops.
- Fast path for dense digital PDFs
- Automatic fallback for low-quality/garbled text
- OCR path for scanned PDFs and images
- MCP tools for VS Code, Claude, and other MCP clients
- Clean markdown output suitable for LLM context ingestion
pip install text-extractor-lightweightOptional extras:
# Preferred backend for fast and robust PDF text extraction
pip install "text-extractor-lightweight[fast]"
# OCR support (images + scanned PDFs)
pip install "text-extractor-lightweight[ocr]"
# Advanced layout fallback
pip install "text-extractor-lightweight[docling]"
# Everything
pip install "text-extractor-lightweight[all]"OCR system dependencies:
- Tesseract OCR: https://github.com/tesseract-ocr/tesseract
- Poppler tools (
pdftoppm) for PDF-to-image conversion
Windows setup:
winget install --id tesseract-ocr.tesseract -e
winget install --id oschwartz10612.Poppler -e# Full file extraction
text-extractor ./docs/report.pdf
# Page-range extraction
text-extractor ./docs/report.pdf --pages 2-6
# Metadata and extraction diagnostics
text-extractor ./docs/report.pdf --info
# Show routing decision only
text-extractor ./docs/report.pdf --strategyflowchart TD
A[Input file] --> B{File type}
B -->|Image| C[Tesseract OCR]
B -->|PDF| D[Quick quality preflight]
D -->|Sparse text| E[pdf2image + OCR]
D -->|Dense text| F[pymupdf preferred]
F -->|Low quality output| G[pdfplumber]
G -->|Still low quality| H[docling]
H -->|Still low quality| E
C --> Z[Markdown output]
E --> Z
F --> Z
G -->
8027
Z
H --> Z
Run directly:
uvx --from text-extractor-lightweight text-extractor-mcpVS Code MCP config (.vscode/mcp.json):
{
"servers": {
"text-extractor": {
"command": "python",
"args": ["-m", "text_extractor.mcp_server"]
}
}
}Use uvx for ad-hoc manual runs, but prefer python -m text_extractor.mcp_server in MCP stdio clients to avoid installer output mixing into the protocol stream.
Claude Code:
claude mcp add text-extractor -- uvx --from text-extractor-lightweight text-extractor-mcpExposed tools:
extract_text_from_file: Extract full text from PDF/image to markdownextract_text_pages: Extract a page range from PDFget_document_info: Return metadata, quality score, token estimate
from text_extractor.extract import extract_text, extract_raw
markdown = extract_text("report.pdf")
print(markdown[:500])
result = extract_raw("report.pdf")
print(result.backend_used, result.total_pages, result.estimated_tokens)This repository now includes a runnable showcase pipeline in examples/showcase_pipeline.py.
It demonstrates how to:
- Detect strategy before extraction
- Extract and score text quality
- Save markdown output and machine-readable report JSON
Run it:
python examples/showcase_pipeline.py /absolute/path/to/document.pdfCustom output directory:
python examples/showcase_pipeline.py /absolute/path/to/document.pdf --out showcase-output- If
text-extractoris not found, ensure your Python Scripts directory is on PATH. - For MCP stdio mode, only an MCP client should communicate with the server stdin/stdout.
- If OCR never triggers for scanned docs, verify Tesseract and Poppler are installed and discoverable.
py -m build
py -m twine check dist/*
py -m twine upload --repository testpypi dist/*
py -m twine upload dist/*For full release steps, see RELEASE_CHECKLIST.md.
MIT