Science-OCR
Science-OCR is a lightweight, ready-to-use Python package designed to extract clean, structured text from scientific papers in PDF format. It wraps a simple interface around Surya-OCR's layout, text_detection, and text_recognition models, while using PyMuPDF (fitz) to rasterize PDF pages into images for processing.
This tool is ideal for researchers, data scientists, and developers who want reliable OCR extraction from research papers—without dealing with complicated pipelines.
✨ Features
- 📄 Optimized for scientific PDFs
- 🔍 High-accuracy OCR with Surya-OCR (layout + detection + recognition)
- 🧩 Minimal API — only one method to use
- 🐍 Easy installation via
pip - 🚀 Zero setup — works out-of-the-box
📦 Installation
pip install science-ocr
No additional configuration required — models load automatically.
🚀 Quick Start
from science_ocr import ScienceOCR
ocr = ScienceOCR()
text = ocr.parse_text(
path="path/to/paper.pdf",
first_page=0, # optional
last_page=None, # optional
dpi=300 # optional
)
print(text)
📘 API Reference
class ScienceOCR(use_gpu=True)
Initializes the OCR engine.
| Parameter | Type | Default | Description |
|---|---|---|---|
| use_gpu | bool | True | If True, uses GPU if available. If False, forces CPU usage, which may be slower but more stable on some systems and avoid memory issues. |
parse_text(self, path, first_page=0, last_page=None, dpi=300)
Extracts OCR text from a PDF.
| Parameter | Type | Default | Description |
|---|---|---|---|
| path | str | — | Path to the PDF file. |
| first_page | int | 0 | 0-indexed first page to process. |
| last_page | int | None | None | Last page index (inclusive). If None, processes until the final page. |
| dpi | int | 300 | Rasterization DPI for PyMuPDF before OCR. |
Returns: A single string containing the concatenated OCR text from the selected page range.
🧠 How It Works (Behind the Scenes)
- PyMuPDF (fitz) loads the PDF and renders each page at the specified DPI.
- Each rendered page image is passed through Surya-OCR:
layoutmodel to detect structuretext_detectionmodel to find text regionstext_recognitionmodel to extract text
- Results are merged and returned as clean, readable text.
This hybrid pipeline is optimized for the complex layouts of scientific literature (equations, tables, multi-column layouts, etc.).
📦 Model Weights
This package uses Surya-OCR models that are mirrored on HuggingFace for reliability:
- Mirror:
https://huggingface.co/TomasGD/surya-ocr-mirror-models-2025_05_07
Models are subject to Surya's licensing terms (see MODEL_LICENSE).
🤝 Contributing
Pull requests and suggestions are welcome! If you encounter any issues, please open an issue on the project's repository.
📄 License
Science-OCR is licensed under AGPL-3.0, but depends on:
- PyMuPDF: AGPL-3.0
- Surya-OCR: Code is GPL-3.0 & Models are AI Pubs Open Rail-M license (free for research, personal use, and startups under $2M funding/revenue)
For commercial use exceeding $2M funding/revenue, you must obtain commercial licenses for the dependencies.
Disclaimer
The maintainers of Science-OCR are not responsible for ensuring your compliance with third-party licenses. It is your responsibility to review and comply with all applicable licenses for dependencies used in this project.
Metadata
Release files for science-ocr 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| science_ocr-0.3.0.tar.gz | 16.3 kB | Without provenance | Details for science_ocr-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| science_ocr-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for science_ocr-0.3.0-py3-none-any.whl |
Total release size: 33.8 kB
Release files / science_ocr-0.3.0.tar.gz
| Download URL | science_ocr-0.3.0.tar.gz |
|---|---|
| Size | 16.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d5f081669ca1ed5108cac4e6f0778ddeb677aab426f64bdc4b1c437113f6fc26
|
|
BLAKE2b-256 checksum How to use checksums |
52e63bfca269c29fb206dc0d2303f2eb5737ca8749fb36a8d1e7ca6d119d93d5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.12
|
Release files / science_ocr-0.3.0-py3-none-any.whl
| Download URL | science_ocr-0.3.0-py3-none-any.whl |
|---|---|
| Size | 17.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
be90bad0d08f7d8bdf9574c4aa4dd83df61625f49b19c9f308e94ef70ec24239
|
|
BLAKE2b-256 checksum How to use checksums |
574bd0f4f082d82677f22d54974ba3b211c5abd4a569dfd24e9a12ad8e8fd958
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.12
|
Security for science-ocr 0.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.