Using the command line

Installing the package provides one command, tetrak-ocr, with five subcommands:

Subcommand

What it does

backends

List every backend and whether this environment can run it

ocr

Transcribe a single file, to stdout or to files beside it

batch

Transcribe everything in workspace/scans/

triage

List what batch held back, or serve it as a local page

evaluate

Benchmark backends against the evaluation corpus (needs a checkout)

tetrak-ocr --help and tetrak-ocr <subcommand> --help list every flag; the command line reference has the same text. This page is about what the flags are for.

Errors the package raises itself are printed as one line beginning error: with the thing to do about it, such as which extra to install, and the command exits 1. Unrecognised arguments exit 2.

tetrak-ocr backends

$ tetrak-ocr backends
 ✓ tesseract
 ✓ tesseract-auto
 · claude  (extra not installed)
 · claude-haiku  (extra not installed)
 ✓ auto-local

✓ means installed and usable; · means the optional extra is missing. The check is “can this actually run”, not “is the package present”: auto-local reports as missing without the qa extra, and paddle-vl reports as missing when paddleocr is installed but the pipeline it builds cannot be constructed.

tetrak-ocr ocr

Transcribe one file. The default is stdout; --output writes a file instead.

tetrak-ocr ocr scan.jpg
tetrak-ocr ocr scan.jpg --backend tesseract-auto
tetrak-ocr ocr programme.pdf --backend marker --output programme.md
tetrak-ocr ocr faded.jpg --contrast 3.5 --psm 6

--backend defaults to tesseract. Choosing a backend is about which to name; the short answer is tesseract-auto over tesseract whenever you are naming a Tesseract backend by hand, and auto-local when you would rather not choose.

--format and the --pdf flags, described under output formats below, write files beside the source under its stem and leave stdout alone. With one format, --output names that file instead; with more than one there is no single file to name, so the combination is refused. --pdf also takes an optional path, so a PDF can be named either way:

tetrak-ocr ocr scan.jpg --pdf                       # scan.pdf beside it
tetrak-ocr ocr scan.jpg --pdf catalogue-ready.pdf   # or name it
tetrak-ocr ocr scan.jpg --format pdf --output catalogue-ready.pdf   # the same
tetrak-ocr ocr scan.jpg --format text --output transcript.txt

Without --format, --output writes the bare transcript, whatever the file is called.

--orient turns a page upright before reading it, as batch does; see turning pages upright. It reports what it did on stderr, so stdout stays the transcript.

tetrak-ocr batch

The pipeline’s normal mode. It uses three directories under workspace/, resolved against your current working directory, so run it from the folder holding your scans:

workspace/
  scans/       input: put files here
  processed/   output: transcript plus the original, side by side
  triage/      quarantine: files whose transcript was too poor to trust
tetrak-ocr batch --backend auto-local

For each supported file in workspace/scans/, the pipeline runs OCR, writes workspace/processed/<name>.md, and moves the original to workspace/processed/<name>.<ext>. Keeping the transcript beside its source means a transcript is never orphaned from the image it came from, and workspace/scans/ being empty afterwards means “what is still to do?” is a question with an answer.

Only extensions the chosen backend supports are picked up. EasyOCR, PaddleOCR and Vision skip PDFs, because they cannot read them; a dry run shows what would be skipped.

The exit code is 0 when every file was processed or triaged, and 1 if any file raised an error or workspace/scans/ does not exist. Errors on one file do not stop the batch: the file is reported and the run carries on.

The triage queue

auto-local refuses to return a transcript whose quality score falls below the floor (0.10, MIN_QUALITY_THRESHOLD). When that happens the batch pipeline diverts the file to workspace/triage/ along with three kinds of file, so you can decide whether to rescan, send it to Claude, or transcribe by hand:

File

What it holds

<stem>.md

A manifest for reading: which backends were tried, their scores, and the first 500 characters of each transcript

<stem>.json

A record for software: every candidate’s score, the reason the file was held, when, and where each full transcript is

<stem>.<backend>.txt

Each candidate’s transcript, whole

tetrak-ocr triage lists the queue from the records.

A file that is refused before any decoder reads it goes to the same queue: a PostScript file called .png, a page over the pixel limit, a PDF with JavaScript, each decided by sillybos before a decoder opens the file. Its manifest and record carry the refusal as the reason (“says PNG, is PostScript”), with no transcript and no scores, and it counts as triaged rather than as an error, so the exit code stays 0 and the file is not left in workspace/scans/ for the next run to refuse again.

