Optional Dependency Management#
Docling separates core functionality from packages that carry licensing risk, heavy transitive dependencies, or platform-specific constraints by placing them in named optional-dependency extras in pyproject.toml. This prevents adoption blockers for organizations with strict license policies while preserving full feature availability for users who opt in.
Why packages become optional#
Two recurring reasons motivate moving a package to an extra:
- License risk. RapidOCR's transitive dependency on
libopencvpulls in packages under GPL-2.0 (ffmpeg,x264,x265) and other restrictive licenses. Movingrapidocrout of core dependencies allows organizations that cannot accept these licenses to install Docling without them. - Missing or incomplete implementation.
extract-msg(for Outlook.msgparsing) was added to theformat-emailextra only after the backend was actually implemented, so the feature doesn't ship as dead weight or with broken imports before it is ready.
Extra taxonomy#
Extras are grouped by function using consistent prefixes :
| Prefix | Purpose | Examples |
|---|---|---|
format-* | File format parsers | format-pdf, format-email, format-office |
feat-ocr-* | OCR engine back-ends | feat-ocr-rapidocr, feat-ocr-easyocr, feat-ocr-mac |
models-* | Inference runtimes/model weights | models-local, models-onnxruntime, models-vlm-inline |
feat-* | Other opt-in features | feat-chunking |
Two convenience bundles aggregate the most common combinations: standard (PDF + Office + email + RapidOCR + chunking + CLI) and all (everything) .
Note: The extract-msg package for Outlook .msg support was added to format-email in PR #3716. If it is not visible in the pyproject.toml snapshot above, check the live file — the snapshot reflects a specific commit.
OCR engine: graceful fallback#
Because OCR engines are optional, OcrAutoModel implements a runtime selection cascade rather than a hard import :
- macOS: tries
ocrmacfirst (platform-specific) - Linux: tries
nemotron-ocr(platform- and hardware-gated) - All platforms: tries
rapidocrwithonnxruntimebackend - All platforms: tries
easyocr - All platforms: tries
rapidocrwithtorchbackend
Each step wraps the import in a try/except ImportError, so a missing package is logged and skipped rather than crashing. If no engine is found at all, the model logs a warning and yields pages through unchanged . Before PR #3248, rapidocr was a hard dependency, meaning this fallback was never reached in practice; making it optional exposed the cascade to users for the first time .
The same pattern applies to extract_msg in the email backend: the module is listed under allowed-unresolved-imports in the type-checker configuration so that import extract_msg can be guarded at runtime without causing type-check failures .
Installing optional extras#
# OCR support (recommended)
pip install 'docling[feat-ocr-rapidocr]'
# Outlook .msg email support
pip install 'docling[format-email]'
# Everything
pip install 'docling[all]'
Users migrating from earlier versions where rapidocr was a core dependency must now install it explicitly via pip install 'docling[feat-ocr-rapidocr]' .
Key files#
pyproject.toml— canonical list of all extras and their version constraintsdocling/models/stages/ocr/auto_ocr_model.py— OCR engine auto-selection and graceful fallback logicdocling/backend/email_backend.py— dual.eml/.msgparsing paths gated on optionalextract_msgimport