A library for performing inference using trained models.
Actively maintained. Last release 6 days ago, commits in 7 of the last 26 weeks. A safe choice.
pip install unstructured-inferenceOpen-Source Pre-Processing Tools for Unstructured Data
The unstructured-inference repo contains hosted model inference code for layout parsing models.
These models are invoked via API as part of the partitioning bricks in the unstructured package.
Requires Python >=3.11, <3.14.
Installation
Package
pip install unstructured-inference
Detectron2
Detectron2 is required for using models from the layoutparser model zoo but is not automatically installed with this package. For MacOS and Linux, build from source with:
pip install 'git+https://github.com/facebookresearch/detectron2.git@57bdb21249d5418c130d54e2ebdc94dda7a4c01a'
Other install options can be found in the Detectron2 installation guide.
Windows is not officially supported by Detectron2, but some users are able to install it anyway. See discussion here for tips on installing Detectron2 on Windows.
Development Setup
This project uses uv for dependency management.
# Clone and install all dependencies (including dev/test/lint groups)
git clone https://github.com/Unstructured-IO/unstructured-inference.git
cd unstructured-inference
make install
Run make help for a full list of available targets.
Getting Started
To get started with the layout parsing model, use the following commands:
from unstructured_inference.inference.layout import DocumentLayout
layout = DocumentLayout.from_file("sample-docs/loremipsum.pdf")
print(layout.pages[0].elements)
Once the model has detected the layout and OCR'd the document, the text extracted from the first
page of the sample document will be displayed.
You can convert a given element to a dict by running the .to_dict() method.