pydocai
Extract text from PDF documents using pypdfium2 with automatic OCR fallback via pytesseract.
Features
- Fast native text extraction using pypdfium2 (Apache 2.0 licensed)
- Automatic OCR fallback for scanned documents using pytesseract
- Smart detection of sparse/scanned PDFs that need OCR
- Memory-efficient processing with lazy imports and temporary file handling
- Page limit to prevent processing extremely large documents (default: 15 pages)
Installation
pip install pydocai
System Dependencies
This package requires Tesseract OCR to be installed on your system for the OCR fallback feature:
macOS:
brew install tesseract
Ubuntu/Debian:
sudo apt-get install tesseract-ocr
Windows: Download and install from: https://github.com/UB-Mannheim/tesseract/wiki
Usage
from pydocai import extract_pdf_text
# Extract text and save to file
success = extract_pdf_text("document.pdf", "output.txt")
# Or let it auto-generate the output filename
success = extract_pdf_text("document.pdf") # Creates document_extracted.txt
How it works
- First attempts native text extraction using pypdfium2
- Checks if extracted text has sufficient content (>= 5 lines per page)
- If content is sparse (likely a scanned document), falls back to OCR
- Saves extracted text to the specified output file
Configuration
You can import and check the default configuration values:
from pydocai import (
OCR_DPI, # DPI for OCR rendering (default: 100)
MAX_PDF_PAGES, # Maximum pages to process (default: 15)
MIN_LINES_PER_PAGE # Minimum lines to consider page valid (default: 5)
)
Development
# Clone the repository
git clone https://github.com/catherine/pydocai.git
cd pydocai
# Install in development mode with dev dependencies
pip install -e ".[dev]"
# Run tests
pytest
License
Apache License 2.0 - see LICENSE for details.
Metadata
Release files for pydocai 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| pydocai-0.1.0.tar.gz | 11.7 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pydocai-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 22.1 kB
Release files / pydocai-0.1.0.tar.gz
| Download URL | pydocai-0.1.0.tar.gz |
|---|---|
| Size | 11.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6cb8467fba356c5ff66b2e51dd108b9b4179a4b7d968712ab9b1f37f5f008cb4
|
|
BLAKE2b-256 checksum How to use checksums |
f0e027c397ccbcd537aa2a72c42f1c2bc295f14f65535e36bd571cce3337d673
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.17
|
Release files / pydocai-0.1.0-py3-none-any.whl
| Download URL | pydocai-0.1.0-py3-none-any.whl |
|---|---|
| Size | 10.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fbb3f212eae9a399d8e735500a8117a73c286c212e2ac9efd78421c939ce1e1d
|
|
BLAKE2b-256 checksum How to use checksums |
055da5f05d409cac95ae7a94f5a89a473eb919a252dea3b76f13ad732780213a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.17
|
Security for pydocai 0.1.0
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.