python-doctr
Document Text Recognition (docTR): deep Learning for high-performance OCR on documents.
What it is and what it does
python-doctr is a PyTorch-based OCR library that combines text detection and recognition models to extract structured text from documents. It reads PDFs and images, localizes each word, recognizes its characters, and returns a nested document structure (Page, Block, Line, Word) that can be exported as JSON or visualized. The library offers multiple architectures for both detection (DBNet, LinkNet, FAST) and recognition (CRNN, SAR, MASTER, ViTSTR, PARSeq, VIPTR), letting you choose speed versus accuracy trade-offs.
The package handles rotated pages and multi-orientation text through configurable options, supports a KIE (Key Information Extraction) predictor for multi-class detection, and includes utilities for document synthesis and interactive result visualization. It integrates with Hugging Face Hub for model distribution and includes a Streamlit demo app for local testing.
Use it for:
- Extract text and bounding boxes from scanned invoices, receipts, or forms for downstream processing.
- Build a document search index by OCR-ing a large PDF archive and exporting structured text.
- Detect and extract specific fields (dates, addresses) from documents using the KIE predictor with a custom multi-class detector.
- Automate data entry workflows by recognizing and localizing text in handwritten or printed documents.
- Validate or correct OCR output by visualizing detected text regions and character predictions interactively.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
python-doctr extracts and localizes text from documents and images using a two-stage deep learning pipeline: text detection (finding word locations) followed by text recognition (identifying characters), with support for PDFs, images, and rotated pages.
Yes, if you need production-grade OCR with flexible model selection and don't mind the weight of torch and torchvision. The library is actively maintained, permissively licensed, and well-documented. Install only if you have a genuine OCR task; the dependency footprint is substantial but justified for deep learning work.
Install
python-doctr on PyPI
pip
pip install python-doctruv
uv add python-doctrpoetry
poetry add python-doctrInstalling python-doctr
Before you install
Low install friction with a pure-Python wheel. Requires 18 runtime dependencies including torch, torchvision, and opencv-python, which are substantial but standard for deep learning work. Repository is active with recent commits and 6258 stars, indicating ongoing maintenance.
License in practice
Apache License 2.0 is permissive: you can use, modify, and distribute python-doctr freely in commercial and private projects, provided you include a copy of the license and note any changes you make.
Quickstart
pip install python-doctr
from doctr.models import ocr_predictor
from doctr.io import DocumentFile
model = ocr_predictor(pretrained=True)
doc = DocumentFile.from_pdf("path/to/doc.pdf")
result = model(doc)
json_output = result.export()
Requires Python 3.10 or higher. torch and torchvision are heavy dependencies; GPU support is optional but recommended for performance.
Verify before relying
- Inference speed and accuracy benchmarks on common document types and languages.
- Memory footprint and whether models can run on resource-constrained environments.
- How well the KIE predictor generalizes to custom document classes beyond the examples shown.
Package facts
| License | Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for… (full text in the JSON record) (permissive) |
| Python support | supports the current Python release (<4,>=3.10.0) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 18 — torch, torchvision, onnx, numpy, scipy, h5py, opencv-python, pypdfium2, pyclipper, shapely, langdetect, rapidfuzz, huggingface-hub, Pillow, defusedxml, anyascii, validators, tqdm |
| Maintenance | actively maintained — 191 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 340,733/month — #7,410 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: python_doctr-1.0.1-py3-none-any.whl
Keywords: OCR, deep learning, computer vision, pytorch, text detection, text recognition
Tags
More Artificial Intelligence packages
LiteLLM provides a unified Python interface to…
permissive · top 100 on PyPI
huggingface-hubClient library and CLI tool for downloading,…
permissive · top 100 on PyPI
langchainLangChain provides a framework for building…
permissive · top 1,000 on PyPI
hf-xethf-xet provides chunk-based deduplication and…
permissive · top 1,000 on PyPI
tokenizersTokenizers converts raw text into token…
permissive · top 1,000 on PyPI
transformersTransformers provides a unified framework for…
permissive · top 1,000 on PyPI
keras-ocrkeras-ocr detects and recognizes text in images…
permissive · top 15,000 on PyPI
onnxtrOnnxTR extracts and recognizes text from…
permissive · top 15,000 on PyPI
surya-ocrSurya is an OCR and document intelligence model…
permissive · top 5,000 on PyPI
easyocrEasyOCR performs optical character recognition…
permissive · top 5,000 on PyPI
layoutparserLayoutParser provides deep learning-based…
permissive · top 5,000 on PyPI
cnocrCnOCR recognizes text in images—Chinese…
permissive · top 15,000 on PyPI
paddleocrPaddleOCR extracts text, tables, and structured…
permissive · top 5,000 on PyPI
img2tableIdentifies and extracts tables from images and…
permissive · top 15,000 on PyPI
pyocrPyOCR wraps multiple OCR engines (Tesseract,…
copyleft · top 15,000 on PyPI
amazon-textract-textractorTextractor wraps Amazon Textract APIs to…
permissive · top 5,000 on PyPI