首页
/ Docling Slim 包深度解析:用最小依赖按需构建文档处理 SDK

Docling Slim 包深度解析:用最小依赖按需构建文档处理 SDK

2026-09-06 14:14:49作者:晏闻田Solitary

Docling Slim 是 Docling 项目的模块化核心发行包,它把原本"全量安装"的 docling 拆分为仅约 50MB 基础依赖的轻量内核,并围绕 PDF/Office/Web 格式、OCR 引擎、模型推理和 CLI 等能力提供 20 余个可选 extras。本文基于 packages/docling-slim/README.md 并结合根目录 pyproject.toml 的实际声明,完整梳理 Slim 包的定位、安装方式、全部 extras 清单与底层依赖映射,帮助你在生产部署与资源受限场景中精确控制安装体积与依赖面。

Docling Slim 是什么:一个"最小内核 + 可选插件"的发行包

packages/docling-slim/README.md 将 Docling Slim 定义为"Lightweight SDK for parsing documents with minimal dependencies and opt-in extras"(最小依赖、按需选装组件的文档解析 SDK)。它的核心设计思想是:

  • 基础依赖极少docling-slim 安装后可提供核心文档处理能力,基础依赖约 50MB;
  • 能力按 extras 选装:PDF 解析、Office 格式、OCR 引擎、本地模型推理、CLI 等能力全部通过 pip extras(pip install docling-slim[xxx])叠加;
  • 同一份源码:从 pyproject.toml 的构建配置看,docling-slim 的 wheel 直接打包仓库根目录下的 docling/ 源码目录(packages = ["docling"]),即 Slim 包就是 Docling 完整 Python 模块本体,区别只在于默认携带的依赖不同

这一点从 根项目 pyproject.toml 可以得到直接印证:docling-slim 2.124.0 的基础依赖只有 8 个包:

# MINIMAL BASE (8 packages) - ~50MB
dependencies = [
  'pydantic>=2.0.0,<3.0.0',
  'docling-core>=2.91.0,<3.0.0',
  'pydantic-settings>=2.3.0,<3.0.0',
  'filetype>=1.2.0,<2.0.0',
  'requests>=2.32.2,<3.0.0',
  'certifi>=2024.7.4',
  'pluggy>=1.0.0,<2.0.0',
  'tqdm>=4.65.0,<5.0.0',
]

其中 docling-core 提供统一的文档表示(DoclingDocument)与序列化能力,pluggy 支撑插件机制,filetype 用于文件类型探测,requests/certifi 负责网络请求。这意味着即便什么都不加装,你也能导入 docling 模块并使用不依赖重型三方库的功能路径;而需要 PDF 解析、表格识别、OCR 等具体能力时再选装对应 extra。

同时该文件声明了一个插件入口点(pyproject.toml):

[project.entry-points.docling]
"docling_defaults" = "docling.models.plugins.defaults"

对应源码 docling/models/plugins/defaults.py,从源码结构看,Docling 通过 entry point 发现默认模型插件,这也解释了为什么插件机制本身可以留在最小内核里,而具体模型库可以全部外置为 extras。

选型建议:docling 与 docling-slim 怎么选

README 给出的选型原则非常直接:

  • 多数用户建议直接安装完整版 docling:功能齐全、包含 CLI,是最简单的上手方式:

    pip install docling
    
  • 需要细粒度控制依赖或最小化安装体积时,使用 docling-slim

这里的"完整版"实际上正是 Slim 包的组合。查看 packages/docling/pyproject.toml 可以看到,docling 是一个meta 包(元包)

# Meta-package: pulls in docling-slim with standard extras (includes CLI).
# The `docling` Python module itself is provided by docling-slim.
dependencies = [
  'docling-slim[standard]==2.124.0',
]

也就是说,pip install docling 等价于安装 docling-slim 并启用 standard 便捷 bundle,docling 包本身不再携带任何 Python 模块(wheel 配置为 bypass-selection = true),所有代码都来自 docling-slim 的 wheel——这一设计(见 packages/docling/pyproject.toml 的注释)正是为了避免历史上"两个 wheel 都打包同一份 docling/ 模块导致安装冲突"的 bug。

此外仓库还有一个 packages/docling-client/pyproject.toml 中的 docling-client 包,它同样是 meta 包,仅依赖 docling-slim[service-client]==2.124.0,用于"只需要远程调用 Docling Serve API、不需要本地模型"的客户端场景。三者关系可以概括为:

本质 依赖
docling-slim 源码本体(docling/ 模块)+ 最小 8 个基础依赖 按需选择 extras
docling meta 包 docling-slim[standard](等价于旧版完整包)
docling-client meta 包 docling-slim[service-client](仅远程服务客户端)

