pyocr-toolkit 0.4.0__tar.gz → 0.6.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/.env.example +27 -0
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/CHANGELOG.md +63 -0
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/PKG-INFO +87 -13
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/README.md +62 -10
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/pyproject.toml +15 -4
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/src/pyocr_toolkit/__init__.py +1 -1
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/src/pyocr_toolkit/api.py +174 -45
- pyocr_toolkit-0.6.0/src/pyocr_toolkit/brands.py +56 -0
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/src/pyocr_toolkit/cli.py +110 -20
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/src/pyocr_toolkit/config.py +52 -0
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/src/pyocr_toolkit/credentials.py +23 -8
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/src/pyocr_toolkit/documents.py +97 -23
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/src/pyocr_toolkit/env.example +27 -0
- pyocr_toolkit-0.6.0/src/pyocr_toolkit/export.py +160 -0
- pyocr_toolkit-0.6.0/src/pyocr_toolkit/extract.py +892 -0
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/src/pyocr_toolkit/jobs.py +26 -8
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/src/pyocr_toolkit/llm/__init__.py +8 -0
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/src/pyocr_toolkit/llm/anthropic_provider.py +44 -3
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/src/pyocr_toolkit/llm/base.py +24 -16
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/src/pyocr_toolkit/llm/gemini_provider.py +6 -0
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/src/pyocr_toolkit/llm/openai_provider.py +22 -1
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/src/pyocr_toolkit/llm/prompts.py +71 -0
- pyocr_toolkit-0.6.0/src/pyocr_toolkit/ocr/__init__.py +34 -0
- pyocr_toolkit-0.6.0/src/pyocr_toolkit/ocr/base.py +271 -0
- pyocr_toolkit-0.6.0/src/pyocr_toolkit/ocr/cloud.py +301 -0
- pyocr_toolkit-0.6.0/src/pyocr_toolkit/ocr/local.py +188 -0
- pyocr_toolkit-0.6.0/src/pyocr_toolkit/ocr/tesseract.py +71 -0
- pyocr_toolkit-0.6.0/src/pyocr_toolkit/pdftext.py +217 -0
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/src/pyocr_toolkit/service.py +254 -30
- pyocr_toolkit-0.6.0/src/pyocr_toolkit/static/common.js +1176 -0
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/src/pyocr_toolkit/static/compare.js +5 -2
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/src/pyocr_toolkit/static/document.js +34 -10
- pyocr_toolkit-0.6.0/src/pyocr_toolkit/static/logos/README.md +12 -0
- pyocr_toolkit-0.6.0/src/pyocr_toolkit/static/logos/claude.svg +1 -0
- pyocr_toolkit-0.6.0/src/pyocr_toolkit/static/logos/googlecloud.svg +1 -0
- pyocr_toolkit-0.6.0/src/pyocr_toolkit/static/logos/googlegemini.svg +1 -0
- pyocr_toolkit-0.6.0/src/pyocr_toolkit/static/logos/mistralai.svg +1 -0
- pyocr_toolkit-0.6.0/src/pyocr_toolkit/static/logos/paddlepaddle.svg +1 -0
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/src/pyocr_toolkit/static/providers.js +29 -2
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/src/pyocr_toolkit/static/reader.js +4 -1
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/src/pyocr_toolkit/static/search.js +6 -2
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/src/pyocr_toolkit/static/styles.css +127 -0
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/src/pyocr_toolkit/static/workspace.js +174 -29
- pyocr_toolkit-0.6.0/src/pyocr_toolkit/templates/_brand.html +9 -0
- pyocr_toolkit-0.6.0/src/pyocr_toolkit/templates/_llm_picker.html +64 -0
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/src/pyocr_toolkit/templates/base.html +1 -1
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/src/pyocr_toolkit/templates/document.html +16 -3
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/src/pyocr_toolkit/templates/help.html +86 -7
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/src/pyocr_toolkit/templates/home.html +6 -5
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/src/pyocr_toolkit/templates/providers.html +82 -37
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/src/pyocr_toolkit/templates/workspace.html +17 -4
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/src/pyocr_toolkit/templates/workspace_detail.html +1 -1
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/src/pyocr_toolkit/web.py +6 -3
- pyocr_toolkit-0.6.0/tests/test_extract.py +466 -0
- pyocr_toolkit-0.6.0/tests/test_ocr_engines.py +503 -0
- pyocr_toolkit-0.6.0/tests/test_pdftext.py +140 -0
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/tests/test_providers.py +119 -0
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/tests/test_web.py +59 -1
- pyocr_toolkit-0.4.0/src/pyocr_toolkit/static/common.js +0 -551
- pyocr_toolkit-0.4.0/src/pyocr_toolkit/templates/_llm_picker.html +0 -12
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/.gitignore +0 -0
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/CONTRIBUTING.md +0 -0
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/LICENSE +0 -0
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/hero-video/README.md +0 -0
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/hero-video/src/HeroDemo.tsx +0 -0
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/hero-video/src/Root.tsx +0 -0
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/hero-video/src/assets.d.ts +0 -0
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/hero-video/src/index.ts +0 -0
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/hero-video/src/motion.tsx +0 -0
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/hero-video/src/scenes/CatchScene.tsx +0 -0
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/hero-video/src/scenes/ColdOpenScene.tsx +0 -0
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/hero-video/src/scenes/MeasureScene.tsx +0 -0
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/hero-video/src/scenes/MontageScene.tsx +0 -0
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/hero-video/src/scenes/OutroScene.tsx +0 -0
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/hero-video/src/scenes/ThreeWaysScene.tsx +0 -0
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/hero-video/src/theme.ts +0 -0
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/hero-video/src/ui.tsx +0 -0
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/src/pyocr_toolkit/__main__.py +0 -0
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/src/pyocr_toolkit/compare.py +0 -0
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/src/pyocr_toolkit/llm/catalog.py +0 -0
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/src/pyocr_toolkit/preprocess.py +0 -0
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/src/pyocr_toolkit/search.py +0 -0
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/src/pyocr_toolkit/static/jobs.js +0 -0
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/src/pyocr_toolkit/static/library.js +0 -0
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/src/pyocr_toolkit/static/models.js +0 -0
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/src/pyocr_toolkit/static/workspaces.js +0 -0
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/src/pyocr_toolkit/templates/_doc_card.html +0 -0
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/src/pyocr_toolkit/templates/_doctabs.html +0 -0
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/src/pyocr_toolkit/templates/_icons.html +0 -0
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/src/pyocr_toolkit/templates/compare.html +0 -0
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/src/pyocr_toolkit/templates/error.html +0 -0
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/src/pyocr_toolkit/templates/jobs.html +0 -0
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/src/pyocr_toolkit/templates/library.html +0 -0
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/src/pyocr_toolkit/templates/models.html +0 -0
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/src/pyocr_toolkit/templates/reader.html +0 -0
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/src/pyocr_toolkit/templates/search.html +0 -0
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/src/pyocr_toolkit/templates/workspaces.html +0 -0
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/src/pyocr_toolkit/workspaces.py +0 -0
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/tests/__init__.py +0 -0
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/tests/conftest.py +0 -0
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/tests/test_api.py +0 -0
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/tests/test_batch.py +0 -0
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/tests/test_core.py +0 -0
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/tests/test_makefile.py +0 -0
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/tests/test_models.py +0 -0
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/tests/test_preprocess.py +0 -0
- {pyocr_toolkit-0.4.0 → pyocr_toolkit-0.6.0}/tests/test_workspaces.py +0 -0
|
@@ -35,6 +35,33 @@ GEMINI_API_KEY=
|
|
|
35
35
|
# OPENAI_COMPATIBLE_MODEL=qwen2.5vl:7b
|
|
36
36
|
# OPENAI_COMPATIBLE_API_KEY=
|
|
37
37
|
|
|
38
|
+
# --- Extra OCR engines (Tesseract needs no settings) ------------------------------
|
|
39
|
+
# Local engines need an extra install, e.g. pip install "pyocr-toolkit[easyocr]"
|
|
40
|
+
# (extras: rapidocr, easyocr, paddleocr, doctr, textract). See `pyocr engines`.
|
|
41
|
+
# EASYOCR_LANGUAGES=en # comma-separated, e.g. en,de
|
|
42
|
+
# PADDLEOCR_LANGUAGE=en # e.g. en, ch, german, japan
|
|
43
|
+
# OCR_GPU=false # EasyOCR / PaddleOCR / docTR on a CUDA GPU
|
|
44
|
+
# OCR_MAX_EDGE_PX=4000 # longest edge of the image given to these engines
|
|
45
|
+
# OCR_TIMEOUT_S=120
|
|
46
|
+
|
|
47
|
+
# Google Cloud Vision (an API key with the Cloud Vision API enabled)
|
|
48
|
+
GOOGLE_VISION_API_KEY=
|
|
49
|
+
# GOOGLE_VISION_LANGUAGE_HINTS= # e.g. en,de; empty = auto-detect
|
|
50
|
+
|
|
51
|
+
# Azure AI Document Intelligence (prebuilt-read)
|
|
52
|
+
AZURE_DOCUMENT_INTELLIGENCE_ENDPOINT=
|
|
53
|
+
AZURE_DOCUMENT_INTELLIGENCE_KEY=
|
|
54
|
+
|
|
55
|
+
# AWS Textract (credentials may also come from ~/.aws or AWS_PROFILE)
|
|
56
|
+
# AWS_REGION=us-east-1
|
|
57
|
+
# AWS_ACCESS_KEY_ID=
|
|
58
|
+
# AWS_SECRET_ACCESS_KEY=
|
|
59
|
+
# AWS_SESSION_TOKEN=
|
|
60
|
+
|
|
61
|
+
# Mistral OCR
|
|
62
|
+
MISTRAL_API_KEY=
|
|
63
|
+
# MISTRAL_OCR_MODEL=mistral-ocr-latest
|
|
64
|
+
|
|
38
65
|
# --- Storage, rendering and OCR ---------------------------------------------------
|
|
39
66
|
# DATA_DIR=data
|
|
40
67
|
# MAX_UPLOAD_MB=200
|
|
@@ -2,6 +2,69 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 0.6.0 - 2026-11-27
|
|
6
|
+
|
|
7
|
+
- **Structured data extraction**: a new prompt, *Structured data (fields → JSON)*, fills a JSON Schema from each page
|
|
8
|
+
instead of transcribing it. Built-in schemas for invoices, receipts and form fields, or your own JSON Schema
|
|
9
|
+
(checked as you type). Providers enforce the schema natively where they can (Claude structured outputs, OpenAI /
|
|
10
|
+
Azure strict `response_format`, Gemini `response_json_schema`); older Claude models and OpenAI-compatible servers
|
|
11
|
+
get it in the prompt, with a warning. Values are copied as printed, and fields that aren't on the page are `null`.
|
|
12
|
+
The LLM tab shows the result as a field table (fields found, line items, schema problems on their field) with the
|
|
13
|
+
raw JSON one click away. Every reply is parsed and validated against the schema; results store `data`,
|
|
14
|
+
`data_errors`, `fields_filled` and `fields_total` next to the text.
|
|
15
|
+
- **Schema editor**: build your own schema field by field (name, type, hint for the model, required; tables and
|
|
16
|
+
groups nest) without writing JSON Schema, or edit it as JSON in an editor with colours, line numbers and the
|
|
17
|
+
error line marked. *Fix syntax* repairs quotes, unquoted keys, missing or trailing commas, unclosed brackets,
|
|
18
|
+
comments, Python `True`/`None` and type names such as `str` or `bool`. Each edit is checked: mistakes come with
|
|
19
|
+
suggestions ("did you mean 'properties'?"), and a note says whether the chosen provider and model enforce the
|
|
20
|
+
schema or only get it in the prompt. An example output, as the field table or as JSON, shows what a result will
|
|
21
|
+
look like before you pay for a run.
|
|
22
|
+
- **Draft fields from plain words**: describe what to extract ("invoice number, date, every line item with its
|
|
23
|
+
amount") and the chosen model drafts the fields, optionally looking at the current page. The draft opens in the
|
|
24
|
+
field editor for review, and *Change my current fields* refines it step by step ("also add the due date"). One
|
|
25
|
+
paid call per draft (tokens and cost shown), through `LLM_CONCURRENCY`. API: `POST /api/extract/draft-schema`
|
|
26
|
+
(`description`, `provider`, `model`, optional `current_schema`, `doc_id` and `page`; same-origin only).
|
|
27
|
+
- The schema is part of the LLM cache key, so each schema is its own source. Plain transcriptions keep their
|
|
28
|
+
existing keys, so cached results are unaffected.
|
|
29
|
+
- API: `prompt_mode: "extract"` with `extract_schema` (a preset id or a JSON Schema) on
|
|
30
|
+
`POST /api/documents/{id}/pages/{n}/llm` and in job bodies, `POST /api/extract/check-schema` (validation notes,
|
|
31
|
+
example output, syntax error position and a repaired version; takes an optional `provider` and `model`), `extract_presets` in
|
|
32
|
+
`/api/config`, and a per-page `data` object in JSON / JSONL exports of an extraction (one source, and
|
|
33
|
+
*Export all* as `data: {source_id: fields}`). CLI:
|
|
34
|
+
`pyocr extract --mode extract --schema invoice|receipt|form|<file.json>`.
|
|
35
|
+
- The README and website now install from PyPI (`pipx install pyocr-toolkit`) instead of from GitHub.
|
|
36
|
+
- Existing results and cache keys are unchanged.
|
|
37
|
+
|
|
38
|
+
## 0.5.0 - 2026-11-27
|
|
39
|
+
|
|
40
|
+
- **More OCR engines.** Besides Tesseract: RapidOCR, EasyOCR, PaddleOCR and docTR (local, optional extras such as
|
|
41
|
+
`pip install "pyocr-toolkit[easyocr]"`), and Google Cloud Vision, Azure AI Document Intelligence, AWS Textract
|
|
42
|
+
and Mistral OCR (cloud, configured with environment variables). Each engine is a separate source
|
|
43
|
+
(`ocr:<engine>`; `ocr` stays Tesseract) that can be searched, compared and exported.
|
|
44
|
+
- The page inspector, Overview extract form, background jobs and the CLI (`--engine ocr:<engine>`,
|
|
45
|
+
`--ocr-engine`, `pyocr engines`) can pick the OCR engine. The Providers page lists every engine with its status
|
|
46
|
+
and a Test button, and cloud OCR keys and engine settings can be saved there like LLM provider credentials.
|
|
47
|
+
- New settings: `GOOGLE_VISION_API_KEY`, `GOOGLE_VISION_LANGUAGE_HINTS`, `AZURE_DOCUMENT_INTELLIGENCE_ENDPOINT`,
|
|
48
|
+
`AZURE_DOCUMENT_INTELLIGENCE_KEY`, `AWS_REGION` (plus the usual AWS credentials), `MISTRAL_API_KEY`,
|
|
49
|
+
`MISTRAL_OCR_MODEL`, `EASYOCR_LANGUAGES`, `PADDLEOCR_LANGUAGE`, `OCR_GPU`, `OCR_MAX_EDGE_PX`, `OCR_TIMEOUT_S`.
|
|
50
|
+
- Existing Tesseract results (`ocr/<page>.json`) are read as before; other engines cache under `ocr/<engine>/`.
|
|
51
|
+
- **Other PDF libraries.** Besides PyMuPDF, the text layer can be read with pypdf, pdfplumber, pdfminer.six and
|
|
52
|
+
pypdfium2 (optional: `pip install "pyocr-toolkit[pdf]"`). Each installed library is its own source
|
|
53
|
+
(`native:<library>`; `native` stays PyMuPDF) that can be compared and exported. The page inspector's Native tab
|
|
54
|
+
has a library picker and a **Test all libraries** button that shows which libraries get text out of the page.
|
|
55
|
+
CLI: `--engine native:<library>` and `pyocr libraries`; API: `?library=` on `/text/native`, a new
|
|
56
|
+
`/pages/{page}/text/native/libraries` endpoint, and `text_libraries` in `/api/config`. Results are cached under
|
|
57
|
+
`native/<library>/<page>.json` and re-read when the library version changes.
|
|
58
|
+
- **Export all sources.** Download everything extracted for a document in one file: Overview → *Export all*,
|
|
59
|
+
the Full text *Download* menu, or `GET /api/documents/{id}/export/all?fmt=json|jsonl|csv|md|zip`.
|
|
60
|
+
JSON keeps each page's text per source, CSV puts sources side by side (a column each), and ZIP bundles the JSON
|
|
61
|
+
and CSV with a TXT and Markdown file per source. Like single-source export, it only reads cached results.
|
|
62
|
+
- Logos for LLM providers and OCR engines across the UI (bundled locally, no external requests).
|
|
63
|
+
- The upload file pickers now offer `.txt`, `.cbr` and `.pam` files, which the server already accepted.
|
|
64
|
+
- Fix: running Tesseract on two documents at once (e.g. two OCR jobs) failed with "Attempt to use Leptonica from
|
|
65
|
+
2 threads at once"; Tesseract calls are now serialised across the whole process.
|
|
66
|
+
- LLM prompts and cache keys are unchanged, so existing results stay valid.
|
|
67
|
+
|
|
5
68
|
## 0.4.0 - 2026-11-27
|
|
6
69
|
|
|
7
70
|
- Several pages per LLM request: set **Pages per request** on the Overview page, `--pages-per-request N` on
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: pyocr-toolkit
|
|
3
|
-
Version: 0.
|
|
4
|
-
Summary: Inspect and compare PDF/image text extraction - native text, Tesseract
|
|
3
|
+
Version: 0.6.0
|
|
4
|
+
Summary: Inspect and compare PDF/image text extraction - native text, OCR engines (Tesseract, EasyOCR, PaddleOCR, docTR, RapidOCR, Google Vision, Azure, Textract, Mistral) and LLMs (Claude, GPT, Gemini, Azure, local) - in your browser.
|
|
5
5
|
Project-URL: Homepage, https://github.com/utkarsh5026/pyocr
|
|
6
6
|
Project-URL: Issues, https://github.com/utkarsh5026/pyocr/issues
|
|
7
7
|
Author: utkarsh5026
|
|
@@ -207,7 +207,7 @@ License: Apache License
|
|
|
207
207
|
See the License for the specific language governing permissions and
|
|
208
208
|
limitations under the License.
|
|
209
209
|
License-File: LICENSE
|
|
210
|
-
Keywords: claude,document-ai,llm,ocr,openai,pdf,pymupdf,rag,tesseract,text-extraction
|
|
210
|
+
Keywords: claude,doctr,document-ai,easyocr,llm,ocr,openai,paddleocr,pdf,pdfplumber,pymupdf,pypdf,rag,tesseract,text-extraction,textract
|
|
211
211
|
Classifier: Development Status :: 4 - Beta
|
|
212
212
|
Classifier: Environment :: Web Environment
|
|
213
213
|
Classifier: Framework :: FastAPI
|
|
@@ -226,6 +226,7 @@ Requires-Python: >=3.10
|
|
|
226
226
|
Requires-Dist: anthropic>=1.0
|
|
227
227
|
Requires-Dist: fastapi>=0.110
|
|
228
228
|
Requires-Dist: google-genai>=1.0
|
|
229
|
+
Requires-Dist: httpx>=0.27
|
|
229
230
|
Requires-Dist: jinja2>=3.1
|
|
230
231
|
Requires-Dist: openai>=1.40
|
|
231
232
|
Requires-Dist: pillow>=10.1
|
|
@@ -236,9 +237,30 @@ Requires-Dist: rapidfuzz>=3.6
|
|
|
236
237
|
Requires-Dist: uvicorn[standard]>=0.29
|
|
237
238
|
Provides-Extra: dev
|
|
238
239
|
Requires-Dist: httpx>=0.27; extra == 'dev'
|
|
240
|
+
Requires-Dist: pdfminer-six>=20231228; extra == 'dev'
|
|
241
|
+
Requires-Dist: pdfplumber>=0.11; extra == 'dev'
|
|
242
|
+
Requires-Dist: pypdf>=4; extra == 'dev'
|
|
243
|
+
Requires-Dist: pypdfium2>=4; extra == 'dev'
|
|
239
244
|
Requires-Dist: pytest>=8; extra == 'dev'
|
|
240
245
|
Requires-Dist: rich>=13; extra == 'dev'
|
|
241
246
|
Requires-Dist: ruff>=0.5; extra == 'dev'
|
|
247
|
+
Provides-Extra: doctr
|
|
248
|
+
Requires-Dist: python-doctr[torch]>=0.10; extra == 'doctr'
|
|
249
|
+
Provides-Extra: easyocr
|
|
250
|
+
Requires-Dist: easyocr>=1.7; extra == 'easyocr'
|
|
251
|
+
Provides-Extra: paddleocr
|
|
252
|
+
Requires-Dist: paddleocr>=3; extra == 'paddleocr'
|
|
253
|
+
Requires-Dist: paddlepaddle>=3; extra == 'paddleocr'
|
|
254
|
+
Provides-Extra: pdf
|
|
255
|
+
Requires-Dist: pdfminer-six>=20231228; extra == 'pdf'
|
|
256
|
+
Requires-Dist: pdfplumber>=0.11; extra == 'pdf'
|
|
257
|
+
Requires-Dist: pypdf>=4; extra == 'pdf'
|
|
258
|
+
Requires-Dist: pypdfium2>=4; extra == 'pdf'
|
|
259
|
+
Provides-Extra: rapidocr
|
|
260
|
+
Requires-Dist: onnxruntime>=1.17; extra == 'rapidocr'
|
|
261
|
+
Requires-Dist: rapidocr>=2; extra == 'rapidocr'
|
|
262
|
+
Provides-Extra: textract
|
|
263
|
+
Requires-Dist: boto3>=1.34; extra == 'textract'
|
|
242
264
|
Description-Content-Type: text/markdown
|
|
243
265
|
|
|
244
266
|
<div align="center">
|
|
@@ -276,8 +298,8 @@ checking that step. Upload a document and you get three versions of every page:
|
|
|
276
298
|
|
|
277
299
|
| | Source | What it is | Good at | Weak at |
|
|
278
300
|
|---|---|---|---|---|
|
|
279
|
-
| 📄 | **Native text** | Text already embedded in the file (PyMuPDF) | Born-digital PDFs. Exact and instant. | Scans have none. Broken font maps produce gibberish. |
|
|
280
|
-
| 🔍 | **
|
|
301
|
+
| 📄 | **Native text** | Text already embedded in the file (PyMuPDF, or pypdf / pdfplumber / pdfminer.six / pypdfium2) | Born-digital PDFs. Exact and instant. | Scans have none. Broken font maps produce gibberish. |
|
|
302
|
+
| 🔍 | **OCR** | Tesseract, or any of 8 other OCR engines (below), on the rendered page image | Free/local or cheap cloud, gives word positions | Varies by engine: Tesseract struggles with tables, columns, poor scans, handwriting |
|
|
281
303
|
| ✨ | **LLM transcription** | A vision LLM told to copy the page *verbatim* | Hard pages, layout, context | Costs money. May quietly "fix" or skip text. |
|
|
282
304
|
|
|
283
305
|
Then you can:
|
|
@@ -285,11 +307,16 @@ Then you can:
|
|
|
285
307
|
- **Extract** page by page, a range like `1-5,9`, or the whole document, as background jobs
|
|
286
308
|
- **Compare** any two sources: character and word error rate (CER/WER), word-level diffs, a per-page chart
|
|
287
309
|
- **Search** across every document and every source at once
|
|
288
|
-
- **Export** clean text as TXT, Markdown, JSON or JSONL for your pipeline
|
|
310
|
+
- **Export** clean text as TXT, Markdown, JSON or JSONL for your pipeline, or every source at once as JSON, CSV,
|
|
311
|
+
Markdown, JSONL or a ZIP
|
|
289
312
|
|
|
290
313
|
**LLM providers:** Claude (Anthropic API), OpenAI, Azure OpenAI, Claude on Azure (Microsoft Foundry), Google
|
|
291
314
|
Gemini, and any OpenAI-compatible server (Ollama, vLLM, LM Studio, OpenRouter) for local or private models.
|
|
292
315
|
|
|
316
|
+
**OCR engines:** Tesseract (default), plus RapidOCR, EasyOCR, PaddleOCR and docTR running locally, and Google
|
|
317
|
+
Cloud Vision, Azure AI Document Intelligence, AWS Textract and Mistral OCR in the cloud. Each engine is its own
|
|
318
|
+
source, so you can score engines against each other or against an LLM.
|
|
319
|
+
|
|
293
320
|
**Inputs:** PDF, XPS, EPUB, CBZ, MOBI, FB2, SVG, PNG, JPEG, TIFF (multi-page), BMP, GIF, WebP and anything else
|
|
294
321
|
[PyMuPDF](https://pymupdf.readthedocs.io/) opens.
|
|
295
322
|
|
|
@@ -334,19 +361,20 @@ choco install tesseract # Windows (or the UB Man
|
|
|
334
361
|
**Option A: pipx** (recommended, installs it as an isolated command):
|
|
335
362
|
|
|
336
363
|
```bash
|
|
337
|
-
pipx install
|
|
364
|
+
pipx install pyocr-toolkit
|
|
338
365
|
```
|
|
339
366
|
|
|
340
367
|
**Option B: pip** in a virtual environment:
|
|
341
368
|
|
|
342
369
|
```bash
|
|
343
370
|
python -m venv .venv && source .venv/bin/activate # Windows: .venv\Scripts\activate
|
|
344
|
-
pip install
|
|
371
|
+
pip install pyocr-toolkit
|
|
345
372
|
```
|
|
346
373
|
|
|
347
374
|
> [!NOTE]
|
|
348
|
-
> The PyPI name is `pyocr-toolkit` (plain `pyocr` is a different, unrelated library).
|
|
349
|
-
>
|
|
375
|
+
> The PyPI name is `pyocr-toolkit` (plain `pyocr` is a different, unrelated library). Optional extras add more
|
|
376
|
+
> engines, e.g. `pipx install "pyocr-toolkit[pdf,rapidocr]"`. To run the latest unreleased code, install from
|
|
377
|
+
> GitHub instead: `pipx install git+https://github.com/utkarsh5026/pyocr`.
|
|
350
378
|
|
|
351
379
|
**Option C: Docker** (Tesseract and several language packs included):
|
|
352
380
|
|
|
@@ -374,7 +402,7 @@ Everything you upload and extract is stored in `./data` (change it with `DATA_DI
|
|
|
374
402
|
| **Home** `/` | Drop files to upload; see setup status and recent documents. |
|
|
375
403
|
| **Library** `/documents` | Document cards showing native / OCR / LLM coverage and how many pages still have no text. Filter by status, workspace or name; delete. |
|
|
376
404
|
| **Workspaces** `/workspaces` | Named groups of documents. Uploading several files or a `.zip` offers to create one, with suggested names (from the file names, or `adjective-scientist` like `festive-albattani`). Open one to rename it, add files or remove documents. |
|
|
377
|
-
| **Overview** `/documents/{id}` | Start background extraction (
|
|
405
|
+
| **Overview** `/documents/{id}` | Start background extraction (any OCR engine or LLM) for all pages or a range such as `1-5,9`, typed or picked on a clickable page map (Shift-click for a range; presets for scans only or pages without text yet); choose pages per LLM request; follow progress; see every *source* (engine + model + prompt) with token usage; export; page thumbnails. |
|
|
378
406
|
| **Page inspector** `/documents/{id}/pages/{n}` | Page image next to native, OCR and LLM text; run OCR or an LLM on just this page; per-page diff; a *Side by side* tab with all three texts in synced columns; search hits drawn on the image; *Adjust* to preprocess the image the LLM receives (filters, fine-tuning, crop/rotate) and A/B it against the original. Keyboard: `←/→`, `/`, `1-5`, `t`, `o`, `e`. |
|
|
379
407
|
| **Full text** `/documents/{id}/text` | Read the whole document from one source, optionally beside the page images; find, copy, download. |
|
|
380
408
|
| **Compare** `/documents/{id}/compare` | Score source B against source A on every page: document-level CER/WER, a clickable CER-per-page chart, and an aligned side-by-side diff of the selected page (opens on the worst page). Works for OCR vs LLM, native vs LLM, or **model vs model**. |
|
|
@@ -405,17 +433,63 @@ and the hint under each model box say whether a model suits transcription (custo
|
|
|
405
433
|
images. For a fully local setup, run Ollama with a vision model and set
|
|
406
434
|
`OPENAI_COMPATIBLE_BASE_URL=http://localhost:11434/v1`.
|
|
407
435
|
|
|
436
|
+
## Configure OCR engines
|
|
437
|
+
|
|
438
|
+
Tesseract is the default engine. Every other engine is optional, and the Providers page (and `pyocr engines`) shows
|
|
439
|
+
which are ready, with a **Test** button for each. Cloud keys and engine settings can be set there too, or as
|
|
440
|
+
environment variables. Local engines run on your machine; the first run downloads the
|
|
441
|
+
model weights. Cloud engines send the rendered page image to that service, and nowhere else.
|
|
442
|
+
|
|
443
|
+
| Engine | Kind | Install / required settings | Optional |
|
|
444
|
+
|---|---|---|---|
|
|
445
|
+
| Tesseract | local | system package (`apt install tesseract-ocr`, `brew install tesseract`) | `TESSERACT_LANGUAGE` |
|
|
446
|
+
| RapidOCR | local | `pip install "pyocr-toolkit[rapidocr]"` (ONNX Runtime, no PyTorch) | – |
|
|
447
|
+
| EasyOCR | local | `pip install "pyocr-toolkit[easyocr]"` (PyTorch) | `EASYOCR_LANGUAGES`, `OCR_GPU` |
|
|
448
|
+
| PaddleOCR | local | `pip install "pyocr-toolkit[paddleocr]"` (PaddlePaddle) | `PADDLEOCR_LANGUAGE` |
|
|
449
|
+
| docTR | local | `pip install "pyocr-toolkit[doctr]"` (PyTorch) | `OCR_GPU` |
|
|
450
|
+
| Google Cloud Vision | cloud | `GOOGLE_VISION_API_KEY` | `GOOGLE_VISION_LANGUAGE_HINTS` |
|
|
451
|
+
| Azure AI Document Intelligence | cloud | `AZURE_DOCUMENT_INTELLIGENCE_ENDPOINT`, `AZURE_DOCUMENT_INTELLIGENCE_KEY` | – |
|
|
452
|
+
| AWS Textract | cloud | `pip install "pyocr-toolkit[textract]"`, `AWS_REGION` | `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY` (or `~/.aws`) |
|
|
453
|
+
| Mistral OCR | cloud | `MISTRAL_API_KEY` | `MISTRAL_OCR_MODEL` (default `mistral-ocr-latest`) |
|
|
454
|
+
|
|
455
|
+
Mistral OCR returns Markdown without word positions, so its search hits can't be drawn on the page image. In the
|
|
456
|
+
API, OCR sources are `ocr` (Tesseract) and `ocr:<engine>`, e.g. `ocr:easyocr`.
|
|
457
|
+
|
|
458
|
+
## PDF libraries
|
|
459
|
+
|
|
460
|
+
Native text comes from PyMuPDF, but Python has other PDF libraries, and they don't all read a text layer the same
|
|
461
|
+
way: reading order, spacing, ligatures and odd font encodings come out differently. If your pipeline uses one of
|
|
462
|
+
them, check *that* library on your PDFs. Each installed library is its own source, `native:<library>`:
|
|
463
|
+
|
|
464
|
+
| Library | Source | Notes |
|
|
465
|
+
|---|---|---|
|
|
466
|
+
| PyMuPDF | `native` | always installed; word boxes |
|
|
467
|
+
| pypdf | `native:pypdf` | pure Python; used by many LangChain / LlamaIndex loaders |
|
|
468
|
+
| pdfplumber | `native:pdfplumber` | built on pdfminer.six; word boxes |
|
|
469
|
+
| pdfminer.six | `native:pdfminer` | pure-Python layout analysis |
|
|
470
|
+
| pypdfium2 | `native:pypdfium2` | PDFium, the engine in Chrome |
|
|
471
|
+
|
|
472
|
+
Install them all with `pip install "pyocr-toolkit[pdf]"` (or just the ones you need). In the page inspector, the
|
|
473
|
+
**Native** tab has a library picker and a **Test all libraries** button that reads the page with each one and shows
|
|
474
|
+
whether it got text out, how much, and how fast. The Compare page and exports list every installed library, so you
|
|
475
|
+
can score `native:pypdf` against `native` across a whole document. `pyocr libraries` shows what's installed, and
|
|
476
|
+
`pyocr extract FILE --engine native:pdfplumber` extracts with one of them. They read PDF files only.
|
|
477
|
+
|
|
408
478
|
## Command line
|
|
409
479
|
|
|
410
480
|
```bash
|
|
411
481
|
pyocr extract report.pdf --engine llm -p anthropic --pages 1-5 --format jsonl -o report.jsonl
|
|
412
482
|
pyocr extract report.pdf --engine llm --pages-per-request 5 # 5 pages in each LLM request
|
|
413
483
|
pyocr extract scan.tiff --engine ocr --format md # Tesseract, Markdown to stdout
|
|
484
|
+
pyocr extract scan.pdf --engine ocr:easyocr # any OCR engine (see `pyocr engines`)
|
|
414
485
|
pyocr extract born-digital.pdf --engine native # embedded text only, no network
|
|
486
|
+
pyocr extract born-digital.pdf --engine native:pypdf # the same text layer as pypdf reads it
|
|
415
487
|
pyocr compare scan.pdf -p openai -m gpt-6.2-sol # per-page OCR / native CER vs an LLM
|
|
416
488
|
pyocr extract scan.pdf -p anthropic --preprocess 'gray;auto;contrast=1.5' # adjust the image first (or a preset: clean, bw, ...)
|
|
489
|
+
pyocr extract invoice.pdf -p anthropic --mode extract --schema invoice --format json # fields, not text (or a JSON Schema file)
|
|
417
490
|
pyocr import a.pdf b.pdf scans.zip folder/ -w invoices # add many files as one workspace (zips unpacked)
|
|
418
491
|
pyocr providers # which providers are ready
|
|
492
|
+
pyocr engines # which OCR engines are ready
|
|
419
493
|
python -m pyocr_toolkit --help # same CLI without the script on PATH
|
|
420
494
|
```
|
|
421
495
|
|
|
@@ -446,8 +520,8 @@ you ask otherwise.
|
|
|
446
520
|
|
|
447
521
|
1. **Native text.** A PDF page is a list of drawing instructions ("glyph 37 at (72, 700)"). Born-digital files map
|
|
448
522
|
each glyph back to a character, so the text can be rebuilt exactly. A scan is only a picture, so it has no text.
|
|
449
|
-
2. **OCR.** The page is rendered to pixels (300 DPI) and Tesseract recognises characters
|
|
450
|
-
reporting a box for each word. That is why search can highlight OCR hits on the page.
|
|
523
|
+
2. **OCR.** The page is rendered to pixels (300 DPI) and an OCR engine (Tesseract by default) recognises characters
|
|
524
|
+
from their shapes, reporting a box for each word (or line, split into words). That is why search can highlight OCR hits on the page.
|
|
451
525
|
3. **LLM.** The page image goes to a vision model with a strict "transcribe, don't correct" prompt
|
|
452
526
|
([`prompts.py`](https://github.com/utkarsh5026/pyocr/blob/main/src/pyocr_toolkit/llm/prompts.py)). It reads in context, so it is strong on hard pages, but it can
|
|
453
527
|
"fix" typos, which the diff view exposes.
|
|
@@ -33,8 +33,8 @@ checking that step. Upload a document and you get three versions of every page:
|
|
|
33
33
|
|
|
34
34
|
| | Source | What it is | Good at | Weak at |
|
|
35
35
|
|---|---|---|---|---|
|
|
36
|
-
| 📄 | **Native text** | Text already embedded in the file (PyMuPDF) | Born-digital PDFs. Exact and instant. | Scans have none. Broken font maps produce gibberish. |
|
|
37
|
-
| 🔍 | **
|
|
36
|
+
| 📄 | **Native text** | Text already embedded in the file (PyMuPDF, or pypdf / pdfplumber / pdfminer.six / pypdfium2) | Born-digital PDFs. Exact and instant. | Scans have none. Broken font maps produce gibberish. |
|
|
37
|
+
| 🔍 | **OCR** | Tesseract, or any of 8 other OCR engines (below), on the rendered page image | Free/local or cheap cloud, gives word positions | Varies by engine: Tesseract struggles with tables, columns, poor scans, handwriting |
|
|
38
38
|
| ✨ | **LLM transcription** | A vision LLM told to copy the page *verbatim* | Hard pages, layout, context | Costs money. May quietly "fix" or skip text. |
|
|
39
39
|
|
|
40
40
|
Then you can:
|
|
@@ -42,11 +42,16 @@ Then you can:
|
|
|
42
42
|
- **Extract** page by page, a range like `1-5,9`, or the whole document, as background jobs
|
|
43
43
|
- **Compare** any two sources: character and word error rate (CER/WER), word-level diffs, a per-page chart
|
|
44
44
|
- **Search** across every document and every source at once
|
|
45
|
-
- **Export** clean text as TXT, Markdown, JSON or JSONL for your pipeline
|
|
45
|
+
- **Export** clean text as TXT, Markdown, JSON or JSONL for your pipeline, or every source at once as JSON, CSV,
|
|
46
|
+
Markdown, JSONL or a ZIP
|
|
46
47
|
|
|
47
48
|
**LLM providers:** Claude (Anthropic API), OpenAI, Azure OpenAI, Claude on Azure (Microsoft Foundry), Google
|
|
48
49
|
Gemini, and any OpenAI-compatible server (Ollama, vLLM, LM Studio, OpenRouter) for local or private models.
|
|
49
50
|
|
|
51
|
+
**OCR engines:** Tesseract (default), plus RapidOCR, EasyOCR, PaddleOCR and docTR running locally, and Google
|
|
52
|
+
Cloud Vision, Azure AI Document Intelligence, AWS Textract and Mistral OCR in the cloud. Each engine is its own
|
|
53
|
+
source, so you can score engines against each other or against an LLM.
|
|
54
|
+
|
|
50
55
|
**Inputs:** PDF, XPS, EPUB, CBZ, MOBI, FB2, SVG, PNG, JPEG, TIFF (multi-page), BMP, GIF, WebP and anything else
|
|
51
56
|
[PyMuPDF](https://pymupdf.readthedocs.io/) opens.
|
|
52
57
|
|
|
@@ -91,19 +96,20 @@ choco install tesseract # Windows (or the UB Man
|
|
|
91
96
|
**Option A: pipx** (recommended, installs it as an isolated command):
|
|
92
97
|
|
|
93
98
|
```bash
|
|
94
|
-
pipx install
|
|
99
|
+
pipx install pyocr-toolkit
|
|
95
100
|
```
|
|
96
101
|
|
|
97
102
|
**Option B: pip** in a virtual environment:
|
|
98
103
|
|
|
99
104
|
```bash
|
|
100
105
|
python -m venv .venv && source .venv/bin/activate # Windows: .venv\Scripts\activate
|
|
101
|
-
pip install
|
|
106
|
+
pip install pyocr-toolkit
|
|
102
107
|
```
|
|
103
108
|
|
|
104
109
|
> [!NOTE]
|
|
105
|
-
> The PyPI name is `pyocr-toolkit` (plain `pyocr` is a different, unrelated library).
|
|
106
|
-
>
|
|
110
|
+
> The PyPI name is `pyocr-toolkit` (plain `pyocr` is a different, unrelated library). Optional extras add more
|
|
111
|
+
> engines, e.g. `pipx install "pyocr-toolkit[pdf,rapidocr]"`. To run the latest unreleased code, install from
|
|
112
|
+
> GitHub instead: `pipx install git+https://github.com/utkarsh5026/pyocr`.
|
|
107
113
|
|
|
108
114
|
**Option C: Docker** (Tesseract and several language packs included):
|
|
109
115
|
|
|
@@ -131,7 +137,7 @@ Everything you upload and extract is stored in `./data` (change it with `DATA_DI
|
|
|
131
137
|
| **Home** `/` | Drop files to upload; see setup status and recent documents. |
|
|
132
138
|
| **Library** `/documents` | Document cards showing native / OCR / LLM coverage and how many pages still have no text. Filter by status, workspace or name; delete. |
|
|
133
139
|
| **Workspaces** `/workspaces` | Named groups of documents. Uploading several files or a `.zip` offers to create one, with suggested names (from the file names, or `adjective-scientist` like `festive-albattani`). Open one to rename it, add files or remove documents. |
|
|
134
|
-
| **Overview** `/documents/{id}` | Start background extraction (
|
|
140
|
+
| **Overview** `/documents/{id}` | Start background extraction (any OCR engine or LLM) for all pages or a range such as `1-5,9`, typed or picked on a clickable page map (Shift-click for a range; presets for scans only or pages without text yet); choose pages per LLM request; follow progress; see every *source* (engine + model + prompt) with token usage; export; page thumbnails. |
|
|
135
141
|
| **Page inspector** `/documents/{id}/pages/{n}` | Page image next to native, OCR and LLM text; run OCR or an LLM on just this page; per-page diff; a *Side by side* tab with all three texts in synced columns; search hits drawn on the image; *Adjust* to preprocess the image the LLM receives (filters, fine-tuning, crop/rotate) and A/B it against the original. Keyboard: `←/→`, `/`, `1-5`, `t`, `o`, `e`. |
|
|
136
142
|
| **Full text** `/documents/{id}/text` | Read the whole document from one source, optionally beside the page images; find, copy, download. |
|
|
137
143
|
| **Compare** `/documents/{id}/compare` | Score source B against source A on every page: document-level CER/WER, a clickable CER-per-page chart, and an aligned side-by-side diff of the selected page (opens on the worst page). Works for OCR vs LLM, native vs LLM, or **model vs model**. |
|
|
@@ -162,17 +168,63 @@ and the hint under each model box say whether a model suits transcription (custo
|
|
|
162
168
|
images. For a fully local setup, run Ollama with a vision model and set
|
|
163
169
|
`OPENAI_COMPATIBLE_BASE_URL=http://localhost:11434/v1`.
|
|
164
170
|
|
|
171
|
+
## Configure OCR engines
|
|
172
|
+
|
|
173
|
+
Tesseract is the default engine. Every other engine is optional, and the Providers page (and `pyocr engines`) shows
|
|
174
|
+
which are ready, with a **Test** button for each. Cloud keys and engine settings can be set there too, or as
|
|
175
|
+
environment variables. Local engines run on your machine; the first run downloads the
|
|
176
|
+
model weights. Cloud engines send the rendered page image to that service, and nowhere else.
|
|
177
|
+
|
|
178
|
+
| Engine | Kind | Install / required settings | Optional |
|
|
179
|
+
|---|---|---|---|
|
|
180
|
+
| Tesseract | local | system package (`apt install tesseract-ocr`, `brew install tesseract`) | `TESSERACT_LANGUAGE` |
|
|
181
|
+
| RapidOCR | local | `pip install "pyocr-toolkit[rapidocr]"` (ONNX Runtime, no PyTorch) | – |
|
|
182
|
+
| EasyOCR | local | `pip install "pyocr-toolkit[easyocr]"` (PyTorch) | `EASYOCR_LANGUAGES`, `OCR_GPU` |
|
|
183
|
+
| PaddleOCR | local | `pip install "pyocr-toolkit[paddleocr]"` (PaddlePaddle) | `PADDLEOCR_LANGUAGE` |
|
|
184
|
+
| docTR | local | `pip install "pyocr-toolkit[doctr]"` (PyTorch) | `OCR_GPU` |
|
|
185
|
+
| Google Cloud Vision | cloud | `GOOGLE_VISION_API_KEY` | `GOOGLE_VISION_LANGUAGE_HINTS` |
|
|
186
|
+
| Azure AI Document Intelligence | cloud | `AZURE_DOCUMENT_INTELLIGENCE_ENDPOINT`, `AZURE_DOCUMENT_INTELLIGENCE_KEY` | – |
|
|
187
|
+
| AWS Textract | cloud | `pip install "pyocr-toolkit[textract]"`, `AWS_REGION` | `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY` (or `~/.aws`) |
|
|
188
|
+
| Mistral OCR | cloud | `MISTRAL_API_KEY` | `MISTRAL_OCR_MODEL` (default `mistral-ocr-latest`) |
|
|
189
|
+
|
|
190
|
+
Mistral OCR returns Markdown without word positions, so its search hits can't be drawn on the page image. In the
|
|
191
|
+
API, OCR sources are `ocr` (Tesseract) and `ocr:<engine>`, e.g. `ocr:easyocr`.
|
|
192
|
+
|
|
193
|
+
## PDF libraries
|
|
194
|
+
|
|
195
|
+
Native text comes from PyMuPDF, but Python has other PDF libraries, and they don't all read a text layer the same
|
|
196
|
+
way: reading order, spacing, ligatures and odd font encodings come out differently. If your pipeline uses one of
|
|
197
|
+
them, check *that* library on your PDFs. Each installed library is its own source, `native:<library>`:
|
|
198
|
+
|
|
199
|
+
| Library | Source | Notes |
|
|
200
|
+
|---|---|---|
|
|
201
|
+
| PyMuPDF | `native` | always installed; word boxes |
|
|
202
|
+
| pypdf | `native:pypdf` | pure Python; used by many LangChain / LlamaIndex loaders |
|
|
203
|
+
| pdfplumber | `native:pdfplumber` | built on pdfminer.six; word boxes |
|
|
204
|
+
| pdfminer.six | `native:pdfminer` | pure-Python layout analysis |
|
|
205
|
+
| pypdfium2 | `native:pypdfium2` | PDFium, the engine in Chrome |
|
|
206
|
+
|
|
207
|
+
Install them all with `pip install "pyocr-toolkit[pdf]"` (or just the ones you need). In the page inspector, the
|
|
208
|
+
**Native** tab has a library picker and a **Test all libraries** button that reads the page with each one and shows
|
|
209
|
+
whether it got text out, how much, and how fast. The Compare page and exports list every installed library, so you
|
|
210
|
+
can score `native:pypdf` against `native` across a whole document. `pyocr libraries` shows what's installed, and
|
|
211
|
+
`pyocr extract FILE --engine native:pdfplumber` extracts with one of them. They read PDF files only.
|
|
212
|
+
|
|
165
213
|
## Command line
|
|
166
214
|
|
|
167
215
|
```bash
|
|
168
216
|
pyocr extract report.pdf --engine llm -p anthropic --pages 1-5 --format jsonl -o report.jsonl
|
|
169
217
|
pyocr extract report.pdf --engine llm --pages-per-request 5 # 5 pages in each LLM request
|
|
170
218
|
pyocr extract scan.tiff --engine ocr --format md # Tesseract, Markdown to stdout
|
|
219
|
+
pyocr extract scan.pdf --engine ocr:easyocr # any OCR engine (see `pyocr engines`)
|
|
171
220
|
pyocr extract born-digital.pdf --engine native # embedded text only, no network
|
|
221
|
+
pyocr extract born-digital.pdf --engine native:pypdf # the same text layer as pypdf reads it
|
|
172
222
|
pyocr compare scan.pdf -p openai -m gpt-6.2-sol # per-page OCR / native CER vs an LLM
|
|
173
223
|
pyocr extract scan.pdf -p anthropic --preprocess 'gray;auto;contrast=1.5' # adjust the image first (or a preset: clean, bw, ...)
|
|
224
|
+
pyocr extract invoice.pdf -p anthropic --mode extract --schema invoice --format json # fields, not text (or a JSON Schema file)
|
|
174
225
|
pyocr import a.pdf b.pdf scans.zip folder/ -w invoices # add many files as one workspace (zips unpacked)
|
|
175
226
|
pyocr providers # which providers are ready
|
|
227
|
+
pyocr engines # which OCR engines are ready
|
|
176
228
|
python -m pyocr_toolkit --help # same CLI without the script on PATH
|
|
177
229
|
```
|
|
178
230
|
|
|
@@ -203,8 +255,8 @@ you ask otherwise.
|
|
|
203
255
|
|
|
204
256
|
1. **Native text.** A PDF page is a list of drawing instructions ("glyph 37 at (72, 700)"). Born-digital files map
|
|
205
257
|
each glyph back to a character, so the text can be rebuilt exactly. A scan is only a picture, so it has no text.
|
|
206
|
-
2. **OCR.** The page is rendered to pixels (300 DPI) and Tesseract recognises characters
|
|
207
|
-
reporting a box for each word. That is why search can highlight OCR hits on the page.
|
|
258
|
+
2. **OCR.** The page is rendered to pixels (300 DPI) and an OCR engine (Tesseract by default) recognises characters
|
|
259
|
+
from their shapes, reporting a box for each word (or line, split into words). That is why search can highlight OCR hits on the page.
|
|
208
260
|
3. **LLM.** The page image goes to a vision model with a strict "transcribe, don't correct" prompt
|
|
209
261
|
([`prompts.py`](https://github.com/utkarsh5026/pyocr/blob/main/src/pyocr_toolkit/llm/prompts.py)). It reads in context, so it is strong on hard pages, but it can
|
|
210
262
|
"fix" typos, which the diff view exposes.
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "pyocr-toolkit"
|
|
3
|
-
version = "0.
|
|
4
|
-
description = "Inspect and compare PDF/image text extraction - native text, Tesseract
|
|
3
|
+
version = "0.6.0"
|
|
4
|
+
description = "Inspect and compare PDF/image text extraction - native text, OCR engines (Tesseract, EasyOCR, PaddleOCR, docTR, RapidOCR, Google Vision, Azure, Textract, Mistral) and LLMs (Claude, GPT, Gemini, Azure, local) - in your browser."
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
requires-python = ">=3.10"
|
|
7
7
|
license = { file = "LICENSE" }
|
|
8
8
|
authors = [{ name = "utkarsh5026" }]
|
|
9
|
-
keywords = ["ocr", "pdf", "tesseract", "llm", "document-ai", "text-extraction", "rag", "pymupdf", "claude", "openai"]
|
|
9
|
+
keywords = ["ocr", "pdf", "tesseract", "easyocr", "paddleocr", "doctr", "textract", "llm", "document-ai", "text-extraction", "rag", "pymupdf", "pypdf", "pdfplumber", "claude", "openai"]
|
|
10
10
|
classifiers = [
|
|
11
11
|
"Development Status :: 4 - Beta",
|
|
12
12
|
"Environment :: Web Environment",
|
|
@@ -35,10 +35,21 @@ dependencies = [
|
|
|
35
35
|
"anthropic>=1.0",
|
|
36
36
|
"openai>=1.40",
|
|
37
37
|
"google-genai>=1.0",
|
|
38
|
+
"httpx>=0.27",
|
|
38
39
|
]
|
|
39
40
|
|
|
40
41
|
[project.optional-dependencies]
|
|
41
|
-
dev = ["pytest>=8", "httpx>=0.27", "ruff>=0.5", "rich>=13"
|
|
42
|
+
dev = ["pytest>=8", "httpx>=0.27", "ruff>=0.5", "rich>=13",
|
|
43
|
+
"pypdf>=4", "pdfplumber>=0.11", "pdfminer.six>=20231228", "pypdfium2>=4"]
|
|
44
|
+
# Other PDF libraries to read the text layer with, next to PyMuPDF (native:<library> sources).
|
|
45
|
+
pdf = ["pypdf>=4", "pdfplumber>=0.11", "pdfminer.six>=20231228", "pypdfium2>=4"]
|
|
46
|
+
# Optional OCR engines (Tesseract needs only the system binary). Google Vision,
|
|
47
|
+
# Azure Document Intelligence and Mistral OCR need no extra packages.
|
|
48
|
+
rapidocr = ["rapidocr>=2", "onnxruntime>=1.17"]
|
|
49
|
+
easyocr = ["easyocr>=1.7"]
|
|
50
|
+
paddleocr = ["paddleocr>=3", "paddlepaddle>=3"]
|
|
51
|
+
doctr = ["python-doctr[torch]>=0.10"]
|
|
52
|
+
textract = ["boto3>=1.34"]
|
|
42
53
|
|
|
43
54
|
[project.urls]
|
|
44
55
|
Homepage = "https://github.com/utkarsh5026/pyocr"
|