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

anyocr logo

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

# Read text from an image (auto-selects best available backend)
result = anyocr.read("document.png")
print(result.text)

# Use a specific backend
result = anyocr.read("document.png", backend="easyocr")

# Multi-language support
result = anyocr.read("document.png", lang=["en", "vi"])

# Access detailed results
for line in result.lines:
    print(f"Text: {line.text}")
    print(f"  BBox: {line.bbox}")
    print(f"  Confidence: {line.confidence:.2f}")

# Batch processing
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.0.tar.gz (38.2 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.0-py3-none-any.whl (33.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: anyocr-0.2.0.tar.gz
  • Upload date:
  • Size: 38.2 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.0.tar.gz
Algorithm Hash digest
SHA256 061d1a183ef31862cfc944eaf56ae6899c6fb56976c19af08fc9d01c31d0096f
MD5 48779caa581485aa0c74ccdbd27c8ac8
BLAKE2b-256 3d71504a8c429ecd3436db1b61e4c017d591430fa7f4a4f1a299f0684a0e8403

See more details on using hashes here.

File details

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

File metadata

  • Download URL: anyocr-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 33.3 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fb542de2c2cdef9e5e2fb74354e9d3bb636a4cd5ebb1bd1a54fc33221710bf46
MD5 692b7df53ef4ffbc6cd2ac484f3537c7
BLAKE2b-256 a9090e7257cefee7afbfd5e053b05c1656225f273cda6486ba849ff9fcf332f6

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