--quality-gate applies the same threshold to any single named backend:

tetrak-ocr batch --backend tesseract-auto --quality-gate

It is opt-in for single backends because it changes which files reach workspace/processed/. It needs the qa extra, which is checked before the first file rather than discovered halfway through a run.

The scoring reads English, and only English: it counts recognised English words and measures GPT-2 perplexity. A transcript in another script would score 0.0 however well it was read, so the gate is skipped, with a message, for transcripts that are not in the Latin script rather than sending a whole Armenian run to triage. auto-local’s own gate applies the same rule to its winning transcript, and the manifest records skipped either way.

The run log

Every batch appends to workspace/telemetry.jsonl, one JSON object per line, flushed per line, so tail -f is a live progress view:

tail -f workspace/telemetry.jsonl

auto-local prints its score table only after every backend has finished, so without this a forty-minute file is indistinguishable from a hung one. The log carries run_start, file_start, one backend_finish per engine in the fan-out, page_finish when a document is transcribed page by page, file_finish and run_finish, each with the file’s path, size, type and page count, and each backend’s elapsed seconds.

{"event": "backend_finish", "file": "camera-1919.pdf", "backend": "marker",
 "seconds": 2246.8, "score": 0.31, "pages": 10, "bytes": 3475030}

Because it accumulates, the log is also the dataset for asking which engines are worth their time on your material:

# median seconds per backend, slowest first
jq -rs 'map(select(.event=="backend_finish"))
        | group_by(.backend)[]
        | [.[0].backend, (length), (map(.seconds) | add / length | floor)]
        | @tsv' workspace/telemetry.jsonl | sort -k3 -rn

Flag

Effect

--telemetry PATH

Write the log somewhere other than the default

--no-telemetry

Do not write it

TETRAK_NO_TELEMETRY=1

The same, as an environment variable

A logging failure never fails a run: the log disables itself, warns once, and the batch carries on.

The CSV manifest (beta)

--manifest appends a row per file to workspace/manifest.csv: what was read, by which engine, what the quality gate made of it, and where the files are now. The run log is for watching a run and measuring it; the manifest is for the people who receive its output, to open in a spreadsheet or to import into a collections system that takes a CSV, such as Omeka S’s CSV Import.

It is not the triage manifest above: that is one report per triaged file; this is one table for the whole workspace.

tetrak-ocr batch --backend auto-local --pdf --manifest

Two of its rows, with the transcript shortened:

file,status,backend,engine,quality,quality_gate,transcript,outputs,location,note,run,finished_at,tetrak_version
graumans-chinese-theatre.jpg,processed,auto-local,vision,0.2356,passed,"THE CHINESE THEATRE. HOLLYWOOD. …",processed/graumans-chinese-theatre.md;processed/graumans-chinese-theatre.pdf,processed/graumans-chinese-theatre.jpg,,20261016T135228Z-5c09,2026-10-16T13:52:37+00:00,5.14.1
inside-facts-1930-cover-ruined.jpg,triage,auto-local,vision,0.0724,failed,,triage/inside-facts-1930-cover-ruined.md,triage/inside-facts-1930-cover-ruined.jpg,"Best transcript (vision, score=0.0724) is below threshold 0.1000",20261016T135228Z-5c09,2026-10-16T13:52:48+00:00,5.14.1

Column

What it holds

file

The scan’s file name, as it was in scans/

status

processed, triage or error

backend

The backend the run asked for

engine

The engine whose transcript was kept or rejected: under auto-local, the one that won

quality

The transcript’s quality score, when it was scored

quality_gate

passed, failed, skipped (not in the Latin script, so not scoreable) or off

transcript

The full transcript. Empty for a file in triage, so importing the manifest never imports a rejected reading

outputs

The files written for it, relative to workspace/, separated by ;

location

Where the scan is now, relative to workspace/

note

Why a file went to triage, or what went wrong

run

The run’s id in the run log, when there is one

finished_at

When the file finished, in UTC

tetrak_version

The Tetrak release that read it

It is appended to across runs, as workspace/processed/ grows, and every file gets a row whatever became of it, so the manifest is also the list of what still needs a person. --manifest PATH writes it elsewhere.

