Skip to main content

A lightweight, unified OCR toolkit with a one-liner API. Supports Surya, EasyOCR, PaddleOCR, Tesseract, and Vision LLMs through a single interface.

Project description

anyocr

OCR made simple — one API, many backends

PyPI Python License

A lightweight, unified OCR toolkit with a one-liner API. Supports multiple backends (Surya, EasyOCR, PaddleOCR, Tesseract) through a single interface.

Runs completely offline after first model download. OCR models are cached locally and no internet connection is required for subsequent use.

Author: Viet-Anh Nguyen | GitHub


Features

  • One-liner API -- anyocr.read("image.png") and you're done
  • Multiple backends -- EasyOCR, PaddleOCR, Tesseract, all through one interface
  • Auto-detection -- automatically selects the best available backend
  • Flexible input -- accepts file paths, numpy arrays, PIL Images, bytes, or URLs
  • Batch processing -- process multiple images efficiently
  • Preprocessing -- built-in image enhancement for better accuracy
  • Type-safe -- full type hints and dataclass results

Installation

Install the core package (no OCR backend):

pip install anyocr

Then install your preferred backend(s):

# EasyOCR -- recommended for general use
pip install anyocr[easyocr]

# PaddleOCR -- best for CJK languages
pip install anyocr[paddle]

# Tesseract -- widest language support (requires tesseract system package)
pip install anyocr[tesseract]

# Install all backends
pip install anyocr[all]

Tesseract system dependency

If using the Tesseract backend, you also need the system binary:

# Ubuntu/Debian
sudo apt install tesseract-ocr

# macOS
brew install tesseract

# Windows -- download from https://github.com/UB-Mannheim/tesseract/wiki

Quick Start

import anyocr

# Auto-selects best available OCR backend (Surya > EasyOCR > PaddleOCR > Tesseract)
# Preprocesses image: deskew, contrast enhancement, binarization
# Returns OCRResult with .text (full text) and .lines (list of TextLine with bbox and confidence)
result = anyocr.read("document.png")
print(result.text)

# Use a specific backend — bypasses auto-selection
result = anyocr.read("document.png", backend="easyocr")

# Multi-language support — pass ISO language codes recognized by the backend
result = anyocr.read("document.png", lang=["en", "vi"])

# Access detailed results — each TextLine has bounding box coordinates and confidence
for line in result.lines:
    print(f"Text: {line.text}")
    print(f"  BBox: {line.bbox}")
    print(f"  Confidence: {line.confidence:.2f}")

# Batch processing — reuses the loaded backend model across all images
results = anyocr.read_batch(["page1.png", "page2.png", "page3.png"])

# Check available backends
print(anyocr.available_backends())  # e.g. ['easyocr', 'tesseract']

# Set default backend
anyocr.set_default_backend("easyocr")

Flexible image input

import anyocr
from PIL import Image
import numpy as np

# File path
result = anyocr.read("photo.jpg")

# PIL Image
img = Image.open("photo.jpg")
result = anyocr.read(img)

# Numpy array
arr = np.array(img)
result = anyocr.read(arr)

# Bytes
with open("photo.jpg", "rb") as f:
    result = anyocr.read(f.read())

# URL
result = anyocr.read("https://example.com/image.png")

Preprocessing

import anyocr

# Enable preprocessing for scanned documents
result = anyocr.read(
    "scan.png",
    do_preprocessing=True,
    do_deskew=True,
    do_enhance_contrast=True,
    contrast_factor=1.8,
)

Backend Comparison

Feature EasyOCR PaddleOCR Tesseract
Speed Medium Fast Fast
Accuracy High Very High Good
Languages 80+ 80+ 100+
GPU support Yes Yes No
CJK quality Good Excellent Fair
Setup pip only pip only System binary required
Model size Large Medium Small
Best for General use CJK / documents Legacy systems

Supported Languages

All backends support English. For other languages:

  • EasyOCR: 80+ languages including Vietnamese, Chinese, Japanese, Korean, Thai, Arabic, Hindi, and more. Full list
  • PaddleOCR: 80+ languages with excellent CJK support. Full list
  • Tesseract: 100+ languages. Install additional language packs via your system package manager. Full list

API Reference

anyocr.read(image, backend=None, lang=None, do_preprocessing=False, **kwargs)

Read text from a single image.

  • image -- file path, numpy array, PIL Image, bytes, or URL
  • backend -- "easyocr", "paddleocr", "tesseract", or None (auto-select)
  • lang -- list of language codes, e.g. ["en", "vi"]
  • do_preprocessing -- enable image preprocessing pipeline
  • Returns: OCRResult

anyocr.read_batch(images, **kwargs)

Read text from multiple images. Same options as read().

anyocr.available_backends()

Returns a list of installed backend names.

anyocr.set_default_backend(name)

Set the default backend for all subsequent calls.

OCRResult

  • .text -- full recognized text (lines joined by newlines)
  • .lines -- list of TextLine objects
  • .confidence -- average confidence score
  • .backend -- name of the backend used
  • .language -- language codes used

TextLine

  • .text -- recognized text
  • .bbox -- bounding box as (x_min, y_min, x_max, y_max)
  • .confidence -- confidence score (0.0 to 1.0)

Local-First / Edge AI

This package is designed to work completely offline. After initial model download, no internet connection is required.

# Pre-download models for offline use
python -m anyocr download

# Download models for specific languages
python -m anyocr download --lang en,vi

# Download for a specific backend
python -m anyocr download --backend easyocr --lang en
import anyocr

# Pre-download English models for the default backend
anyocr.download_models(lang=["en"])

# Pre-download for a specific backend and languages
anyocr.download_models(lang=["en", "vi"], backend="easyocr")

Development

git clone https://github.com/vietanhdev/anyocr.git
cd anyocr
pip install -e ".[dev]"
pytest tests/ -v

License

MIT License. See LICENSE for details.


Built by Viet-Anh Nguyen | NRL.ai

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

anyocr-0.2.2.tar.gz (38.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

anyocr-0.2.2-py3-none-any.whl (33.4 kB view details)

Uploaded Python 3

File details

Details for the file anyocr-0.2.2.tar.gz.

File metadata

  • Download URL: anyocr-0.2.2.tar.gz
  • Upload date:
  • Size: 38.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for anyocr-0.2.2.tar.gz
Algorithm Hash digest
SHA256 0b848a31598907e48c143571bf2996cb11418733e2da868aeb35718c0927b359
MD5 8748e9dd81fb63fd8a931b070a861b8f
BLAKE2b-256 e4e0e074213a6ac036e0aa1c0081075a9b99a35234133ef1b98958e1500989e7

See more details on using hashes here.

File details

Details for the file anyocr-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: anyocr-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 33.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for anyocr-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 41f7a1c60c8b92123027e65a491181ef4b3bd15e4b0f6a8aa1f3d48fd1f20c36
MD5 9e46e3a542eafa590615d5b961566aeb
BLAKE2b-256 6064506b8966ffa80bd0375459ddc7a96ee3fdbd31d467cee5bd7d2a52e9daff

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page