Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .devcontainer/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ done
# every container build.
#
# `[dev]` is pytest and ruff, which is what a Codespace needs to run the fast
# suite. The OCR backends are separate extras: add ,easyocr ,paddle ,marker or
# suite. The OCR backends are separate extras: add ,easyocr ,paddle or
# use [all] if you need them, and expect a long install and model downloads on
# first use.
echo "Creating Python virtualenv..."
Expand Down
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pip install 'tetrak[all]' # everything, several gigabytes
`[qa]` is what turns `auto-local` on, because scoring needs a spell checker and
GPT-2 perplexity. It does not install any extra *engines* — `auto-local` picks
the best of whatever is present, so with core plus `[qa]` it is choosing
between one engine. Add `[easyocr]`, `[paddle]`, `[marker]` or `[vision]` to
between one engine. Add `[easyocr]`, `[paddle]` or `[vision]` to
give it something to choose between, or `[all]` for the lot.

Plus the system dependencies Tesseract and poppler:
Expand Down Expand Up @@ -225,11 +225,16 @@ top of them.
| `easyocr` | `[easyocr]` | ✗ | Deep-learning detector/recogniser. Handles varied contrast and awkward grounds |
| `paddle` | `[paddle]` | ✗ | Deep-learning detector/recogniser aimed at dense small text |
| `paddle-vl` | `[paddle-vl]` | ✓ | Document vision-language model. Reads PDFs and multi-page TIFFs; strongest local engine measured, but minutes per page. Join it to auto-local with `--with-paddle-vl` |
| `marker` | `[marker]` | ✓ | Layout-aware document conversion — the only local backend that models reading order |
| `marker` | withdrawn¹ | ✓ | Layout-aware document conversion — the only local backend that models reading order |
| `claude` | `[claude]` | ✓ | The Anthropic vision API. Reads material no local tool can |
| `claude-haiku` | `[claude]` | ✓ | The same API with Anthropic's smallest current model. Cheaper, and measurably worse on the material `claude` is for |
| `auto-local` | `[qa]` | ✓ | **The recommended default.** Runs the viable local engines, scores each, keeps the best |

¹ The `marker` extra is withdrawn for now. Every marker-pdf release requires
Pillow below 11, and Tetrak requires Pillow 13 for its security fixes, so the
two cannot share an environment. It comes back when marker-pdf allows Pillow
13; until then, use tetrak 5.20 or earlier for Marker.

A few things worth knowing before you pick one:

- **`tesseract-auto` over `tesseract`, always**, if you are naming a Tesseract
Expand Down
5 changes: 4 additions & 1 deletion docs/guide/backends.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ strategy built on top of them.
| `easyocr-hy` | `[armenian]` | ✗ | EasyOCR's detector with our own Armenian recogniser behind it. See [Armenian material](#armenian-material) |
| `paddle` | `[paddle]` | ✗ | Deep-learning detector and recogniser aimed at dense small text |
| `paddle-vl` | `[paddle-vl]` | ✓ | Document vision-language model. Reads PDFs and multi-page TIFFs; strongest local engine measured, but minutes per page |
| `marker` | `[marker]` | ✓ | Layout-aware document conversion, the only local backend that models reading order |
| `marker` | withdrawn | ✓ | Layout-aware document conversion, the only local backend that models reading order |
| `claude` | `[claude]` | ✓ | The Anthropic vision API. Reads material no local tool can |
| `claude-haiku` | `[claude]` | ✓ | The same API with Anthropic's smallest current model. Cheaper, and measurably worse on the material `claude` is for |
| `auto-local` | `[qa]` | ✓ | **The recommended default.** Runs the viable local engines, scores each, keeps the best |
Expand All @@ -37,6 +37,9 @@ deliberately not repeated here, where nothing would keep them current.
the fastest worth using: the model ships with macOS, so there are no
weights to download and no slow first call. It cannot read PDFs, and it
has no Armenian, Greek, Hebrew, Georgian or Indic support.
- **`marker` cannot be installed for now.** Its extra is withdrawn because
marker-pdf requires Pillow below 11 and Tetrak requires Pillow 13; see
[installation](../installation.md). Where it is available:
- **`marker` is slow and GPU-gated inside `auto-local`.** It is the only
local engine that gets multi-column newsprint into the right reading
order, and it is much the most expensive engine in the set.
Expand Down
13 changes: 11 additions & 2 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ well over a gigabyte before any model downloads at first run.
| `armenian` | `easyocr-hy` | our Armenian recogniser, as an EasyOCR custom network (pulls in EasyOCR) |
| `paddle` | `paddle` | PaddleOCR and PaddlePaddle |
| `paddle-vl` | `paddle-vl` | PaddleOCR-VL, the document vision-language model in the same package |
| `marker` | `marker` | marker-pdf 1.x |
| `marker` | `marker` | withdrawn for now; see below |
| `vision` | `vision` | `ocrmac`, a wrapper over Apple's Vision framework. macOS only |
| `claude` | `claude`, `claude-haiku` | the Anthropic SDK |
| `orientation` | `--orient armenian` | NumPy and OpenCV, which EasyOCR brings in anyway |
| `ocr` | everything above except `armenian` | |
| `ocr` | everything above except `armenian` and `marker` | |
| `all` | the same as `ocr` | |