三者通过 uv workspace 组织在同一个仓库中(pyproject.toml[tool.uv.workspace] members = ["packages/docling", "packages/docling-client"]),版本号统一为 2.124.0。

安装方式与典型组合

README 给出了四个最常用的安装示例,覆盖本地模型 PDF 解析、纯 Office、CLI 与远程服务客户端四类场景:

# PDF support with local models
pip install docling-slim[format-pdf,models-local]

# Office formats only
pip install docling-slim[format-office]

# PDF + CLI
pip install docling-slim[format-pdf,cli]

# Docling service client for using the Docling Serve API
pip install docling-slim[service-client]

仓库内其他文档中的实际用法与之一致,例如服务客户端示例 docs/examples/service_client/README.md 使用 pip install "docling-slim[service-client]",而视频处理文档 docs/usage/processing_audio_media.md 使用 pip install "docling-slim[format-video]"

全部 Extras 清单:从 README 表格到 pyproject 依赖映射

以下完整继承 packages/docling-slim/README.md 的 extras 清单,并在关键项上补充了 pyproject.toml 中的真实依赖声明。

便捷 Bundle

Extra 说明 典型用途
standard 全部标准功能(与 docling 包相同) 完整功能使用
all 全部可用 extras 完整安装

从源码看,两个 bundle 的展开式是(pyproject.toml):

standard = [
  'docling-slim[format-pdf,models-local,feat-ocr-rapidocr,format-office,format-web,format-latex,format-email,format-iwork,feat-chunking,extract-core,service-client,cli]',
]

all = [
  # format-video is deliberately excluded: it pulls in resemblyzer, which
  # requires webrtcvad, which has no wheels and needs Python dev headers
  # (Python.h) plus a C compiler to build from source. `all` must install
  # cleanly without a compiler, so speaker diarization stays opt-in via
  # docling-slim[format-video].
  'docling-slim[standard,models-vlm-inline,format-audio,format-html-render,format-xml-jats,format-xml-uspto,format-xml-xbrl,models-remote,models-onnxruntime,feat-ocr-easyocr,feat-ocr-tesserocr,feat-ocr-mac]',
]

值得注意的实现细节:all 故意排除了 format-video——因为它会引入 resemblyzer,其依赖 webrtcvad 没有预编译 wheel,需要 Python 开发头文件和 C 编译器才能源码构建。为保证 all 在无编译器环境下也能干净安装,说话人分离(speaker diarization)能力保留为需要显式选装的 format-video

CLI

Extra 说明 对应依赖
cli 命令行接口(typer、rich) typer>=0.12.5,<0.27.0rich>=13.0.0python-dotenv~=1.0pyproject.toml

python-dotenv 在注释中标注为"尽力而为"的 .env 加载支持(服务于 docling convert-remote 命令),缺失时该命令仍可通过命令行参数与环境变量工作。

CLI 的两个入口点在 pyproject.toml 中声明:

[project.scripts]
docling = "docling.cli.main:app"
docling-tools = "docling.cli.tools:app"

对应源码分别为 docling/cli/main.pydocling/cli/tools.pypackages/docling/pyproject.toml 还解释了为何 meta 包要重复声明这两个入口点:uv tool install docling 只会把所命名包自己的 scripts 链接到 ~/.local/bin,而实际模块在运行时由 docling-slim 提供。

核心组件

Extra 说明 对应依赖
convert-core 核心转换组件 numpy>=1.24.0,<3.0.0pillow>=10.0.0,<13.0.0rtree>=1.3.0,<2.0.0scipy>=1.6.0,<2.0.0pyproject.toml
extract-core 结构化信息抽取 docling-slim[convert-core] + polyfactory>=2.22.2pyproject.toml

注意 extract-core 会级联引入 convert-core,体现了 extras 之间"组合复用"的设计:格式/功能 extras 普遍通过 docling-slim[xxx] 的自引用方式叠加底层依赖。

格式支持

PDF 格式

Extra 说明 对应依赖
format-pdf PDF 解析(pypdfium2 + docling-parse) 组合 format-pdf-pypdfium2format-pdf-doclingpyproject.toml
format-pdf-pypdfium2 仅 PDF 渲染 pypdfium2>=4.30.0,!=4.30.1,<6.0.0
format-pdf-docling 高级 PDF 解析 docling-parse>=7.16.0,<8.0.0 + pypdfium2

