Skip to main content

English OCR, layout analysis, and table recognition from document images

Project description

Surya Tabular OCR

A trimmed fork of Surya focused on English-only OCR, layout analysis, and table recognition from document images. Programmatic use only — no CLI.

Installation

Requires Python 3.10+ and PyTorch. You may need to install the CPU version of torch first if you're not using a Mac or a GPU machine. See here for more details.

pip install surya-tabular-ocr
# or
uv add surya-tabular-ocr

Model weights download automatically on first use.

Usage

Table extraction pipeline (recommended)

Single-call interface that runs layout detection, table recognition, and OCR together:

from surya.pipeline import TableExtractionPipeline

pipeline = TableExtractionPipeline()  # loads all models once
result = pipeline.extract_tables(image, ocr=True)
# result is a plain dict: {"tables": [...], "image_size": [w, h]}
  • Accepts PIL.Image or raw bytes
  • ocr=True runs text recognition on each detected table
  • skip_table_detection=True treats the whole image as one table

Individual predictors

OCR:

from PIL import Image
from surya.foundation import FoundationPredictor
from surya.recognition import RecognitionPredictor
from surya.detection import DetectionPredictor

image = Image.open("doc.png")
recognition = RecognitionPredictor(FoundationPredictor())
detection = DetectionPredictor()

predictions = recognition([image], det_predictor=detection)

Layout analysis:

from PIL import Image
from surya.foundation import FoundationPredictor
from surya.layout import LayoutPredictor

image = Image.open("doc.png")
layout = LayoutPredictor(FoundationPredictor())

predictions = layout([image])

Table recognition:

from PIL import Image
from surya.table_rec import TableRecPredictor

image = Image.open("table.png")
table_rec = TableRecPredictor()

predictions = table_rec([image])

Configuration

All settings are in surya/settings.py and overridable via environment variables:

  • TORCH_DEVICE — override auto-detected device (e.g. cuda)
  • RECOGNITION_BATCH_SIZE, DETECTOR_BATCH_SIZE, LAYOUT_BATCH_SIZE, TABLE_REC_BATCH_SIZE
  • COMPILE_DETECTOR, COMPILE_LAYOUT, COMPILE_TABLE_REC, COMPILE_ALL — enable torch compilation

Development

git clone https://github.com/nexusaicodes/surya-tabular-ocr.git
cd surya-tabular-ocr
uv sync --group dev
pre-commit install          # enable ruff linting/formatting on commit
uv run pytest

License

Code is GPL-3.0-or-later (inherited from upstream). Model weights use a modified AI Pubs Open Rail-M license. See LICENSE and MODEL_LICENSE.

Acknowledgments

Trimmed fork of Surya by Vik Paruchuri and the Datalab team.

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

surya_tabular_ocr-0.1.0.tar.gz (218.3 kB view details)

Uploaded Source

Built Distribution

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

surya_tabular_ocr-0.1.0-py3-none-any.whl (136.5 kB view details)

Uploaded Python 3

File details

Details for the file surya_tabular_ocr-0.1.0.tar.gz.

File metadata

  • Download URL: surya_tabular_ocr-0.1.0.tar.gz
  • Upload date:
  • Size: 218.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.1 {"installer":{"name":"uv","version":"0.11.1","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 surya_tabular_ocr-0.1.0.tar.gz
Algorithm Hash digest
SHA256 678465098da09f63b3fa69236bf152fb34f427d46faef3edbc25073e5d498c46
MD5 63555faccb4f00b71ecf75f2962544ca
BLAKE2b-256 4d21c253c87683799d675f6ec405e1a6cf7b41e2af38a6170763ab053619a684

See more details on using hashes here.

File details

Details for the file surya_tabular_ocr-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: surya_tabular_ocr-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 136.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.1 {"installer":{"name":"uv","version":"0.11.1","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 surya_tabular_ocr-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a96647db932bddad8bff57cfb6e71d1e7c52dc558eb43b3f3f62aeea4cb21886
MD5 222abf9ac15f102930442d7a7e9e0bdd
BLAKE2b-256 b49bf0aea23f6f401c1202b10f29b840e9450d731eed3e1fd033aa669ed9ca11

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