2023-02-17 21:02:23 +00:00
# Unstructured
2023-05-30 20:58:16 +00:00
>The `unstructured` package from
2023-02-17 21:02:23 +00:00
[Unstructured.IO](https://www.unstructured.io/) extracts clean text from raw source documents like
PDFs and Word documents.
2023-05-30 20:58:16 +00:00
This page covers how to use the [`unstructured`](https://github.com/Unstructured-IO/unstructured)
2023-05-31 22:03:21 +00:00
ecosystem within LangChain.
2023-02-17 21:02:23 +00:00
## Installation and Setup
2023-05-02 03:37:35 +00:00
If you are using a loader that runs locally, use the following steps to get `unstructured` and
its dependencies running locally.
2023-08-01 21:17:49 +00:00
- Install the Python SDK with `pip install unstructured`.
- You can install document specific dependencies with extras, i.e. `pip install "unstructured[docx]"`.
- To install the dependencies for all document types, use `pip install "unstructured[all-docs]"`.
2023-02-17 21:02:23 +00:00
- Install the following system dependencies if they are not already available on your system.
Depending on what document types you're parsing, you may not need all of these.
2023-03-31 03:45:31 +00:00
- `libmagic-dev` (filetype detection)
- `poppler-utils` (images and PDFs)
- `tesseract-ocr`(images and PDFs)
- `libreoffice` (MS Office docs)
- `pandoc` (EPUBs)
2023-02-17 21:02:23 +00:00
2023-05-02 03:37:35 +00:00
If you want to get up and running with less set up, you can
simply run `pip install unstructured` and use `UnstructuredAPIFileLoader` or
`UnstructuredAPIFileIOLoader`. That will process your document using the hosted Unstructured API.
2023-06-27 23:54:15 +00:00
The Unstructured API requires API keys to make requests.
You can generate a free API key [here](https://www.unstructured.io/api-key) and start using it today!
Checkout the README [here](https://github.com/Unstructured-IO/unstructured-api) here to get started making API calls.
We'd love to hear your feedback, let us know how it goes in our [community slack](https://join.slack.com/t/unstructuredw-kbe4326/shared_invite/zt-1x7cgo0pg-PTptXWylzPQF9xZolzCnwQ).
And stay tuned for improvements to both quality and performance!
Check out the instructions
[here](https://github.com/Unstructured-IO/unstructured-api#dizzy-instructions-for-using-the-docker-image) if you'd like to self-host the Unstructured API or run it locally.
2023-05-02 03:37:35 +00:00
2023-02-17 21:02:23 +00:00
## Wrappers
### Data Loaders
The primary `unstructured` wrappers within `langchain` are data loaders. The following
shows how to use the most basic unstructured data loader. There are other file-specific
data loaders available in the `langchain.document_loaders` module.
```python
from langchain.document_loaders import UnstructuredFileLoader
loader = UnstructuredFileLoader("state_of_the_union.txt")
loader.load()
```
If you instantiate the loader with `UnstructuredFileLoader(mode="elements")`, the loader
will track additional metadata like the page number and text type (i.e. title, narrative text)
when that information is available.