It is a beta. The columns may change before it is declared stable, so read them by the header, not by position. A manifest whose header differs from this version’s is refused before any scan is touched; move it aside, or name a new file. Comments on what the columns should be are welcome.

The file is UTF-8 without a byte-order mark, which is what import tools expect. Excel guesses the encoding of a CSV opened by double-clicking it and can get non-Latin transcripts wrong; open it with Data > From Text/CSV instead.

Dry runs

tetrak-ocr batch --backend tesseract --dry-run

Lists what would be processed without touching anything, and, just as useful, what would be skipped because the chosen backend cannot read it. The pipeline filters workspace/scans/ by the backend’s supported extensions, so a PDF simply vanishes under easyocr or paddle; a dry run is where that becomes visible.

No OCR runs and nothing is moved, but the chosen backend’s package does have to be installed: the file list depends on which extensions that backend declares it can read.

Turning pages upright

tetrak-ocr batch --backend tesseract-auto --orient latin
tetrak-ocr batch --backend easyocr-hy --orient armenian

Scans come in on their side or upside down (microfilm shot however the pages lay, a postcard turned on the glass), and an engine reading a page that is not upright returns nonsense or nothing. --orient reads which way up each page is from the ink on it, and turns the page before the engine sees it. It asks two questions:

  1. Do the lines of text run across or down? This works for any script.

  2. With the lines across, which way is up? This depends on the script, which is why you name it. For latin, more ink sits above a line of writing than below it (ascenders and capitals against descenders). For armenian that is not true, and what tells is which way the open sides of the letters face. Each measure is wrong on the other script, so name the script the pages are in. A page that is half one and half the other, such as a bilingual dictionary, reads as whichever script the measure knows.

The article Which way up is Armenian? has the measurements behind both.

A page is turned only when both answers are clear. Turning an upright page upside down would be worse than leaving a sideways one alone, so a blank leaf, a dark frame or a reading too near even is read as it is, and the batch says so by name:

  Processing: frame-0042.tif
    turned 90° clockwise to read
  Processing: frame-0043.tif
    orientation unsure (no text to read); read as it is

The scan itself is never changed. The engine reads a turned copy, a searchable PDF embeds that copy so its text layer lines up with the page it shows, and the original moves to workspace/processed/ exactly as it arrived. The manifest’s note column and the run log’s orientation event record what was done. Only single-page files are checked; a PDF or a multi-page TIFF is read as it is. --orient armenian needs the orientation extra (pip install 'tetrak[orientation]'); latin needs nothing beyond the core install.

Tuning Tesseract

tetrak-ocr batch --backend tesseract --contrast 3.0 --psm 6
tetrak-ocr batch --backend tesseract --auto

--contrast (default 2.0; try 3.0 for faded originals) and --psm (default 3; 3 is automatic layout, 6 a single uniform block, 11 sparse text) apply to the Tesseract backends only. Passing them with another backend prints a note rather than silently ignoring them. --auto picks both per image from the image’s own statistics and is usually better than either default; naming tesseract-auto is the same thing. A value you give explicitly wins over the automatic one.

Adding PaddleOCR-VL to the pool

tetrak-ocr batch --backend auto-local --with-paddle-vl

PaddleOCR-VL measures as the strongest local backend and wins where the rest of the pool is weakest, on dense multi-column pages, but it costs minutes per page rather than seconds, and fan-out would pay that on every file. So it is opt-in. The flag needs the paddle-vl extra and only means anything to auto-local; to run the engine on its own, name it with --backend paddle-vl.

Output formats

One OCR pass can be written several ways. --format (or -f) names the set; it is repeatable and comma-separated, and md, txt, plain and plaintext are accepted as aliases.

Format

Writes

For

markdown

<name>.md

The default: the transcript under a heading

text

<name>.txt

Bare transcript, for anything that will parse it

pdf

<name>.pdf

Invisible text layer over the scan, for catalogue indexing

tetrak-ocr batch --backend auto-local --format markdown,pdf
tetrak-ocr batch --backend auto-local -f markdown -f pdf   # identical
tetrak-ocr batch --backend auto-local --format text        # .txt only

--format is a full specification: naming pdf alone writes a PDF and no Markdown. The OCR runs once regardless of how many formats are asked for, so the second and third cost a file write rather than another pass.

--pdf predates it and stays additive, so existing commands keep working: on batch it means --format markdown,pdf, and combined with --format it adds pdf to whatever was named. On ocr, which writes nothing unless asked, --pdf writes the PDF and nothing else.

