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.0.dev21.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.0.dev21.tar.gz.

File metadata

  • Download URL: swarmauri_ocr_pytesseract-0.9.0.dev21.tar.gz
  • Upload date:
  • Size: 8.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.27 {"installer":{"name":"uv","version":"0.9.27","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.0.dev21.tar.gz
Algorithm Hash digest
SHA256 b2b9f1d04cfb248d7e94865c42af59130705598f8055a8695cdee81bd557266d
MD5 a5575c90223d287c30dd6b8f263f3f80
BLAKE2b-256 e8ca43bcda76c2066a3a09d9f907da6d0aee82e833f5aa9a330f30cc13e0f87a

See more details on using hashes here.

File details

Details for the file swarmauri_ocr_pytesseract-0.9.0.dev21-py3-none-any.whl.

File metadata

  • Download URL: swarmauri_ocr_pytesseract-0.9.0.dev21-py3-none-any.whl
  • Upload date:
  • Size: 9.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.27 {"installer":{"name":"uv","version":"0.9.27","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.0.dev21-py3-none-any.whl
Algorithm Hash digest
SHA256 666069837b9f3fc458a71d2e0252ed00fa222c79146b7f36edaee222f39b55a1
MD5 852fefbcd9914b294b51b0f860b1d0ec
BLAKE2b-256 5c471c74e242ea411e5603eaa726f033a06e6020389420e7d9fe87b07115f66e

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