Tesseract OCR Libraries
& wrappers.
A working, comparable reference to the libraries and wrappers for every major language — what to install, a minimal example, and the trade-offs between native bindings and CLI wrappers.
Which library should I use?
Pick the row for your language, then read the section below.
| Language | Recommended | Type | Notes |
|---|---|---|---|
| Python | pytesseract | CLI wrapper | Simplest; see the Python guide. Use tesserocr for in-process speed. |
| JavaScript / TypeScript | tesseract.js | WASM | Runs in browser and Node; no PDF support. |
| C++ | TessBaseAPI | Native | The core API; maximum control. |
| Java | Tess4J | JNA binding | Needs the native libraries on the classpath. |
| Go | gosseract | cgo binding | Requires libtesseract-dev. |
| C# / .NET | Tesseract (.NET) | Native wrapper | NuGet package; bundles native binaries. |
| Rust | leptess | Native binding | Links against Leptonica + Tesseract. |
| PHP | thiagoalessio/tesseract_ocr | CLI wrapper | Composer package. |
Python
The largest ecosystem: a CLI wrapper plus several native bindings.
pytesseract— the standard CLI wrapper. Easy, but spawns a process per call.tesserocr— native binding to the C++ API; faster in-process, requireslibtesseract-dev.pyocr— a wrapper supporting multiple engines.aiopytesseract— async wrapper for concurrent workloads.
pip install pytesseract pillow
import pytesseract
from PIL import Image
print(pytesseract.image_to_string(Image.open("image.png")))Full walkthrough: Tesseract OCR in Python (pytesseract).
JavaScript / TypeScript
tesseract.js brings the engine to the browser and Node through WebAssembly.
npm install tesseract.js
const Tesseract = require('tesseract.js');
Tesseract.recognize('image.png', 'eng', { logger: m => console.log(m) })
.then(({ data: { text } }) => console.log(text));Note: tesseract.js does not support PDF files and does not modify the recognition model. For Node-only use, node-tesseract-ocr wraps the installed CLI instead.
C++
The native TessBaseAPI is the reference integration and what most bindings wrap.
#include <tesseract/baseapi.h>
#include <leptonica/allheaders.h>
tesseract::TessBaseAPI* api = new tesseract::TessBaseAPI();
api->Init(NULL, "eng");
Pix* image = pixRead("image.png");
api->SetImage(image);
char* text = api->GetUTF8Text();
printf("%s", text);
api->End(); pixDestroy(&image);Build against libtesseract-dev and libleptonica-dev (see installation).
Java
Tess4J is the mature JNA wrapper; JavaCPP presets are an alternative.
// Maven: net.sourceforge.tess4j:tess4j
import net.sourceforge.tess4j.Tesseract;
Tesseract t = new Tesseract();
t.setDatapath("tessdata");
String text = t.doOCR(new java.io.File("image.png"));Go
gosseract uses cgo to link against the Tesseract C++ library.
go get github.com/otiai10/gosseract/v2
import "github.com/otiai10/gosseract/v2"
client := gosseract.NewClient()
defer client.Close()
client.SetImage("image.png")
text, _ := client.Text()Requires libtesseract-dev and libleptonica-dev (Linux) or the Homebrew packages (macOS).
C# / .NET
The Tesseract NuGet package wraps the native library and ships binaries.
// dotnet add package Tesseract
using Tesseract;
using var engine = new TesseractEngine(@"./tessdata", "eng", EngineMode.Default);
using var img = Pix.LoadFromFile("image.png");
using var page = engine.Process(img);
Console.WriteLine(page.GetText());Other languages
Community bindings exist for most ecosystems.
- Rust —
leptess(native binding),rusty-tesseract(CLI wrapper). - PHP —
thiagoalessio/tesseract_ocr(Composer, CLI wrapper). - Ruby —
rtesseract(CLI wrapper). - C — the Tesseract C API (
tesseract/capi.h).
CLI wrapper vs native binding
The choice matters more than the language for performance.
| Factor | CLI wrapper | Native binding |
|---|---|---|
| Setup | Easy — just install the engine | Needs dev headers/libraries |
| Speed per call | Slower (process per call) | Faster (in-process) |
| Control | CLI flags and config only | Full API (iterators, boxes, confidence) |
| Examples | pytesseract, rtesseract, node-tesseract-ocr | tesserocr, Tess4J, gosseract, TessBaseAPI |
For one-off scripts, a CLI wrapper is usually the fastest path. For high-volume or latency-sensitive services, prefer a native binding or batch through the CLI (see the performance notes).
Libraries FAQ
Which Tesseract library should I use?
Match the row in the table above to your language. Use a native binding for speed and control, a CLI wrapper for simplicity.
Do I need the engine installed separately?
Yes for most wrappers — they rely on the installed Tesseract engine and language data. Only tesseract.js bundles a WebAssembly build of the engine.
Does tesseract.js support PDFs?
No. It recognises images; convert PDF pages to images first, or use a library that adds PDF support.
Which is fastest?
Native in-process bindings such as tesserocr, Tess4J and gosseract avoid per-call process startup. For CLI wrappers, batch pages and use multiprocessing.
Next steps
Install the engine, then pick your language.