```bash
Expand All @@ -83,6 +83,15 @@ error: The 'paddle' backend needs the 'paddleocr' and 'paddlepaddle' packages, n
Install with: pip install 'tetrak[paddle]'
```

```{note}
The `marker` extra is withdrawn for now. Every marker-pdf release, and
surya-ocr under it, requires Pillow below 11, and Tetrak requires Pillow 13
for the security fixes in that release, so the two cannot share an
environment. `tetrak-ocr backends` lists `marker` as unavailable and says
why. The extra comes back once marker-pdf allows Pillow 13. Until then,
use tetrak 5.20 or earlier for Marker, in an environment of its own.
```

```{warning}
The `marker` extra is copyleft. `marker-pdf` and its Surya models are, as of
writing, GPL-3.0, with a commercial-use exception offered by their author.
Expand Down
25 changes: 18 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ classifiers = [
# other backend pulls hundreds of megabytes to several gigabytes, and most
# users want one or two of them — so they are extras, not requirements.
dependencies = [
"Pillow>=10.0",
# 13.0 fixes the October 2026 advisories, among them heap overflows in
# the TIFF, JPEG and JPEG 2000 decoders that a crafted scan reaches
# through Image.open(). Archives send scans, so the floor is the patch.
"Pillow>=13.0",
"pytesseract>=0.3",
"pdf2image>=1.16",
"python-dotenv>=1.0",
Expand All @@ -67,11 +70,19 @@ paddle = ["paddleocr>=3.0", "paddlepaddle>=3.0"]
# here however much it sounds like it. Floors raised from `paddle`'s >=3.0:
# PaddleOCRVL does not exist before paddleocr 3.4.
paddle-vl = ["paddleocr>=3.4", "paddlex[ocr]>=3.4", "paddlepaddle>=3.2"]
# Capped below 2.0: marker-pdf 2.0 routes through an LLM and requires a
# llama-server binary installed separately (brew install llama.cpp), which
# turns a pip-only install into one with a system dependency and changes what
# the backend measures. The committed benchmark was produced with 1.x.
marker = ["marker-pdf>=1.0,<2.0"]
# The `marker` extra is withdrawn. Every marker-pdf release, and surya-ocr
# under it, requires Pillow below 11, which cannot share an environment with
# the Pillow>=13.0 floor above. The backend stays registered and says why it
# is unavailable (registry._WITHDRAWN).
#
# To bring Marker back once marker-pdf allows Pillow 13, restore:
#
# marker = ["marker-pdf>=1.0,<2.0"]
#
# add `marker` back to the `ocr` umbrella, and delete its _WITHDRAWN entry.
# The cap below 2.0 still applies: marker-pdf 2.0 routes through an LLM and
# requires a separately installed llama-server binary, which changes what the
# backend measures. The committed benchmark was produced with 1.x.
# Apple's Vision framework, via a thin PyObjC wrapper. macOS only, hence the
# marker: without it `pip install "tetrak[all]"` would fail on Linux.
# Vision itself ships with the OS, so this extra downloads a wrapper and
Expand Down Expand Up @@ -114,7 +125,7 @@ dev = ["pytest>=8.0", "pytest-cov>=5.0", "ruff>=0.5", "tetrak[orientation]"]
# Per-pipeline umbrellas. The individual extras keep their own names --
# `easyocr` and a future `whisper` do not collide, so namespacing them would
# churn CI, AGENTS.md and the devcontainer for nothing.
ocr = ["tetrak[claude,easyocr,paddle,paddle-vl,marker,vision,qa,orientation]"]
ocr = ["tetrak[claude,easyocr,paddle,paddle-vl,vision,qa,orientation]"]
all = ["tetrak[ocr]"]

[project.scripts]
Expand Down
7 changes: 6 additions & 1 deletion site/content/ocr/reference/engines.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ rather than importing it directly.
| `easyocr` | `[easyocr]` | ✗ | Varied contrast and awkward grounds |
| `paddle` | `[paddle]` | ✗ | Dense small text — but weak on this corpus |
| `paddle-vl` | `[paddle-vl]` | ✓ | Document vision-language model. Best local average, and slow enough to be batch-only |
| `marker` | `[marker]` | ✓ | Layout-aware conversion; multi-column and PDFs |
| `marker` | withdrawn | ✓ | Layout-aware conversion; multi-column and PDFs |
| `claude` | `[claude]` | ✓ | Anything the others cannot read |
| `claude-haiku` | `[claude]` | ✓ | Not escalation: the smaller model, measured and found short |
| `auto-local` | core | ✓ | Unattended mixed material; runs several and keeps the best |
Expand Down Expand Up @@ -214,6 +214,11 @@ weights (~1 GB) download on first use and cache under `~/.paddlex/`.

## Marker

The `marker` extra is withdrawn for now. Every marker-pdf release requires
Pillow below 11, and Tetrak requires Pillow 13 for its security fixes, so the
two cannot share an environment. It comes back when marker-pdf allows
Pillow 13. The measurements below were made with marker-pdf 1.x and stand.

Layout-aware document conversion, and the only local backend that models
reading order — which is why it wins the multi-column newsprint cover.

Expand Down
21 changes: 21 additions & 0 deletions src/tetrak_ocr/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,27 @@ def __init__(self, backend: str, extra: str, packages: str) -> None:
)


class BackendWithdrawnError(MissingBackendError):
"""A backend's extra has been withdrawn, so no ``pip install`` enables it.

A :class:`MissingBackendError`, so callers that fall back to another
backend still do, but the message must not name an extra that no longer
exists: pip would warn and install nothing, and the user would be back
where they started.
"""

def __init__(self, backend: str, packages: str, reason: str) -> None:
self.backend = backend
self.extra = None
self.packages = packages
self.reason = reason
OcrPipelineError.__init__(
self,
f"The '{backend}' backend needs {packages}, which this version of "
f"Tetrak cannot be installed alongside.\n{reason}",
)


class MissingFeatureError(OcrPipelineError):
"""An option was asked for whose optional dependency is not installed.

Expand Down
20 changes: 19 additions & 1 deletion src/tetrak_ocr/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from collections.abc import Callable
from pathlib import Path

from .errors import MissingBackendError, UnknownBackendError
from .errors import BackendWithdrawnError, MissingBackendError, UnknownBackendError

# name -> (module path, extra to install, human-readable requirement)
#
Expand Down Expand Up @@ -80,6 +80,22 @@

BACKENDS: tuple[str, ...] = tuple(_BACKENDS)

# Backends whose extra has been withdrawn from pyproject.toml, with what to
# tell someone who asks for one. The backend stays registered, so it runs
# wherever its package is importable, and comes back by restoring the extra
# and deleting its entry here.
_WITHDRAWN: dict[str, str] = {
# Every marker-pdf release, and surya-ocr under it, requires Pillow below
# 11. Tetrak requires Pillow 13 for its security fixes, so the two cannot
# share an environment. Restore the `marker` extra once marker-pdf allows
# Pillow 13.
"marker": (
"marker-pdf requires Pillow below 11, and Tetrak requires Pillow 13 or "
"later for its security fixes. Use tetrak 5.20 or earlier for Marker, in "
"an environment of its own."
),
}


def _load(name: str):
"""Import a backend module, raising a helpful error for unknown names."""
Expand All @@ -94,6 +110,8 @@ def _load(name: str):
# cannot run. Turn that into the actionable error here rather than letting
# a NameError surface from deep inside the call.
if extra is not None and not getattr(module, "_IMPORT_OK", True):
if name in _WITHDRAWN:
raise BackendWithdrawnError(name, packages, _WITHDRAWN[name])
raise MissingBackendError(name, extra, packages)

return module
Expand Down
28 changes: 28 additions & 0 deletions tests/ocr/test_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
from __future__ import annotations

import sys
import tomllib
import types
from pathlib import Path

import pytest

Expand Down Expand Up @@ -165,6 +167,32 @@ def test_the_error_names_the_extra_to_install(self, monkeypatch: pytest.MonkeyPa
assert "tetrak[paddle]" in message, "must give the exact install command"
assert "pip install" in message

def test_a_withdrawn_extra_is_not_offered(self, monkeypatch: pytest.MonkeyPatch) -> None:
"""pip warns and installs nothing for an extra that no longer exists,
so the error says why the backend is unavailable instead."""
stub = types.ModuleType("tetrak_ocr.backends.marker")
stub._IMPORT_OK = False
monkeypatch.setitem(sys.modules, "tetrak_ocr.backends.marker", stub)

with pytest.raises(MissingBackendError) as exc:
get_backend("marker")

message = str(exc.value)
assert "tetrak[marker]" not in message
assert "Pillow" in message

def test_every_withdrawn_extra_is_absent_from_pyproject(self) -> None:
"""Restoring an extra means deleting its _WITHDRAWN entry, or the
error would go on saying it cannot be installed."""
from tetrak_ocr import registry

pyproject = Path(__file__).resolve().parents[2] / "pyproject.toml"
extras = tomllib.loads(pyproject.read_text(encoding="utf-8"))["project"][
"optional-dependencies"
]
for name in registry._WITHDRAWN:
assert registry._BACKENDS[name][1] not in extras

def test_is_available_reports_false_without_raising(
self, monkeypatch: pytest.MonkeyPatch
) -> None:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_install_targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def test_every_shipped_extra_gets_an_sbom(self) -> None:
"""A consumer-facing extra with no SBOM is the failure this prevents."""
found = {t["target"] for t in targets(TOOL.parent.parent / "pyproject.toml")}

assert {"core", "all", "claude", "easyocr", "marker", "paddle", "qa", "vision"} <= found
assert {"core", "all", "claude", "easyocr", "paddle", "qa", "vision"} <= found
assert "dev" not in found and "docs" not in found and "apidocs" not in found

def test_the_matrix_is_valid_json_for_actions(self) -> None:
Expand Down
Loading