$ show docling-project/docling
Docling is a production-grade Python library for converting diverse document formats (PDF, DOCX, PPTX, XLSX, HTML, LaTeX, EPUB, images, audio, video, email, EBCDIC, and more) into a unified, structured `DoclingDocument` representation. It is designed to serve as the document understanding layer for AI workflows, particularly Retrieval-Augmented Generation (RAG), agentic AI, and document extraction pipelines. The system provides a rich Python SDK, a Typer-based CLI (`docling convert`), a service client for remote conversion via `docling-serve`, and an MCP server. It supports multiple output formats including Markdown, JSON, HTML, DocTags, and plain text. Architecturally, Docling employs a modular pipeline system with pluggable backends for each input format and a stage-based processing model. The core pipeline (`StandardPdfPipeline`, `VlmPipeline`, `AsrPipeline`) orchestrates page-level operations (preprocessing, OCR, layout detection, table structure recognition, picture classification, reading order) and document-level enrichments (code/formula extraction, heading hierarchy, picture description). Inference engines are abstracted behind factory patterns supporting ONNX Runtime, HuggingFace Transformers, vLLM, MLX, KServe v2, and remote APIs. The library integrates with over 20 OCR engines and vision-language models, and includes a plugin system for extensibility. Key entry points include the `DocumentConverter` class, the CLI (`docling.cli.main`), and the service client (`docling.service_client`). External dependencies span PDF libraries (pypdfium2, docling-parse), ML frameworks (torch, transformers, onnxruntime), OCR engines (Tesseract, EasyOCR, RapidOCR), and cloud services (KServe, Azure, S3). The codebase is actively maintained with frequent releases, extensive test coverage, and a clear migration path from legacy components.
The LLM identified 4 files worth highlighting for reuse:
Implements a high-performance layout postprocessor using R-tree and interval tree spatial indices combined with a Union-Find data structure for efficient overlap detection and cell assignment. Handles cross-type overlaps (table vs picture), empty cluster removal, and cell merging. The spatial algorithms are self-contained and could be extracted for any geometric deduplication or clustering task.
A full Markdown-to-DoclingDocument parser backend built on the `marko` AST. Uses a lazy creation stack pattern (`_flush_creation_stack`) to handle nested headings, lists, and tables. Includes GFM table parsing, HTML block delegation, and defensive cleanup for malformed Markdown. The parser is self-contained and could be reused as a standalone Markdown-to-structured-document converter.
Defines the abstract base class `BaseVlmEngine` and a factory function `create_vlm_engine` that dynamically discovers engine implementations via a registry. Supports multiple backends (Transformers, vLLM, MLX, API) with a clean `initialize/predict_batch/cleanup` lifecycle. The pattern is reusable for any multi-backend inference system and demonstrates non-obvious skill in plugin architecture and runtime abstraction.
Provides synchronous and asynchronous watchers (`PollingWatcher`, `WebSocketWatcher`) for monitoring remote document conversion tasks. Implements automatic reconnection, fallback from WebSocket to polling, and configurable timeouts. The watcher pattern is self-contained and could be extracted for any long-running task monitoring system requiring both polling and push-based updates.