Skip to main content

Document components for the Sayou Data Platform

Project description

sayou-document

PyPI version License Docs

The Universal Document Parsing Gateway for Sayou Fabric.

sayou-document is a high-fidelity parsing engine that converts diverse document formats (PDF, DOCX, PPTX, XLSX, Images) into a unified, structured Document Object Model (DOM).

Unlike simple text extractors, it preserves the semantic structure of documents—headers, tables, charts, and layout coordinates—making it ideal for RAG (Retrieval-Augmented Generation) and Layout-aware LLM applications.

💡 Core Philosophy

"One Interface, High Fidelity."

We abstract away the complexity of proprietary file formats. Whether it's a slide deck or a spreadsheet, sayou-document normalizes it into a consistent Document > Page > Element hierarchy.

  1. Smart Routing: Automatically detects file types (and converts images to PDF if needed) to select the optimal parser.
  2. Hybrid Extraction: Combines native text extraction with OCR fallback for scanned pages or images.
  3. Strict Schema: Outputs data strictly adhering to Pydantic models, ready for the next pipeline stage (Refinery).
flowchart LR
    File[Raw File] --> Pipeline[Document Pipeline]
    Pipeline -->|PDF/Image| OCR[PDF Parser + OCR]
    Pipeline -->|Office| Office[DOCX/PPTX/XLSX Parser]
    OCR --> DOM[Structured Document Model]
    Office --> DOM

📦 Installation

pip install sayou-document

# For OCR support (requires Tesseract installed on OS)
pip install "sayou-document[ocr]"

⚡ Quick Start

The DocumentPipeline handles file detection, conversion, and parsing automatically.

import os
from sayou.document.pipeline import DocumentPipeline

def run_demo():
    # 1. Initialize Pipeline (with optional OCR)
    pipeline = DocumentPipeline(use_default_ocr=True)
    pipeline.initialize()

    # 2. Parse a file (PDF, Word, Excel, PPT, or Image)
    file_path = "quarterly_report.pdf"
    # file_path = "scan_image.png"  # Images are auto-converted to PDF & OCR'd
    
    with open(file_path, "rb") as f:
        file_bytes = f.read()
        
    doc = pipeline.run(file_bytes, os.path.basename(file_path))
    
    if doc:
        print(f"File: {doc.file_name} ({doc.doc_type})")
        print(f"Pages: {doc.page_count}")
        
        # 3. Access Structured Data
        first_page = doc.pages[0]
        if first_page.elements:
            print(f"Content Preview: {first_page.elements[0].text[:100]}...")
        
        # Export to JSON
        print(doc.model_dump_json(indent=2))

if __name__ == "__main__":
    run_demo()

🔑 Key Components

Parsers

  • PdfParser: Extracts text, images, and TOC from PDFs using PyMuPDF. Supports full-page OCR for scanned documents.
  • DocxParser: Parses Word documents, preserving heading levels and table structures.
  • PptxParser: Extracts text frames, notes, and tables from slides.
  • ExcelParser: Converts sheets into table elements and extracts embedded images.

Converters & OCR

  • ImageToPdfConverter: Automatically converts JPG/PNG images to PDF to leverage the robust PDF parsing pipeline.
  • TesseractOCR: (Optional) Provides OCR capabilities for handling scanned content and embedded images.

🤝 Contributing

We welcome contributions for new Parsers (e.g., HwpParser for Korean documents, HtmlParser) or Enhanced OCR integrations (e.g., Google Vision API).

📜 License

Apache 2.0 License © 2025 Sayouzone

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

sayou_document-0.1.9.tar.gz (24.6 kB view details)

Uploaded Source

Built Distribution

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

sayou_document-0.1.9-py3-none-any.whl (28.0 kB view details)

Uploaded Python 3

File details

Details for the file sayou_document-0.1.9.tar.gz.

File metadata

  • Download URL: sayou_document-0.1.9.tar.gz
  • Upload date:
  • Size: 24.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for sayou_document-0.1.9.tar.gz
Algorithm Hash digest
SHA256 27d541c9ad1cf82eef72429ae887ea37f01a25685e63de1491b27354b7b5e1c9
MD5 78f955ecfdbb2372f5b86050d4c05e63
BLAKE2b-256 fda2430f5f25a621b7674a7bf5aafa2925e5b9aa5c860f9a5e68e71835c093c1

See more details on using hashes here.

File details

Details for the file sayou_document-0.1.9-py3-none-any.whl.

File metadata

  • Download URL: sayou_document-0.1.9-py3-none-any.whl
  • Upload date:
  • Size: 28.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for sayou_document-0.1.9-py3-none-any.whl
Algorithm Hash digest
SHA256 88e08d27719c2b0b1fb4b2a126db09e3a63830979485f303df450f9645c2e6a3
MD5 d21a8b0842b8df4c5c41b2de14f56583
BLAKE2b-256 bf130c3cab552f906b81d7d0bd20da2ce72a3cba4292aa4175e8605a6b1aa61f

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