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.11+ 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.Imageor rawbytes ocr=Trueruns text recognition on each detected tableskip_table_detection=Truetreats 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_SIZECOMPILE_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
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file surya_tabular_ocr-0.1.1.tar.gz.
File metadata
- Download URL: surya_tabular_ocr-0.1.1.tar.gz
- Upload date:
- Size: 197.0 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c45a10efab0a4d361127651370e623ea702e7d54ec1cb64a3b8ed0c8c7435fa2
|
|
| MD5 |
77d06bdb15285e7d6e4f4e762ee0f585
|
|
| BLAKE2b-256 |
7f402dcee9bf61c3c24a7653eea657cd18bc2763ef59c42f1ded61c0e4024517
|
File details
Details for the file surya_tabular_ocr-0.1.1-py3-none-any.whl.
File metadata
- Download URL: surya_tabular_ocr-0.1.1-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8a24ab843a0dca37c97013761757d9c769a5baaf70259ecea358b08f34c10ad9
|
|
| MD5 |
09243d5a45604369f78f962d3e3868be
|
|
| BLAKE2b-256 |
aec83b7a6895b0bbf0bc675ea4548bd88acdb23950a48485f3de5301cd13bfab
|