PDF 能力被拆成"渲染层"(pypdfium2)与"版面解析层"(docling-parse)两个可独立选装的 extra,format-pdf 是它们的组合。需要轻量 PDF 支持(只做渲染/读取)时,只装 format-pdf-pypdfium2 即可。

Office 格式(office = docx + pptx + xlsx)

Extra 说明 对应依赖
format-office 全部 Office 格式 format-docx + format-pptx + format-xlsx
format-docx Microsoft Word 文档 python-docx>=1.2.0,<2.0.0
format-pptx Microsoft PowerPoint python-pptx>=1.0.2,<2.0.0
format-xlsx Microsoft Excel openpyxl>=3.1.5,<4.0.0

Web 格式(web = html + markdown)

Extra 说明 对应依赖
format-web HTML 与 Markdown format-html + format-markdown
format-html HTML 解析 beautifulsoup4>=4.12.3,<5.0.0
format-markdown Markdown 解析 marko>=2.1.2,<3.0.0

其他格式

Extra 说明 对应依赖
format-latex LaTeX 文档(.tex) pylatexenc>=2.10,<3.0pyproject.toml
format-xml-xbrl XBRL 财务报告 arelle-release>=2.38.17,<3.0.0
format-html-render 基于 Playwright 的 HTML 渲染 playwright>=1.58.0
format-audio 音频转写(Whisper) openai-whispernumba,非 Apple Silicon macOS 平台使用 whisper-s2t-reborn,macOS arm64 使用 mlx-whisperpyproject.toml

此外,pyproject.toml 中还有 README 表格未逐一列出的格式 extras(它们同样可通过 pip install docling-slim[...] 选装):

  • format-opendocument:ODT/ODS/ODP,依赖 odfdopyproject.toml);
  • format-email.eml/.msg 邮件,在 format-html 基础上叠加 mail-parserpython-oxmsgpyproject.toml);
  • format-iwork:Apple Pages(.pages),仅需 defusedxml——注释说明 Pages 5+ 的 Snappy 解压器用纯 Python 实现,无需编译型依赖(pyproject.toml);
  • format-xml-jats:JATS 学术文章 XML,依赖 lxml
  • format-xml-uspto:USPTO 专利 XML,依赖 defusedxml
  • format-video:在 format-audio 上叠加 resemblyzersoundfilescikit-learnlibrosa,用于说话人分离(pyproject.toml)。

OCR 引擎

Extra 说明 对应依赖
feat-ocr-rapidocr RapidOCR(轻量) rapidocr>=3.9.1,<4.0.0
feat-ocr-rapidocr-onnx RapidOCR + ONNX 运行时 rapidocr + 按 Python 版本条件选 onnxruntimepyproject.toml
feat-ocr-easyocr EasyOCR easyocr>=1.7,<2.0 + scikit-image>=0.19pyproject.toml
feat-ocr-tesserocr Tesseract OCR tesserocr>=2.7.1,<3.0.0 + pandas>=2.1.4,<4.0.0
feat-ocr-mac macOS 原生 OCR ocrmac>=1.0.0,<2.0.0,仅 sys_platform == "darwin" 时生效

从依赖声明中的注释可以看到几个值得关注的工程细节:

  • feat-ocr-easyocr 额外钉住 scikit-image>=0.19,是因为 easyocr 对其声明没有下限,在 Python 3.10 上依赖解析器可能回溯到 2019 年的 0.16.2 版本(无 Py3.10 wheel),导致源码构建失败;
  • feat-ocr-rapidocr-onnx 按 Python 版本分档约束 onnxruntime(3.11 以下 <1.24,3.14 及以上 >=1.24.1,<2.0.0),适配不同解释器的可用 wheel;
  • pyproject.toml 中还声明了 README 未列出的 feat-ocr-nemotron(NVIDIA Nemotron OCR),仅在 Linux x86_64 + Python 3.12 环境启用(pyproject.toml)。

OCR 引擎的运行时选择方式与安装 extras 相互对应:安装 extras 后,通过 DocumentConverterocr_options 指定引擎,例如 docs/getting_started/installation.md 展示了切换 TesseractOcrOptions 的完整代码(该文档还列出了 EasyOCR、RapidOCR、Nemotron、Tesseract CLI、OcrMac 等引擎与 extras 的对应表)。

模型类

Extra 说明 对应依赖
models-local 本地 PyTorch 模型(GPU/CPU 推理) torch>=2.2.2,<3.0.0torchvisiondocling-ibm-models>=3.13.0,<5acceleratehuggingface_hubdefusedxmlpyproject.toml
models-remote 远程模型服务(Triton) tritonclient[grpc]>=2.65.0,<3.0.0
models-onnxruntime ONNX Runtime 加速 按平台/Python 版本选择 onnxruntimeonnxruntime-gpupyproject.toml
models-vlm-inline 视觉语言模型(内联处理) transformers>=4.42.0(macOS 上限 <5.9.0、其他平台 <6.0.0)、accelerate、Apple Silicon 上 mlx-vlmqwen-vl-utilspeftpyproject.toml

其他功能

Extra 说明 对应依赖
feat-chunking 文档分块(RAG 场景) docling-core[chunking]>=2.73.0,<3.0.0pyproject.toml
service-client Docling 服务客户端(远程处理) httpx>=0.28,<1.0.0websockets>=14.0,<17.0typerrichpython-dotenv~=1.0pyproject.toml

向后兼容:旧版 docling extras 的映射

packages/docling/pyproject.toml 中,docling meta 包还重新声明了一组与旧版本同名的 extras,全部转发到 docling-slim 的新 extras 命名,保证存量用户的 pip install "docling[xxx]" 命令继续可用:

[project.optional-dependencies]
easyocr        = ['docling-slim[feat-ocr-easyocr]==2.124.0']
tesserocr      = ['docling-slim[feat-ocr-tesserocr]==2.124.0']
ocrmac         = ['docling-slim[feat-ocr-mac]==2.124.0']
vlm            = ['docling-slim[models-vlm-inline]==2.124.0']
rapidocr       = ['docling-slim[feat-ocr-rapidocr-onnx]==2.124.0']
asr            = ['docling-slim[format-audio]==2.124.0']
htmlrender     = ['docling-slim[format-html-render]==2.124.0']
remote-serving = ['docling-slim[models-remote]==2.124.0']
onnxruntime    = ['docling-slim[models-onnxruntime]==2.124.0']
xbrl           = ['docling-slim[format-xml-xbrl]==2.124.0']

这份映射表对迁移旧项目很有价值:例如旧的 docling[vlm]docling[asr] 分别等价于新的 docling-slim[models-vlm-inline]docling-slim[format-audio]。结合 docs/getting_started/installation.md 中的 extras 说明,可以看出官方文档仍以 docling 包的 extras 命名作为对外口径,而 Slim 包的细粒度命名是更底层的组织方式。

实际选用策略:按能力矩阵拼装 extras

基于以上清单,一个可操作的选型流程是:

  1. 只做格式解析、不要模型pip install docling-slim[format-pdf](复杂版面)或 [format-pdf-pypdfium2](仅渲染);Office 场景用 [format-office]
  2. 要跑本地版面/表格/OCR 模型:追加 models-local(PyTorch 全家桶);追求更轻量推理可用 models-onnxruntime
  3. 需要 OCR:按引擎选 feat-ocr-rapidocr(轻量)、feat-ocr-rapidocr-onnx(ONNX 优化)、feat-ocr-easyocr(多语言)、feat-ocr-tesserocr(需系统安装 Tesseract,见 docs/getting_started/installation.md 的系统依赖说明)或 feat-ocr-mac(仅 macOS);
  4. RAG 分块:追加 feat-chunking(底层是 docling-core 的 chunking extra,对应源码 docling/chunking/init.py);
  5. 只调用远程 Docling Servepip install docling-slim[service-client](或直接 pip install docling-client),客户端 SDK 位于 docling/service_client/,示例见 docs/examples/service_client/README.md
  6. 要 CLI:追加 cli,获得 doclingdocling-tools 两个可执行命令;
  7. 不确定就对齐官方默认:使用 standard bundle(pip install docling 的效果)或 all(注意 format-video 需显式追加)。

小结

Docling Slim 通过"8 个基础依赖的最小内核 + 细粒度 extras"的方式重构了 Docling 的分发形态:doclingdocling-client 退化为转发到 docling-slim[standard] / docling-slim[service-client] 的 meta 包,全部源码与 CLI 入口点集中在 pyproject.toml 定义的 docling-slim wheel 中。对于需要控制安装体积、规避不必要重依赖(如 torch、playwright、whisper)的部署场景,按上文能力矩阵拼装 extras 即可获得可复现、可审计的依赖集;而绝大多数用户直接 pip install docling 即可获得与 standard bundle 一致的完整体验。

参考路径packages/docling-slim/README.md(本文主体来源)、pyproject.toml(extras 依赖声明)、packages/docling/pyproject.toml(meta 包与兼容映射)、packages/docling-client/pyproject.toml(客户端 meta 包)、docs/getting_started/installation.md(extras 与 OCR 引擎说明)、docs/examples/service_client/README.md(service-client 用法示例)。

登录后查看全文
热门项目推荐
相关项目推荐