Skip to main content

Swarmauri Tesseract Image to Text Model

Project description

Swarmauri Logo

PyPI - Downloads Hits PyPI - Python Version PyPI - License PyPI - swarmauri_ocr_pytesseract


Swarmauri OCR Pytesseract

OCR adapter for Swarmauri built on top of PyTesseract. Accepts paths, bytes, or PIL images, and exposes synchronous, async, and batch APIs for extracting text.

Features

  • Wraps Tesseract OCR via PyTesseract behind Swarmauri's OCRBase interface.
  • Supports multiple languages (language parameter) and custom Tesseract configs.
  • Handles individual, async, and batched OCR calls with optional concurrency limits.
  • Helper to list installed Tesseract languages through get_supported_languages().

Prerequisites

  • Python 3.10 or newer.
  • Tesseract OCR installed on the host (tesseract binary reachable on PATH or via TESSERACT_CMD).
  • pytesseract, Pillow, and related dependencies (installed automatically with this package).

Installation

# pip
pip install swarmauri_ocr_pytesseract

# poetry
poetry add swarmauri_ocr_pytesseract

# uv (pyproject-based projects)
uv add swarmauri_ocr_pytesseract

Quickstart

from swarmauri_ocr_pytesseract import PytesseractOCR

ocr = PytesseractOCR(language="eng")
text = ocr.extract_text("docs/invoice.png")
print(text)

Processing Image Bytes

from pathlib import Path
from swarmauri_ocr_pytesseract import PytesseractOCR

png_bytes = Path("receipts/ticket.png").read_bytes()
ocr = PytesseractOCR(language="eng", config="--psm 6")
print(ocr.extract_text(png_bytes))

Async and Batch APIs

import asyncio
from swarmauri_ocr_pytesseract import PytesseractOCR

ocr = PytesseractOCR(language="fra")

async def run_async():
    text = await ocr.aextract_text("scans/document_fr.png")
    print(text)

    texts = await ocr.abatch([
        "scans/page1.png",
        "scans/page2.png",
    ], max_concurrent=2)
    for page, content in enumerate(texts, start=1):
        print(f"Page {page}: {content[:80]}")

# asyncio.run(run_async())

List Available Languages

from swarmauri_ocr_pytesseract import PytesseractOCR

ocr = PytesseractOCR()
print(ocr.get_supported_languages())

Tips

  • Set TESSERACT_CMD if the binary lives outside standard locations (e.g., Windows installs).
  • Use appropriate page segmentation modes (--psm) and OCR engine modes (--oem) through the config parameter to improve quality.
  • Pre-process images (grayscale, thresholding) before passing them to the OCR for better accuracy.
  • When running in containers, ensure Tesseract language packs (.traineddata) are installed for the languages you plan to use.

Want to help?

If you want to contribute to swarmauri-sdk, read up on our guidelines for contributing that will help you get started.

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

swarmauri_ocr_pytesseract-0.9.2.dev7.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

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

File details

Details for the file swarmauri_ocr_pytesseract-0.9.2.dev7.tar.gz.

File metadata

  • Download URL: swarmauri_ocr_pytesseract-0.9.2.dev7.tar.gz
  • Upload date:
  • Size: 8.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.3 {"installer":{"name":"uv","version":"0.10.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for swarmauri_ocr_pytesseract-0.9.2.dev7.tar.gz
Algorithm Hash digest
SHA256 c8a774f84cf063951a5b30ec232cdbce1ba8f0152de9bcd196924b1dc435e0de
MD5 682248a553acbbbf8dba7d715543878e
BLAKE2b-256 158a4f63d2a7a48bcdaa7723c62fc5c7bce58b14943f8369e1990c8e50fe5e26

See more details on using hashes here.

File details

Details for the file swarmauri_ocr_pytesseract-0.9.2.dev7-py3-none-any.whl.

File metadata

  • Download URL: swarmauri_ocr_pytesseract-0.9.2.dev7-py3-none-any.whl
  • Upload date:
  • Size: 9.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.3 {"installer":{"name":"uv","version":"0.10.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for swarmauri_ocr_pytesseract-0.9.2.dev7-py3-none-any.whl
Algorithm Hash digest
SHA256 b58547c691d9dc94cebd7fa3505a3fea563d36a8efc468934eb105e8b68e8536
MD5 40a7d2add8430aa032050dc83274f8ac
BLAKE2b-256 ac960f52feda705be7e127f8c09636a9ff7467265cdf3465a170983f6a4f8418

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