Structured data extraction from text using LLMs and dynamic model generation
Project description
structx
Advanced structured data extraction from any document using LLMs with multimodal support.
structx is a powerful Python library for extracting structured data from text,
tables, and documents using Large Language Models (LLMs). With the optional
docs extra, it provides a multimodal PDF pipeline that passes PDFs directly to
vision-capable models and 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
docsextra - 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. For document/PDF processing, install structx[docs].
✨ 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 in the base install,
with PDF, DOCX, TXT, Markdown, 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: Multi-threaded and async operations
- 🔄 Robust Error Handling: Automatic retry mechanism with exponential backoff
- 📈 Token Usage Tracking: Detailed step-by-step metrics for cost monitoring
- � Flexible Configuration: Configurable extraction using OmegaConf
- 🔌 Multiple LLM Providers: Support through litellm integration
Installation
pip install structx
For document and multimodal PDF support:
pip install "structx[docs]"
🔧 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
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"Extracted {result.success_count} items")
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.
# 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"
)
📊 Token Usage Monitoring
# Check token usage for cost monitoring
usage = result.get_token_usage()
if usage:
print(f"Total tokens: {usage.total_tokens}")
print(f"By step: {[(s.name, s.tokens) for s in usage.steps]}")
🚀 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.
- Getting Started
- Basic Extraction
- Unstructured Text Processing
- Async Operations
- Multiple Queries
- Custom Models
- Token Usage Tracking
- API Reference
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 → 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.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file structx-0.5.0.tar.gz.
File metadata
- Download URL: structx-0.5.0.tar.gz
- Upload date:
- Size: 42.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5310a5f8327f5f64e89d6faed51a3764d248ae1e1f9b2a4a2536d447ba65e7f7
|
|
| MD5 |
ce9687681f1e29531f1b85a6d1e3b635
|
|
| BLAKE2b-256 |
8dedeea1807b65ece9dd1c49f8114b60830faa4f80c849e63a3bb374e1789d04
|
Provenance
The following attestation bundles were made for structx-0.5.0.tar.gz:
Publisher:
publish.yml on Blacksuan19/structx
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
structx-0.5.0.tar.gz -
Subject digest:
5310a5f8327f5f64e89d6faed51a3764d248ae1e1f9b2a4a2536d447ba65e7f7 - Sigstore transparency entry: 2136203972
- Sigstore integration time:
-
Permalink:
Blacksuan19/structx@c9daaac7ca4961bebe615d9c2c3e5126d0bfdc8c -
Branch / Tag:
refs/tags/0.5.0 - Owner: https://github.com/Blacksuan19
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@c9daaac7ca4961bebe615d9c2c3e5126d0bfdc8c -
Trigger Event:
push
-
Statement type:
File details
Details for the file structx-0.5.0-py3-none-any.whl.
File metadata
- Download URL: structx-0.5.0-py3-none-any.whl
- Upload date:
- Size: 41.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9df13c2b86537d118d8ed1f5d8c164b515bfa62fde244fcda449e430b0787791
|
|
| MD5 |
008329a745136b11a773fd363044d559
|
|
| BLAKE2b-256 |
4002789dfbdbe322bf07b8936bf57ce24da6a973dd439644b846f09270d97e23
|
Provenance
The following attestation bundles were made for structx-0.5.0-py3-none-any.whl:
Publisher:
publish.yml on Blacksuan19/structx
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
structx-0.5.0-py3-none-any.whl -
Subject digest:
9df13c2b86537d118d8ed1f5d8c164b515bfa62fde244fcda449e430b0787791 - Sigstore transparency entry: 2136204065
- Sigstore integration time:
-
Permalink:
Blacksuan19/structx@c9daaac7ca4961bebe615d9c2c3e5126d0bfdc8c -
Branch / Tag:
refs/tags/0.5.0 - Owner: https://github.com/Blacksuan19
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@c9daaac7ca4961bebe615d9c2c3e5126d0bfdc8c -
Trigger Event:
push
-
Statement type: