面向非结构化数据的开源预处理工具
unstructured 库提供开源组件,用于摄取和预处理图像及文本文档,如 PDF、HTML、Word 文档等更多格式。unstructured 的应用场景围绕简化和优化大语言模型(LLM)的数据处理流程。其模块化函数和连接器构成一个协同系统,简化数据摄取和预处理,使其适应不同平台,并高效地将非结构化数据转换为结构化输出。
Unstructured Transform 以 MCP 服务器形式,为智能体提供生产级文档处理能力。它支持将 60 多种文件类型转换为结构化数据,可直接用于应用程序、向量数据库和下游流程——通过在智能体当前会话中直接解析、富化、分块和嵌入文件实现。
选择 MCP 客户端。 Transform 兼容几乎所有 MCP 主机或智能体框架——如 Claude Code、Cursor、Codex CLI 等。
将 Transform MCP 服务器添加到客户端的 MCP 配置中(通过命令行 mcp add 命令或客户端的 MCP 设置/配置文件,具体取决于工具)。
一次性认证,当客户端提示时登录即可。签名后,Transform 工具将在智能体下一条消息时可用。
将文件指向智能体。 拖放或引用本地文件或 URL。Transform 支持 60 多种格式(PDF、邮件、图片、扫描件等)。
用自然语言描述需求。 告诉智能体你的意图(例如“解析并分块这份合同以存入向量库”),Transform 将分区、富化、分块和嵌入文件,返回随时可用的结构化数据。
每月 15,000 页免费,之后每页 3 美分!
📄 完整文档:https://docs.unstructured.io/transform/overview
准备好将数据处理流程投入生产并利用高级功能?查看 Unstructured Pipelines。除了更优的处理性能,还可通过低代码 UI 或 API 利用分块、嵌入以及图像和表格富化生成功能。申请演示 联系销售团队,了解如何开始。
有几种方式使用 unstructured 库:
* 在容器中运行库 或
* 安装库
1. 从 PyPI 安装
2. 本地开发安装
* 如需在 Windows 上使用 conda 安装,请参考文档
以下说明旨在帮助您使用 Docker 与 unstructured 交互。如果机器上尚未安装 Docker,请参阅此处。
注意:我们构建多平台镜像以支持 x86_64 和 Apple silicon 硬件。docker pull 应自动下载对应架构的镜像,但如有需要也可使用 --platform 指定(例如 --platform linux/amd64)。
我们为所有推送到 main 分支的提交构建 Docker 镜像。每个镜像以对应的短提交哈希(如 fbc7a69)和应用版本(如 0.5.5-dev1)标记。最新镜像还会标记为 latest。利用这一点,从镜像仓库执行 docker pull。
docker pull downloads.unstructured.io/unstructured-io/unstructured:latest
拉取完成后,可从该镜像创建容器并进入 shell。
# 创建容器
docker run -dt --name unstructured downloads.unstructured.io/unstructured-io/unstructured:latest
# 进入 Docker 镜像运行的 bash shell
docker exec -it unstructured bash
您也可以自行构建 Docker 镜像。注意基础镜像是 wolfi-base,会定期更新。如果本地构建镜像,可能因 wolfi-base 上游变更而导致 docker-build 失败。
如果只需解析一种数据类型,可以通过注释掉其他数据类型所需的依赖包/需求来加快构建速度。请参阅 Dockerfile 了解哪些行对您的用例是必需的。
make docker-build
# 进入 Docker 镜像运行的 bash shell
make docker-start-bash
在运行中的容器内,可直接在 Python 交互模式下尝试:
# 进入 Python 控制台,运行下面的分区函数
python3
>>> from unstructured.partition.pdf import partition_pdf
>>> elements = partition_pdf(filename="example-docs/layout-parser-paper-fast.pdf")
>>> from unstructured.partition.text import partition_text
>>> elements = partition_text(filename="example-docs/fake-text.txt")
使用以下说明开始使用 unstructured 并测试安装。
pip install "unstructured[all-docs]"pip install unstructuredpip install "unstructured[docx,pptx]"如果系统尚未安装以下依赖,请安装(根据要解析的文档类型,可能不需要全部):
libmagic-dev(文件类型检测)poppler-utils(图片和 PDF)tesseract-ocr(图片和 PDF,安装 tesseract-lang 以支持更多语言)libreoffice(MS Office 文档)pandoc 会通过 pypandoc-binary Python 包自动捆绑(无需系统安装)关于 Windows 安装建议及功能依赖,请参阅安装文档。
至此,您应能运行以下代码:
from unstructured.partition.auto import partition
elements = partition(filename="example-docs/eml/fake-email.eml")
print("\n\n".join([str(el) for el in elements]))
以下说明旨在帮助您在本地运行 unstructured 以贡献代码。
本项目使用 uv 进行依赖管理。先安装它:
# macOS / Linux
curl -LsSf https://astral.sh/uv/install.sh | sh
然后安装所有依赖(基础、扩展、开发、测试和 lint 组):
make install
这会运行 uv sync --locked --all-extras --all-groups,创建虚拟环境并一步安装所有内容。无需手动创建或激活虚拟环境。
如需仅安装特定文档类型的扩展:
uv sync --extra pdf
uv sync --extra csv --extra docx
修改 pyproject.toml 中的依赖后更新锁文件:
make lock
uv sync --extra pdf --extra image。tesseract。安装说明见此处。tesseract 和 poppler。pdf2image 文档提供了跨平台安装 poppler 的说明。此外,如果您计划为 unstructured 贡献代码,我们提供可选的 pre-commit 配置文件,确保代码符合项目的格式和 lint 标准。如果不希望每次提交前自动整理代码,可使用 make check 查看是否需要 lint 或格式调整,并用 make tidy 实施这些调整。
如果使用可选的 pre-commit,只需运行 pre-commit install 安装钩子(pre-commit 包已包含在 make install 中)。最后,若决定使用 pre-commit,也可用 pre-commit uninstall 卸载钩子。
除了在本地操作系统上开发,我们还提供 Docker 辅助开发环境:
make docker-start-dev
这会启动一个 Docker 容器,并将本地仓库挂载到 /mnt/local_unstructured。该 Docker 镜像允许您开发时不必担心操作系统与仓库及其依赖的兼容性。
如需更全面的文档,请访问 https://docs.unstructured.io 。您也可以在文档页了解我们的其他产品,包括 SaaS API。
以下是开源文档页面中几个对新用户有帮助的页面:
以下示例展示如何开始使用 unstructured 库。最简单的解析方式是使用 partition 函数。使用 partition 函数时,unstructured 会自动检测文件类型并路由到对应的文件专属分区函数。使用 partition 函数时,可能需要按文档类型安装额外依赖。例如,安装 docx 依赖需运行 pip install "unstructured[docx]"。详见安装指南。
from unstructured.partition.auto import partition
elements = partition("example-docs/layout-parser-paper.pdf")
运行 print("\n\n".join([str(el) for el in elements])) 可获取输出的字符串表示,形如:
LayoutParser : A Unified Toolkit for Deep Learning Based Document Image Analysis
Zejiang Shen 1 ( (cid:0) ), Ruochen Zhang 2 , Melissa Dell 3 , Benjamin Charles Germain Lee 4 , Jacob Carlson 3 , and
Weining Li 5
Abstract. Recent advances in document image analysis (DIA) have been primarily driven by the application of neural
networks. Ideally, research outcomes could be easily deployed in production and extended for further investigation.
However, various factors like loosely organized codebases and sophisticated model configurations complicate the easy
reuse of important innovations by a wide audience. Though there have been ongoing efforts to improve reusability and
simplify deep learning (DL) model development in disciplines like natural language processing and computer vision, none
of them are optimized for challenges in the domain of DIA. This represents a major gap in the existing toolkit, as DIA
is central to academic research across a wide range of disciplines in the social sciences and humanities. This paper
introduces LayoutParser, an open-source library for streamlining the usage of DL in DIA research and applications.
The core LayoutParser library comes with a set of simple and intuitive interfaces for applying and customizing DL models
for layout detection, character recognition, and many other document processing tasks. To promote extensibility,
LayoutParser also incorporates a community platform for sharing both pre-trained models and full document digitization
pipelines. We demonstrate that LayoutParser is helpful for both lightweight and large-scale digitization pipelines in
real-word use cases. The library is publicly available at https://layout-parser.github.io
Keywords: Document Image Analysis · Deep Learning · Layout Analysis · Character Recognition · Open Source library ·
Toolkit.
Introduction
Deep Learning(DL)-based approaches are the state-of-the-art for a wide range of document image analysis (DIA) tasks
including document image classification [11,
有关文件专属分区函数的完整选项和使用说明,请参阅我们文档中的分区部分。
请参阅我们的安全策略,了解如何报告安全漏洞。
遇到 Bug 了吗?请创建新的 GitHub Issue,并使用 Bug 报告模板描述问题。为帮助我们诊断,请运行 python scripts/collect_env.py 收集系统环境信息并包含在报告中。您的帮助将让我们持续改进软件——谢谢!
| 章节 | 描述 |
|---|---|
| 公司网站 | Unstructured.io 产品和公司信息 |
| 文档 | 完整 API 文档 |
| 批处理 | 通过 Unstructured 摄取批量文档 |
Unstructured 默认会向 GET https://packages.unstructured.io/python-telemetry 发送轻量分析数据:导入时一次库加载 ping,以及每次顶层公开分区调用的尽力而为的本地尝试。共享端点支持独立的启动和运行时查询参数模式。运行时事件包含 URL 查询参数形式的包版本、规范化平台/Python/架构值、固定枚举分区特征和聚合的最终元素计数;没有请求体。它们从不包含文档或元素内容、文件名、路径、分区提供的 URL、原始 MIME 值、异常详情、凭据、代理配置,或持久的安装、机器、进程、账户、用户或开发者标识。运行时传递从不等待分区处理的网络,没有重定向、重试、响应体下载或队列,也不查询代理或 netrc 环境设置。最多一个遥测守护进程可能滞留在网络操作中;后续事件在槽位被占用时丢弃,进程退出也不等待它。连接/读取超时限制套接字操作,但不限制总网络墙钟时长。
要在导入或分区前选择退出,请将 DO_NOT_TRACK 或 SCARF_NO_ANALYTICS 任一变量设置为去除空白后的非空值(例如 true、1、yes、false 或 0);任一变量都会禁用库加载和运行时遥测。取消设置或留空(仅空白)则保留默认行为。请参阅我们的隐私政策。