Skip to main content

structx

Advanced structured data extraction from any document using LLMs with multimodal support.

Documentation PyPI GitHub Actions

See the project roadmap for planned portable business rules and semantic validation work.

structx is a powerful Python library for extracting structured data from text, tables, and documents using Large Language Models (LLMs). It passes existing PDFs directly to vision-capable models; the optional docs extra converts other document formats to PDF first.

🔔 Package rename notice (PyPI)

The PyPI distribution has been renamed from structx-llm to structx (September 2025).

  • Imports are unchanged: continue using import structx
  • Document processing now lives in the optional docs extra
  • Please update your environments and requirement files to use the new name

Upgrade commands:

pip uninstall -y structx-llm
pip install -U structx

If you previously pinned structx-llm in requirements or lock files, replace it with structx. Install structx[docs] for non-PDF document conversion.

✨ Key Features

🎯 Advanced Document Processing

  • � Multimodal PDF Pipeline: Passes PDFs directly to vision-capable models and converts supported non-PDF documents to PDF
  • 🖼️ Vision-Enabled Extraction: Native instructor multimodal support for PDFs and images
  • 🔄 Smart Format Detection: Automatic processing mode selection for best results
  • 📊 Flexible File Support: CSV, Excel, JSON, Parquet, raw text, and existing PDFs in the base install; DOCX, PPTX, images, and more via structx[docs]

🚀 Intelligent Data Extraction

  • 🔄 Dynamic Model Generation: Create type-safe Pydantic models from natural language queries
  • 🎯 Automatic Schema Inference: Intelligent schema generation and refinement
  • 📊 Complex Data Structures: Support for nested and hierarchical data
  • 🔄 Natural Language Refinement: Improve models with conversational instructions

⚡ Performance & Reliability

  • 🚀 High-Performance Processing: Threaded sync and native async row requests
  • 🔄 Robust Error Handling: Automatic retry mechanism with exponential backoff
  • 📈 Token Usage Tracking: Detailed step-by-step metrics for cost monitoring
  • Flexible Configuration: Model settings from arguments, YAML, environment variables, dotenv files, and secrets through Pydantic Settings
  • 🔌 Multiple LLM Providers: Support through litellm integration

Installation

pip install structx

For converting DOCX, PowerPoint, OpenDocument, markup, image, and other non-PDF document formats:

pip install "structx[docs]"

For estimating PDF page and text counts before extraction, without running an extraction:

pip install "structx[measurement]"        # embedded text only
pip install "structx[measurement-ocr]"    # adds local OCR for scanned pages

🔧 What The Package Provides

  • Structured readers for CSV, Excel, JSON, Parquet, and Feather
  • Instructor multimodal vision support
  • Optional Docling document parsing with CPU-only PyTorch resolution for uv on Linux
  • Optional WeasyPrint PDF rendering for non-PDF document formats
  • Optional standalone document measurement, separate from the extraction path

Quick Start

Basic Text Extraction

from structx import Extractor

# Initialize extractor
extractor = Extractor.from_litellm(
    model="gpt-4o",
    api_key="your-api-key",
    max_retries=3,      # Automatically retry on transient errors
    min_wait=1,         # Start with 1 second wait
    max_wait=10         # Maximum 10 seconds between retries
)

# Extract from text
result = extractor.extract(
    data="System check on 2024-01-15 detected high CPU usage (92%) on server-01.",
    query="extract incident date and details"
)

# Access results
print(f"Successful rows: {result.success_count}")
print(result.data[0].model_dump_json(indent=2))

📄 Document Processing with Multimodal Support

Install structx[docs] before using non-PDF document formats. Existing PDFs can be passed directly through the multimodal path with the base installation.

# Process a PDF invoice through the multimodal pipeline
result = extractor.extract(
    data="scripts/example_input/S0305SampleInvoice.pdf",
    query="extract the invoice number, total amount, and line items"
)

# Convert a DOCX contract and process with multimodal support
result = extractor.extract(
    data="scripts/example_input/free-consultancy-agreement.docx",
    query="extract parties, effective date, and payment terms"
)

