Skip to main content

doc-page-extractor

Document page extraction tool that converts page images into text layouts with pixel coordinates.

The default backend remains local DeepSeek-OCR for existing users. Version 1.1 adds a unified OCR adapter layer with DeepSeek OpenAI-compatible Vendor support and Baidu cloud OCR support.

Installation

pip install doc-page-extractor

PyTorch is not installed automatically. You only need CUDA PyTorch when using the local DeepSeek-OCR backend.

Backends

Local DeepSeek-OCR

This is the default and keeps the existing API behavior:

from doc_page_extractor import create_page_extractor

extractor = create_page_extractor()

Install CUDA PyTorch before using this backend:

# CUDA 12.1
pip install torch torchvision --index-url https://download.pytorch.org/whl/cu121

# CUDA 11.8
pip install torch torchvision --index-url https://download.pytorch.org/whl/cu118

# CUDA 12.6
pip install torch torchvision --index-url https://download.pytorch.org/whl/cu126

Check CUDA with:

nvidia-smi
python -c "import torch; print(torch.cuda.is_available())"

DeepSeek OCR Vendor

Use this backend when DeepSeek OCR is exposed through an OpenAI-compatible endpoint:

from doc_page_extractor import (
    DeepSeekVendorOCRConfig,
    create_deepseek_vendor_page_extractor,
)

extractor = create_deepseek_vendor_page_extractor(
    DeepSeekVendorOCRConfig.from_env()
)

Expected environment variables:

DOC_PAGE_EXTRACTOR_DEEPSEEK_VENDOR_BASE_URL=
DOC_PAGE_EXTRACTOR_DEEPSEEK_VENDOR_API_KEY=
DOC_PAGE_EXTRACTOR_DEEPSEEK_VENDOR_MODEL=deepseek-ocr
DOC_PAGE_EXTRACTOR_DEEPSEEK_VENDOR_TEMPERATURE=0.0
DOC_PAGE_EXTRACTOR_DEEPSEEK_VENDOR_TOP_P=0.7

Baidu Cloud OCR

Use this backend for Baidu Unlimited-OCR through Baidu Cloud:

from doc_page_extractor import BaiduCloudOCRConfig, create_baidu_page_extractor

extractor = create_baidu_page_extractor(BaiduCloudOCRConfig.from_env())

Expected environment variables:

DOC_PAGE_EXTRACTOR_BAIDU_AK=
DOC_PAGE_EXTRACTOR_BAIDU_SK=
DOC_PAGE_EXTRACTOR_BAIDU_BASE_URL=https://aip.baidubce.com

Extraction

All backends return the same PageExtractor shape:

from PIL import Image
from doc_page_extractor import ExtractionContext

context = ExtractionContext(check_aborted=lambda: False)

for page_image, layouts in extractor.extract(
    image=Image.open("page.png"),
    size="gundam",
    stages=1,
    context=context,
):
    for layout in layouts:
        print(layout.det, layout.text)

Layout keeps the original ref, det, and text fields. Version 1.1.1 also adds kind, a stable LayoutKind enum that callers should prefer over provider-specific labels. Adapter metadata remains available through optional fields such as type, polygon, html, source, and raw.

Use extract_page_results() when you need the structured page model:

from doc_page_extractor import LayoutKind

for page_image, result in extractor.extract_page_results(
    image=Image.open("page.png"),
    size="gundam",
    stages=1,
    context=context,
):
    if result.structured is None:
        continue
    for block in result.structured.blocks:
        if block.kind == LayoutKind.TABLE:
            print(block.html)

The structured model groups asset captions with images, tables, and equations when possible. DeepSeek output is structured from flat OCR tags; Baidu Cloud OCR is normalized from Baidu's richer layout JSON into the same public kinds.

Baidu Cloud OCR extracts footnotes directly. If stages > 1 is requested with the Baidu adapter, the extractor emits a warning and runs a single stage because DeepSeek-style multi-stage redaction can erase Baidu footnote regions.

Development

For contributors and developers, see Development Guide.

Useful local commands:

poetry run python test.py
poetry run pylint --disable=import-error doc_page_extractor
poetry run python scripts/ocr_sample.py --adapter both --image tests/images/friendly-title.png

Requirements

  • Python >= 3.10, < 3.14
  • CUDA-capable NVIDIA GPU only when using local DeepSeek-OCR
  • Remote OCR credentials only when using DeepSeek Vendor or Baidu Cloud OCR

Dependencies & Licenses

This project is licensed under the MIT License. The local DeepSeek-OCR backend depends on the DeepSeek-OCR model, which uses easydict (LGPLv3) for configuration management.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

doc_page_extractor-1.1.1.tar.gz (19.7 kB view details)

Uploaded Source

Built Distribution

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

doc_page_extractor-1.1.1-py3-none-any.whl (24.7 kB view details)

Uploaded Python 3

File details

Details for the file doc_page_extractor-1.1.1.tar.gz.

File metadata

  • Download URL: doc_page_extractor-1.1.1.tar.gz
  • Upload date:
  • Size: 19.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for doc_page_extractor-1.1.1.tar.gz
Algorithm Hash digest
SHA256 033f64645c4c2020adac7fb3a7adb7df30e9b3cd5ba71c50c76bb72227cf0313
MD5 d101daf4250130b4784d09b9fa2af823
BLAKE2b-256 5f55993e5bb5582f23daaf46e68ab5e7cdd720cd142817e9f19ad51ef9b6ce64

See more details on using hashes here.

Provenance

The following attestation bundles were made for doc_page_extractor-1.1.1.tar.gz:

Publisher: release.yaml on Moskize91/doc-page-extractor

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file doc_page_extractor-1.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for doc_page_extractor-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 996b396c04fa45df68219c87139c0d1e7d9200073a95cca5c3c6ee0b2e305583
MD5 9c8a21fdcfd7b3b34d17968fb329aec6
BLAKE2b-256 470429483ae08e4bf1d1db9a4e5f106148f038dcf3072178fcca767c79e77157

See more details on using hashes here.

Provenance

The following attestation bundles were made for doc_page_extractor-1.1.1-py3-none-any.whl:

Publisher: release.yaml on Moskize91/doc-page-extractor

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

1.2.0

2 files

This release

1.1.1 This release

2 files

1.1.0

2 files

1.0.12

2 files

1.0.11

2 files

1.0.10

2 files

1.0.9

2 files

1.0.8

2 files

1.0.7

2 files

1.0.6

2 files

1.0.5

2 files

1.0.4

2 files

1.0.3

2 files

1.0.2

2 files

1.0.1

2 files

1.0.0

2 files

0.2.4

2 files

0.2.3

2 files

0.2.2

2 files

0.2.1

2 files

0.2.0

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

0.0.10

2 files

0.0.9

2 files

0.0.8

2 files

0.0.7

2 files

0.0.6

2 files

0.0.5

2 files

0.0.2

2 files

0.0.1

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page