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

# 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.1.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.1-py3-none-any.whl (33.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: anyocr-0.2.1.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.1.tar.gz
Algorithm Hash digest
SHA256 e95a86d43cdc65d3034ecc4c740204af59a25a96ef6d3de33e7413e5ffea7d24
MD5 8c1f975c659ab47e1f18f68112d55e99
BLAKE2b-256 bf7fd52f7e36b8c19f6d3d46e99994e63ffe938f9c075ff05f499135ba0b5c80

See more details on using hashes here.

File details

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

File metadata

  • Download URL: anyocr-0.2.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4e557c6229d35c6eaf89291213a0090f647f0786b725b8abf0000b227fb39b53
MD5 95e1570994a09e1dd787cf6fcc6004ad
BLAKE2b-256 f848d91e4b6fe48a4896de9fbcc33d129fb2999e775c96f1c5bf1a79fb0a508a

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