pyocr-toolkit 0.7.0__tar.gz → 0.8.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.7.0 → pyocr_toolkit-0.8.0}/.env.example +4 -1
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/CHANGELOG.md +12 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/PKG-INFO +38 -1
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/README.md +35 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/pyproject.toml +3 -1
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/src/pyocr_toolkit/__init__.py +1 -1
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/src/pyocr_toolkit/api.py +34 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/src/pyocr_toolkit/cli.py +32 -11
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/src/pyocr_toolkit/config.py +5 -2
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/src/pyocr_toolkit/env.example +4 -1
- pyocr_toolkit-0.8.0/src/pyocr_toolkit/remote.py +433 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/src/pyocr_toolkit/static/common.js +79 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/src/pyocr_toolkit/static/styles.css +10 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/src/pyocr_toolkit/templates/_icons.html +1 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/src/pyocr_toolkit/templates/base.html +22 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/src/pyocr_toolkit/templates/help.html +11 -1
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/src/pyocr_toolkit/templates/home.html +3 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/src/pyocr_toolkit/templates/library.html +1 -1
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/src/pyocr_toolkit/templates/workspace_detail.html +1 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/src/pyocr_toolkit/workspaces.py +11 -3
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/tests/conftest.py +7 -0
- pyocr_toolkit-0.8.0/tests/test_remote.py +353 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/.gitignore +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/CONTRIBUTING.md +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/LICENSE +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/hero-video/README.md +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/hero-video/src/HeroDemo.tsx +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/hero-video/src/Root.tsx +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/hero-video/src/assets.d.ts +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/hero-video/src/index.ts +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/hero-video/src/motion.tsx +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/hero-video/src/scenes/CatchScene.tsx +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/hero-video/src/scenes/ColdOpenScene.tsx +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/hero-video/src/scenes/MeasureScene.tsx +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/hero-video/src/scenes/MontageScene.tsx +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/hero-video/src/scenes/OutroScene.tsx +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/hero-video/src/scenes/ThreeWaysScene.tsx +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/hero-video/src/theme.ts +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/hero-video/src/ui.tsx +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/src/pyocr_toolkit/__main__.py +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/src/pyocr_toolkit/brands.py +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/src/pyocr_toolkit/compare.py +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/src/pyocr_toolkit/credentials.py +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/src/pyocr_toolkit/documents.py +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/src/pyocr_toolkit/export.py +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/src/pyocr_toolkit/extract.py +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/src/pyocr_toolkit/jobs.py +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/src/pyocr_toolkit/llm/__init__.py +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/src/pyocr_toolkit/llm/anthropic_provider.py +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/src/pyocr_toolkit/llm/base.py +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/src/pyocr_toolkit/llm/catalog.py +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/src/pyocr_toolkit/llm/gemini_provider.py +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/src/pyocr_toolkit/llm/openai_provider.py +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/src/pyocr_toolkit/llm/prompts.py +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/src/pyocr_toolkit/ocr/__init__.py +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/src/pyocr_toolkit/ocr/base.py +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/src/pyocr_toolkit/ocr/cloud.py +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/src/pyocr_toolkit/ocr/local.py +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/src/pyocr_toolkit/ocr/tesseract.py +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/src/pyocr_toolkit/pdftext.py +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/src/pyocr_toolkit/preprocess.py +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/src/pyocr_toolkit/search.py +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/src/pyocr_toolkit/service.py +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/src/pyocr_toolkit/static/compare.js +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/src/pyocr_toolkit/static/document.js +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/src/pyocr_toolkit/static/jobs.js +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/src/pyocr_toolkit/static/leaderboard.js +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/src/pyocr_toolkit/static/library.js +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/src/pyocr_toolkit/static/logos/README.md +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/src/pyocr_toolkit/static/logos/claude.svg +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/src/pyocr_toolkit/static/logos/googlecloud.svg +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/src/pyocr_toolkit/static/logos/googlegemini.svg +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/src/pyocr_toolkit/static/logos/mistralai.svg +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/src/pyocr_toolkit/static/logos/paddlepaddle.svg +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/src/pyocr_toolkit/static/models.js +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/src/pyocr_toolkit/static/providers.js +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/src/pyocr_toolkit/static/reader.js +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/src/pyocr_toolkit/static/search.js +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/src/pyocr_toolkit/static/workspace.js +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/src/pyocr_toolkit/static/workspaces.js +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/src/pyocr_toolkit/templates/_brand.html +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/src/pyocr_toolkit/templates/_doc_card.html +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/src/pyocr_toolkit/templates/_doctabs.html +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/src/pyocr_toolkit/templates/_llm_picker.html +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/src/pyocr_toolkit/templates/_section_tabs.html +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/src/pyocr_toolkit/templates/compare.html +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/src/pyocr_toolkit/templates/document.html +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/src/pyocr_toolkit/templates/error.html +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/src/pyocr_toolkit/templates/jobs.html +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/src/pyocr_toolkit/templates/leaderboard.html +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/src/pyocr_toolkit/templates/models.html +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/src/pyocr_toolkit/templates/providers.html +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/src/pyocr_toolkit/templates/reader.html +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/src/pyocr_toolkit/templates/search.html +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/src/pyocr_toolkit/templates/workspace.html +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/src/pyocr_toolkit/templates/workspaces.html +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/src/pyocr_toolkit/web.py +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/tests/__init__.py +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/tests/test_api.py +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/tests/test_batch.py +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/tests/test_core.py +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/tests/test_extract.py +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/tests/test_makefile.py +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/tests/test_models.py +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/tests/test_ocr_engines.py +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/tests/test_pdftext.py +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/tests/test_preprocess.py +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/tests/test_providers.py +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/tests/test_web.py +0 -0
- {pyocr_toolkit-0.7.0 → pyocr_toolkit-0.8.0}/tests/test_workspaces.py +0 -0
|
@@ -52,7 +52,8 @@ GOOGLE_VISION_API_KEY=
|
|
|
52
52
|
AZURE_DOCUMENT_INTELLIGENCE_ENDPOINT=
|
|
53
53
|
AZURE_DOCUMENT_INTELLIGENCE_KEY=
|
|
54
54
|
|
|
55
|
-
# AWS Textract
|
|
55
|
+
# AWS: Textract and importing from s3:// (pip install "pyocr-toolkit[s3]").
|
|
56
|
+
# Leave these empty on EC2 / SageMaker / with ~/.aws: boto3 then finds the profile or instance role.
|
|
56
57
|
# AWS_REGION=us-east-1
|
|
57
58
|
# AWS_ACCESS_KEY_ID=
|
|
58
59
|
# AWS_SECRET_ACCESS_KEY=
|
|
@@ -65,6 +66,8 @@ MISTRAL_API_KEY=
|
|
|
65
66
|
# --- Storage, rendering and OCR ---------------------------------------------------
|
|
66
67
|
# DATA_DIR=data
|
|
67
68
|
# MAX_UPLOAD_MB=200
|
|
69
|
+
# Most files one import from S3 / web links may add
|
|
70
|
+
# IMPORT_MAX_FILES=500
|
|
68
71
|
# PREVIEW_DPI=110
|
|
69
72
|
# LLM_DPI=200
|
|
70
73
|
# LLM_MAX_EDGE_PX=2400
|
|
@@ -2,6 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 0.8.0 - 2026-11-28
|
|
6
|
+
|
|
7
|
+
- **Import from S3 and links, for running on EC2 or SageMaker.** `pyocr import s3://bucket/file.pdf`,
|
|
8
|
+
`s3://bucket/folder/` (everything under it, zips unpacked) and `https://` links (S3 presigned URLs work without
|
|
9
|
+
AWS credentials), mixed freely with local files. In the web app, use *Import from S3 or a link* on Home, on a
|
|
10
|
+
workspace page or in the Ctrl+K palette; it calls the new `POST /api/imports`. Files are copied into `DATA_DIR`
|
|
11
|
+
like uploads. S3 needs the new `[s3]` extra (boto3) and uses the standard AWS credential chain, so a laptop
|
|
12
|
+
profile, an EC2 instance role or a SageMaker execution role works with no settings. The `AWS_*` settings
|
|
13
|
+
override it. `pyocr doctor` shows which credentials were found and from where, never their values. New
|
|
14
|
+
setting: `IMPORT_MAX_FILES` (default 500). Links to cloud metadata addresses are refused.
|
|
15
|
+
- LLM prompts and cache keys are unchanged, so existing results stay valid.
|
|
16
|
+
|
|
5
17
|
## 0.7.0 - 2026-11-28
|
|
6
18
|
|
|
7
19
|
- **Calmer interface, same features.** The top bar has three sections, *Documents* (Workspaces / All files / Leaderboard),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: pyocr-toolkit
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.8.0
|
|
4
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
|
|
@@ -259,6 +259,8 @@ Requires-Dist: pypdfium2>=4; extra == 'pdf'
|
|
|
259
259
|
Provides-Extra: rapidocr
|
|
260
260
|
Requires-Dist: onnxruntime>=1.17; extra == 'rapidocr'
|
|
261
261
|
Requires-Dist: rapidocr>=2; extra == 'rapidocr'
|
|
262
|
+
Provides-Extra: s3
|
|
263
|
+
Requires-Dist: boto3>=1.34; extra == 's3'
|
|
262
264
|
Provides-Extra: textract
|
|
263
265
|
Requires-Dist: boto3>=1.34; extra == 'textract'
|
|
264
266
|
Description-Content-Type: text/markdown
|
|
@@ -490,6 +492,7 @@ pyocr compare scan.pdf -p openai -m gpt-6.2-sol # per-page OCR
|
|
|
490
492
|
pyocr extract scan.pdf -p anthropic --preprocess 'gray;auto;contrast=1.5' # adjust the image first (or a preset: clean, bw, ...)
|
|
491
493
|
pyocr extract invoice.pdf -p anthropic --mode extract --schema invoice --format json # fields, not text (or a JSON Schema file)
|
|
492
494
|
pyocr import a.pdf b.pdf scans.zip folder/ -w invoices # add many files as one workspace (zips unpacked)
|
|
495
|
+
pyocr import s3://my-bucket/scans/2024/ -w scans-2024 # every PDF/image/zip under an S3 folder (see below)
|
|
493
496
|
pyocr providers # which providers are ready
|
|
494
497
|
pyocr engines # which OCR engines are ready
|
|
495
498
|
python -m pyocr_toolkit --help # same CLI without the script on PATH
|
|
@@ -518,6 +521,40 @@ reported with the reason. A single file still uploads straight to the library. W
|
|
|
518
521
|
(`data/workspaces/<id>.json`), so removing a document from one, or deleting a workspace, keeps the document unless
|
|
519
522
|
you ask otherwise.
|
|
520
523
|
|
|
524
|
+
### Import from S3 or a link (EC2, SageMaker)
|
|
525
|
+
|
|
526
|
+
On an EC2 instance or in SageMaker, documents usually live in S3. Paste `s3://` paths or `https://` links into
|
|
527
|
+
**Import from S3 or a link** (on Home, on a workspace page, or Ctrl+K), or pass them to `pyocr import`:
|
|
528
|
+
|
|
529
|
+
```bash
|
|
530
|
+
pip install "pyocr-toolkit[s3]" # boto3, needed for s3:// only
|
|
531
|
+
pyocr import s3://my-bucket/scans/invoice-117.pdf # one file
|
|
532
|
+
pyocr import s3://my-bucket/scans/2024/ -w scans-2024 # everything under a folder (subfolders too), zips unpacked
|
|
533
|
+
pyocr import "https://my-bucket.s3.amazonaws.com/a.pdf?X-Amz-Signature=..." # a presigned URL: no AWS credentials needed
|
|
534
|
+
pyocr import local.pdf s3://my-bucket/more/ # local and remote in one workspace
|
|
535
|
+
pyocr doctor # shows which AWS credentials S3 would use, and from where
|
|
536
|
+
```
|
|
537
|
+
|
|
538
|
+
The file is fetched once and copied into `DATA_DIR`, just like an upload, so everything else works the same and the
|
|
539
|
+
document stays usable if the object is later deleted.
|
|
540
|
+
|
|
541
|
+
**Credentials.** No AWS settings are needed in most cases. boto3 checks a fixed list of places in order: environment
|
|
542
|
+
variables, `~/.aws` profiles and SSO, container credentials, and the EC2 instance metadata service. So the same command
|
|
543
|
+
uses your profile on a laptop, the instance role on EC2 and the execution role in SageMaker. `pyocr doctor` tells you
|
|
544
|
+
which one it found. The role needs `s3:GetObject`, plus `s3:ListBucket` to import a folder. The optional `AWS_*`
|
|
545
|
+
settings (shared with Textract) override the chain, and `AWS_ENDPOINT_URL_S3` points at an S3-compatible server such as MinIO.
|
|
546
|
+
|
|
547
|
+
**Limits and safety.** Each file can be up to `MAX_UPLOAD_MB`, and one import adds at most `IMPORT_MAX_FILES` files (500 by default).
|
|
548
|
+
Hidden files and unsupported types in a folder are ignored. Anything that fails (missing, access denied, expired link)
|
|
549
|
+
is listed with the reason and the rest still imports. Links to cloud metadata addresses (169.254.169.254, including
|
|
550
|
+
behind redirects) are refused, because they serve the machine's own credentials. Signatures in presigned URLs are not echoed back in messages.
|
|
551
|
+
The import endpoint has the same cross-site protection as saving credentials.
|
|
552
|
+
|
|
553
|
+
**Viewing the app from your laptop.** `pyocr serve` listens on `127.0.0.1` only (there's no login). On EC2, use an SSH
|
|
554
|
+
tunnel rather than opening the port: `ssh -L 8000:127.0.0.1:8000 ec2-user@<host>`, then browse `http://localhost:8000`.
|
|
555
|
+
SageMaker Studio's `/proxy/<port>/` path isn't supported by the web UI yet (its links assume it is served at `/`);
|
|
556
|
+
the CLI works there.
|
|
557
|
+
|
|
521
558
|
## How it works
|
|
522
559
|
|
|
523
560
|
1. **Native text.** A PDF page is a list of drawing instructions ("glyph 37 at (72, 700)"). Born-digital files map
|
|
@@ -225,6 +225,7 @@ pyocr compare scan.pdf -p openai -m gpt-6.2-sol # per-page OCR
|
|
|
225
225
|
pyocr extract scan.pdf -p anthropic --preprocess 'gray;auto;contrast=1.5' # adjust the image first (or a preset: clean, bw, ...)
|
|
226
226
|
pyocr extract invoice.pdf -p anthropic --mode extract --schema invoice --format json # fields, not text (or a JSON Schema file)
|
|
227
227
|
pyocr import a.pdf b.pdf scans.zip folder/ -w invoices # add many files as one workspace (zips unpacked)
|
|
228
|
+
pyocr import s3://my-bucket/scans/2024/ -w scans-2024 # every PDF/image/zip under an S3 folder (see below)
|
|
228
229
|
pyocr providers # which providers are ready
|
|
229
230
|
pyocr engines # which OCR engines are ready
|
|
230
231
|
python -m pyocr_toolkit --help # same CLI without the script on PATH
|
|
@@ -253,6 +254,40 @@ reported with the reason. A single file still uploads straight to the library. W
|
|
|
253
254
|
(`data/workspaces/<id>.json`), so removing a document from one, or deleting a workspace, keeps the document unless
|
|
254
255
|
you ask otherwise.
|
|
255
256
|
|
|
257
|
+
### Import from S3 or a link (EC2, SageMaker)
|
|
258
|
+
|
|
259
|
+
On an EC2 instance or in SageMaker, documents usually live in S3. Paste `s3://` paths or `https://` links into
|
|
260
|
+
**Import from S3 or a link** (on Home, on a workspace page, or Ctrl+K), or pass them to `pyocr import`:
|
|
261
|
+
|
|
262
|
+
```bash
|
|
263
|
+
pip install "pyocr-toolkit[s3]" # boto3, needed for s3:// only
|
|
264
|
+
pyocr import s3://my-bucket/scans/invoice-117.pdf # one file
|
|
265
|
+
pyocr import s3://my-bucket/scans/2024/ -w scans-2024 # everything under a folder (subfolders too), zips unpacked
|
|
266
|
+
pyocr import "https://my-bucket.s3.amazonaws.com/a.pdf?X-Amz-Signature=..." # a presigned URL: no AWS credentials needed
|
|
267
|
+
pyocr import local.pdf s3://my-bucket/more/ # local and remote in one workspace
|
|
268
|
+
pyocr doctor # shows which AWS credentials S3 would use, and from where
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
The file is fetched once and copied into `DATA_DIR`, just like an upload, so everything else works the same and the
|
|
272
|
+
document stays usable if the object is later deleted.
|
|
273
|
+
|
|
274
|
+
**Credentials.** No AWS settings are needed in most cases. boto3 checks a fixed list of places in order: environment
|
|
275
|
+
variables, `~/.aws` profiles and SSO, container credentials, and the EC2 instance metadata service. So the same command
|
|
276
|
+
uses your profile on a laptop, the instance role on EC2 and the execution role in SageMaker. `pyocr doctor` tells you
|
|
277
|
+
which one it found. The role needs `s3:GetObject`, plus `s3:ListBucket` to import a folder. The optional `AWS_*`
|
|
278
|
+
settings (shared with Textract) override the chain, and `AWS_ENDPOINT_URL_S3` points at an S3-compatible server such as MinIO.
|
|
279
|
+
|
|
280
|
+
**Limits and safety.** Each file can be up to `MAX_UPLOAD_MB`, and one import adds at most `IMPORT_MAX_FILES` files (500 by default).
|
|
281
|
+
Hidden files and unsupported types in a folder are ignored. Anything that fails (missing, access denied, expired link)
|
|
282
|
+
is listed with the reason and the rest still imports. Links to cloud metadata addresses (169.254.169.254, including
|
|
283
|
+
behind redirects) are refused, because they serve the machine's own credentials. Signatures in presigned URLs are not echoed back in messages.
|
|
284
|
+
The import endpoint has the same cross-site protection as saving credentials.
|
|
285
|
+
|
|
286
|
+
**Viewing the app from your laptop.** `pyocr serve` listens on `127.0.0.1` only (there's no login). On EC2, use an SSH
|
|
287
|
+
tunnel rather than opening the port: `ssh -L 8000:127.0.0.1:8000 ec2-user@<host>`, then browse `http://localhost:8000`.
|
|
288
|
+
SageMaker Studio's `/proxy/<port>/` path isn't supported by the web UI yet (its links assume it is served at `/`);
|
|
289
|
+
the CLI works there.
|
|
290
|
+
|
|
256
291
|
## How it works
|
|
257
292
|
|
|
258
293
|
1. **Native text.** A PDF page is a list of drawing instructions ("glyph 37 at (72, 700)"). Born-digital files map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "pyocr-toolkit"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.8.0"
|
|
4
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"
|
|
@@ -50,6 +50,8 @@ easyocr = ["easyocr>=1.7"]
|
|
|
50
50
|
paddleocr = ["paddleocr>=3", "paddlepaddle>=3"]
|
|
51
51
|
doctr = ["python-doctr[torch]>=0.10"]
|
|
52
52
|
textract = ["boto3>=1.34"]
|
|
53
|
+
# Import documents from s3:// (https:// links, S3 presigned URLs included, need nothing extra).
|
|
54
|
+
s3 = ["boto3>=1.34"]
|
|
53
55
|
|
|
54
56
|
[project.urls]
|
|
55
57
|
Homepage = "https://github.com/utkarsh5026/pyocr"
|
|
@@ -30,6 +30,7 @@ from .llm import MAX_PAGES_PER_REQUEST, PROMPT_MODES, ProviderError, build_provi
|
|
|
30
30
|
from .ocr import build_ocr_engines
|
|
31
31
|
from .pdftext import DEFAULT_TEXT_LIBRARY, native_source_id
|
|
32
32
|
from .preprocess import Preprocess, presets_json, process_bytes
|
|
33
|
+
from .remote import MAX_LOCATIONS, import_remote
|
|
33
34
|
from .service import LLMSpec, Services, ocr_source_id, parse_pages
|
|
34
35
|
from .workspaces import WorkspaceStore, ingest, suggest_names
|
|
35
36
|
|
|
@@ -134,6 +135,14 @@ class ProviderTestBody(BaseModel):
|
|
|
134
135
|
model: str | None = None
|
|
135
136
|
|
|
136
137
|
|
|
138
|
+
class ImportBody(BaseModel):
|
|
139
|
+
#: s3://bucket/key, s3://bucket/folder/ or http(s):// links (S3 presigned URLs work)
|
|
140
|
+
urls: list[str] = Field(..., min_length=1, max_length=MAX_LOCATIONS)
|
|
141
|
+
workspace_id: str | None = None
|
|
142
|
+
#: create a workspace with this name for what was imported (only if something was)
|
|
143
|
+
workspace_name: str | None = Field(None, max_length=80)
|
|
144
|
+
|
|
145
|
+
|
|
137
146
|
class CredentialsBody(BaseModel):
|
|
138
147
|
#: env var name -> new value; empty / missing = keep the current value
|
|
139
148
|
values: dict[str, str | None] = Field(default_factory=dict)
|
|
@@ -327,6 +336,31 @@ def build_api(settings: Settings, store: DocumentStore, services: Services, jobs
|
|
|
327
336
|
body["workspace"] = asdict(workspaces.get(workspace_id))
|
|
328
337
|
return body
|
|
329
338
|
|
|
339
|
+
@api.post("/imports", status_code=201, tags=["documents"])
|
|
340
|
+
def import_urls(body: ImportBody, request: Request):
|
|
341
|
+
"""Import from S3 (``s3://bucket/key``, ``s3://bucket/folder/``) or web links; zips are unpacked.
|
|
342
|
+
|
|
343
|
+
S3 uses the AWS_* settings or the standard AWS credential chain (profile, EC2 instance
|
|
344
|
+
role, SageMaker execution role). Locations that fail are listed in ``skipped`` with why.
|
|
345
|
+
Same response as ``POST /api/uploads``.
|
|
346
|
+
"""
|
|
347
|
+
_require_same_origin(request) # it fetches with this machine's AWS identity
|
|
348
|
+
if body.workspace_id: # fail before fetching anything
|
|
349
|
+
workspaces.get(body.workspace_id)
|
|
350
|
+
elif body.workspace_name and body.workspace_name.strip():
|
|
351
|
+
workspaces.check_new_name(body.workspace_name)
|
|
352
|
+
result = import_remote(store, body.urls, settings)
|
|
353
|
+
for meta in result.documents:
|
|
354
|
+
store.warm_page_stats(meta.id)
|
|
355
|
+
out = result.to_json()
|
|
356
|
+
ids = [m.id for m in result.documents]
|
|
357
|
+
if body.workspace_id:
|
|
358
|
+
ws = workspaces.add_documents(body.workspace_id, ids) if ids else workspaces.get(body.workspace_id)
|
|
359
|
+
out["workspace"] = asdict(ws)
|
|
360
|
+
elif body.workspace_name and body.workspace_name.strip() and ids:
|
|
361
|
+
out["workspace"] = asdict(workspaces.create(body.workspace_name, ids))
|
|
362
|
+
return out
|
|
363
|
+
|
|
330
364
|
@api.get("/documents/{doc_id}", tags=["documents"])
|
|
331
365
|
def document(doc_id: str):
|
|
332
366
|
return doc_summary(get_doc(doc_id))
|
|
@@ -147,8 +147,12 @@ def cmd_doctor(_args: argparse.Namespace) -> int:
|
|
|
147
147
|
except OSError as exc:
|
|
148
148
|
ok = False
|
|
149
149
|
print(f" ✗ Data dir {data} is not writable: {exc}")
|
|
150
|
+
from .remote import aws_status
|
|
151
|
+
|
|
152
|
+
s3_ready, s3_detail = aws_status(settings) # optional: a problem here is shown, not counted as a failure
|
|
153
|
+
print(f" S3 import {'✓' if s3_ready else '·'} {s3_detail}")
|
|
150
154
|
env = Path(".env")
|
|
151
|
-
print(f" .env
|
|
155
|
+
print(f" .env {'found' if env.exists() else 'not found (run `pyocr init`)'} in {Path.cwd()}")
|
|
152
156
|
ready = [p for p in services.providers.values() if p.configured]
|
|
153
157
|
print(f" LLM providers {len(ready)} of {len(services.providers)} configured")
|
|
154
158
|
for p in services.providers.values():
|
|
@@ -161,14 +165,19 @@ def cmd_doctor(_args: argparse.Namespace) -> int:
|
|
|
161
165
|
|
|
162
166
|
|
|
163
167
|
def cmd_import(args: argparse.Namespace) -> int:
|
|
168
|
+
from itertools import chain
|
|
169
|
+
|
|
164
170
|
from .documents import SUPPORTED_EXTENSIONS, DocumentError, DocumentStore
|
|
165
|
-
from .
|
|
171
|
+
from .remote import RemoteFetcher, is_remote, parse_locations
|
|
172
|
+
from .workspaces import ARCHIVE_EXTENSIONS, IngestResult, WorkspaceStore, ingest, is_archive, suggest_names
|
|
166
173
|
|
|
167
174
|
settings = get_settings()
|
|
168
175
|
store = DocumentStore(settings.documents_dir)
|
|
169
176
|
spaces = WorkspaceStore(settings.workspaces_dir, store)
|
|
177
|
+
remote_args = [a for a in args.files if is_remote(a)]
|
|
178
|
+
local_args = [Path(a) for a in args.files if not is_remote(a)]
|
|
170
179
|
paths: list[Path] = []
|
|
171
|
-
for path in
|
|
180
|
+
for path in local_args:
|
|
172
181
|
if path.is_dir():
|
|
173
182
|
wanted = SUPPORTED_EXTENSIONS | ARCHIVE_EXTENSIONS
|
|
174
183
|
paths += sorted(p for p in path.rglob("*") if p.is_file() and p.suffix.lower() in wanted
|
|
@@ -177,18 +186,30 @@ def cmd_import(args: argparse.Namespace) -> int:
|
|
|
177
186
|
paths.append(path)
|
|
178
187
|
else:
|
|
179
188
|
raise FileNotFoundError(f"no such file or folder: {path}")
|
|
180
|
-
if not paths:
|
|
189
|
+
if not paths and not remote_args:
|
|
181
190
|
raise ValueError("nothing to import: no supported files found")
|
|
182
191
|
|
|
183
|
-
|
|
192
|
+
result = IngestResult()
|
|
184
193
|
try:
|
|
194
|
+
locations = parse_locations(remote_args) if remote_args else []
|
|
195
|
+
# set up S3 / HTTP before touching the library, so a missing boto3 adds nothing
|
|
196
|
+
remote_files = RemoteFetcher(settings, result, progress=lambda label: print(f" ↓ {label}", file=sys.stderr)
|
|
197
|
+
).files(locations) if locations else iter(())
|
|
198
|
+
names = [p.name for p in local_args] + [loc.name for loc in locations]
|
|
199
|
+
grouped = not args.no_workspace and (args.workspace or len(paths) + len(locations) > 1
|
|
200
|
+
or any(is_archive(p.name) for p in paths)
|
|
201
|
+
or any(loc.is_folder for loc in locations))
|
|
185
202
|
if grouped:
|
|
186
|
-
name = args.workspace or suggest_names(
|
|
187
|
-
count=1)[0]
|
|
203
|
+
name = args.workspace or suggest_names(names, taken=[w.name for w in spaces.list()], count=1)[0]
|
|
188
204
|
ws = spaces.create(name)
|
|
189
|
-
|
|
190
|
-
|
|
205
|
+
local_files = ((p.name, p.read_bytes()) for p in paths)
|
|
206
|
+
result = ingest(store, chain(local_files, remote_files), max_bytes=settings.max_upload_mb * 1024 * 1024,
|
|
207
|
+
result=result)
|
|
208
|
+
if grouped and result.documents:
|
|
191
209
|
ws = spaces.add_documents(ws.id, [m.id for m in result.documents])
|
|
210
|
+
elif grouped:
|
|
211
|
+
spaces.delete(ws.id) # nothing came in: don't leave an empty workspace behind
|
|
212
|
+
grouped = False
|
|
192
213
|
except DocumentError as exc:
|
|
193
214
|
print(f"error: {exc}", file=sys.stderr)
|
|
194
215
|
return 2
|
|
@@ -377,8 +398,8 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
377
398
|
e.add_argument("-o", "--output", type=Path, default=None, help="file to write (default: stdout)")
|
|
378
399
|
e.set_defaults(func=lambda a: asyncio.run(_extract(a)))
|
|
379
400
|
|
|
380
|
-
m = sub.add_parser("import", help="add files, folders
|
|
381
|
-
m.add_argument("files",
|
|
401
|
+
m = sub.add_parser("import", help="add files, folders, .zip archives, s3:// paths or https:// links as one workspace")
|
|
402
|
+
m.add_argument("files", nargs="+", metavar="FILE|FOLDER|s3://bucket/key|s3://bucket/folder/|https://...")
|
|
382
403
|
m.add_argument("-w", "--workspace", default=None, help="workspace name (default: a suggested one)")
|
|
383
404
|
m.add_argument("--no-workspace", action="store_true", help="add to the library without grouping")
|
|
384
405
|
m.set_defaults(func=cmd_import)
|
|
@@ -19,6 +19,8 @@ class Settings(BaseSettings):
|
|
|
19
19
|
# --- storage / rendering -------------------------------------------------
|
|
20
20
|
data_dir: Path = Path("data")
|
|
21
21
|
max_upload_mb: int = 200
|
|
22
|
+
# Most files one import from S3 / web links may add (`pyocr import s3://...`, Import from S3 or URL).
|
|
23
|
+
import_max_files: int = 500
|
|
22
24
|
# DPI used for the page preview shown in the browser.
|
|
23
25
|
preview_dpi: int = 110
|
|
24
26
|
# DPI used for the image sent to the LLM and for Tesseract OCR.
|
|
@@ -62,8 +64,9 @@ class Settings(BaseSettings):
|
|
|
62
64
|
azure_document_intelligence_endpoint: str | None = None
|
|
63
65
|
azure_document_intelligence_key: str | None = None
|
|
64
66
|
|
|
65
|
-
# AWS Textract (DetectDocumentText)
|
|
66
|
-
# usual AWS chain (~/.aws/credentials, AWS_PROFILE,
|
|
67
|
+
# AWS: Textract (DetectDocumentText) and importing from s3://. Credentials
|
|
68
|
+
# can also come from the usual AWS chain (~/.aws/credentials, AWS_PROFILE,
|
|
69
|
+
# EC2 instance roles, SageMaker execution roles).
|
|
67
70
|
aws_region: str | None = None
|
|
68
71
|
aws_access_key_id: str | None = None
|
|
69
72
|
aws_secret_access_key: str | None = None
|
|
@@ -52,7 +52,8 @@ GOOGLE_VISION_API_KEY=
|
|
|
52
52
|
AZURE_DOCUMENT_INTELLIGENCE_ENDPOINT=
|
|
53
53
|
AZURE_DOCUMENT_INTELLIGENCE_KEY=
|
|
54
54
|
|
|
55
|
-
# AWS Textract
|
|
55
|
+
# AWS: Textract and importing from s3:// (pip install "pyocr-toolkit[s3]").
|
|
56
|
+
# Leave these empty on EC2 / SageMaker / with ~/.aws: boto3 then finds the profile or instance role.
|
|
56
57
|
# AWS_REGION=us-east-1
|
|
57
58
|
# AWS_ACCESS_KEY_ID=
|
|
58
59
|
# AWS_SECRET_ACCESS_KEY=
|
|
@@ -65,6 +66,8 @@ MISTRAL_API_KEY=
|
|
|
65
66
|
# --- Storage, rendering and OCR ---------------------------------------------------
|
|
66
67
|
# DATA_DIR=data
|
|
67
68
|
# MAX_UPLOAD_MB=200
|
|
69
|
+
# Most files one import from S3 / web links may add
|
|
70
|
+
# IMPORT_MAX_FILES=500
|
|
68
71
|
# PREVIEW_DPI=110
|
|
69
72
|
# LLM_DPI=200
|
|
70
73
|
# LLM_MAX_EDGE_PX=2400
|