Searchable PDFs

The pdf format writes the scan with the transcript embedded as an invisible text layer. That single file is what makes a transcript indexable in Preservica Starter, CONTENTdm, Omeka and AtoM without asking a vendor for anything, and it is the accessibility output too: the layer an indexer reads is the layer a screen reader reads.

The PDF is an access copy: images past 2400px on the long edge are downsampled and JPEG-encoded, which takes a 1.1 MB postcard scan to a PDF an institution can actually serve. --pdf-full-size embeds the source untouched instead, for when the PDF is the deliverable rather than a derivative. Both flags imply --pdf.

The text layer carries whichever backend’s transcript the run produced, so it matches the .md sidecar exactly. Read it back with pdftotext -raw; plain pdftotext reflows and de-hyphenates, so the two will not look identical through it.

The text is laid over the page rather than positioned word by word, so selecting text in a viewer will not align with the words on the scan. That is deliberate: a word-positioned layer measured markedly worse on reading order, the thing a screen reader announces, on multi-column material.

Warning

Scripts the font cannot encode. The built-in font covers Western European text; a system Unicode font is used automatically where one is needed and present. Where neither can encode the transcript the PDF is refused, because the alternative is a page of black boxes that extracts as nothing. Point --pdf-font at a TrueType font that covers the script.

Multi-page documents

A searchable PDF needs one transcript per page; a backend returns one per document. So the pdf format on a multi-page PDF or TIFF transcribes it page by page, splitting the document into single pages, which keeps the text layer that Marker reads instead of OCR-ing, then laying each page’s words onto the page they came from.

That costs roughly twice the OCR time, and it is inherent per-document work in the engine rather than overhead that can be removed. It is paid only when both conditions hold: the pdf format was requested, and the document has more than one page.

tetrak-ocr batch --backend auto-local --pdf   # multi-page: ~2x, gets a PDF
tetrak-ocr batch --backend auto-local         # multi-page: normal speed, no PDF

The .md and .txt come from the same pass with the pages joined, so no document is ever transcribed twice. When the per-page route is taken the run says so, and the log records each page as it lands:

Processing: king-of-kings-souvenir-1927.pdf
  21 pages, transcribing individually for the PDF

Naming. A PDF transcribed to a searchable PDF is written as <stem>.searchable.pdf. It would otherwise collide with the original, which the batch pipeline moves into the same directory, and one would silently overwrite the other. Non-PDF sources keep the plain <stem>.pdf.

tetrak-ocr triage

What batch held back, from the records in workspace/triage/: each file, its best score, the engine that produced it and the reason it was held.

tetrak-ocr triage                     # a table in the terminal
tetrak-ocr triage --serve             # the same as a page, at http://127.0.0.1:8321/
tetrak-ocr triage --serve --port 9000
tetrak-ocr triage --dir ../other/triage

--serve binds to the loopback address and nothing else, and there is no flag to change that. The page reads a local directory for the person at the machine, so there is nothing to authenticate and nothing remote, and it answers one address, /, with GET; it serves no files. It is read-only: triage stays passive, and the page re-reads the directory on every request, so it follows a batch that is still running. Stop it with Ctrl-C.

A directory written by a release before 5.19 holds manifests without records. Those files are still listed, by name, with a note to read the manifest; an empty or missing directory is reported as empty rather than as an error.

tetrak-ocr evaluate

Benchmark backends against the evaluation corpus: every fixture is transcribed and scored against its committed ground truth on character similarity and word recall.

tetrak-ocr evaluate --backend tesseract-auto
tetrak-ocr evaluate --all
tetrak-ocr evaluate --all --save
tetrak-ocr evaluate --backend vision --save --merge

This one needs a checkout of the repository: the corpus is not shipped in the package, and running it elsewhere says so rather than failing obscurely. --all runs every backend you have installed, side by side. --save writes evaluation/ocr/benchmark.{csv,md} plus a dated, git-linked snapshot under evaluation/ocr/runs/. --merge, for a single-backend run, splices that backend’s column into the committed benchmark without re-measuring the others, which costs hours and real API spend on claude; it refuses if the corpus has changed since.

The flags are passed straight through to the harness, so tetrak-ocr evaluate --help prints the harness’s own help.

Note

--save overwrites the committed benchmark with whatever it managed to run. On a partial install, keep the output rather than committing it.