📏 Document Measurement Before Extraction

Install structx[measurement] to size a PDF without extracting it. This path is independent of extraction: it never converts or replaces the input file.

from structx.measurement import DocumentMeasurer

measurement = DocumentMeasurer(ocr_mode="auto").measure(
    "scripts/example_input/S0305SampleInvoice.pdf"
)

# Estimates, plus whether every page could actually be measured
print(measurement.page_count, measurement.character_count, measurement.status)

📊 Token Usage Monitoring

# Check token usage for cost monitoring
usage = result.usage
if usage:
    print(f"Total tokens: {usage.total_tokens}")
    for step, calls in usage.steps.items():
        print(step.value, [call.total_tokens for call in calls])

🚀 Why Multimodal PDF Processing?

The innovative multimodal approach provides significant advantages over traditional text-based extraction:

  • 📄 Context Preservation: Full document layout and structure are maintained
  • 🎯 Higher Accuracy: Vision models can interpret tables, charts, and complex layouts
  • 🔄 No Chunking Issues: Eliminates problems with information split across chunks
  • 📊 Universal Format: Existing PDFs are passed through directly; supported non-PDF documents become processable through PDF conversion
  • 🖼️ Visual Understanding: Handles documents with visual elements, formatting, and structure

📚 Documentation

For comprehensive documentation, examples, and guides, visit our documentation site.

Examples

Check out our example gallery for real-world use cases,

📁 Supported File Formats

📊 Structured Data (Direct Processing)

  • CSV: Comma-separated values with custom delimiters
  • Excel: .xlsx/.xls with sheet selection and custom options
  • JSON: JavaScript Object Notation with nested support
  • Parquet: Columnar storage format for large datasets
  • Feather: Fast binary format for data frames

📄 Unstructured Documents (Multimodal Pipeline)

Format Extensions Processing Method Quality
PDF .pdf PDF → Multimodal ⭐⭐⭐⭐⭐
Word .docx, .doc Docling → HTML → PDF → Multimodal ⭐⭐⭐⭐⭐
PowerPoint .pptx, .ppt Docling → HTML → PDF → Multimodal ⭐⭐⭐⭐
Text .txt, .md, .py, .log, .xml, .html Docling → HTML → PDF → Multimodal ⭐⭐⭐⭐

🔄 Processing Pipeline

  • PDF passthrough: Existing PDFs are sent directly to multimodal extraction
  • Docling parsing: Reads non-PDF document-like inputs into a structured document model
  • WeasyPrint rendering: Converts Docling HTML to a temporary PDF for non-PDF inputs
  • Multimodal extraction: Sends the rendered PDF to instructor's multimodal API

Contributing

Contributions are welcome! Please read our Contributing Guidelines for details.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Metadata

Release files for structx 0.6.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for structx 0.6.5
File Size Uploaded
structx-0.6.5.tar.gz 67.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for structx 0.6.5
File Interpreter ABI Platform
structx-0.6.5-py3-none-any.whl Python 3 none any Details

Total release size: 120.8 kB

Release files / structx-0.6.5.tar.gz

Download URL structx-0.6.5.tar.gz
Size 67.2 kB
Tags Source
SHA-256 checksum
How to use checksums
fc8a7343748fd6a73149e32b906c6e84c207749930cd3eca1fdfa45a5bafb402
BLAKE2b-256 checksum
How to use checksums
204ee7c4a3017b4b5e0994ce65b2f39e144259a76fa913e68ee428a09de38ebf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 22, 2026.

Transparency log

Release files / structx-0.6.5-py3-none-any.whl

Download URL structx-0.6.5-py3-none-any.whl
Size 53.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a51d823db3b229212734d16b98c4d97fb82a5884999f4f59f5be123d5b3fc48f
BLAKE2b-256 checksum
How to use checksums
9f986d60d9b3869d62f96145d9060882cfee8f5764dbd1ad9cb6e539a575b8c6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 22, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.6.5 This release

2 release files

0.6.4

2 release files

0.6.3

2 release files

0.6.2

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.11

2 release files

0.4.10

2 release files

0.4.8

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page