A Python SDK for interacting with Docling Serve API using Pydantic models
Project description
Docling Serve SDK
A Python SDK for interacting with Docling Serve API using Pydantic models.
Author: Alberto Ferrer
Email: albertof@barrahome.org
Repository: https://github.com/bet0x/docling-serve-sdk
Features
- ✅ Document conversion (PDF, DOCX, HTML, images, etc.)
- ✅ OCR processing with multiple engines
- ✅ Table extraction and structure analysis
- ✅ Image handling and processing
- ✅ Async/sync support
- ✅ Type-safe with Pydantic models
- ✅ Comprehensive error handling
Installation
# Clone or download the SDK
cd docling_serve_sdk
# Install with uv
uv pip install -e .
# Or with pip
pip install -e .
Quick Start
from docling_serve_sdk import DoclingClient
# Create client
client = DoclingClient(base_url="http://localhost:5001")
# Check health
health = client.health_check()
print(f"Status: {health.status}")
# Convert document
result = client.convert_file("document.pdf")
print(f"Content: {result.document['md_content']}")
Examples
Basic Conversion
from docling_serve_sdk import DoclingClient
client = DoclingClient(base_url="http://localhost:5001")
result = client.convert_file("document.pdf")
print(f"Status: {result.status}")
print(f"Processing time: {result.processing_time:.2f}s")
print(f"Content: {result.document['md_content']}")
Custom Options
from docling_serve_sdk import (
DoclingClient,
ConvertDocumentsRequestOptions,
InputFormat,
OutputFormat,
ImageRefMode,
OCREngine
)
# Create custom options
options = ConvertDocumentsRequestOptions(
from_formats=[InputFormat.PDF, InputFormat.DOCX],
to_formats=[OutputFormat.MD, OutputFormat.HTML],
image_export_mode=ImageRefMode.EMBEDDED,
do_ocr=True,
ocr_engine=OCREngine.EASYOCR,
include_images=True,
images_scale=2.0
)
# Convert with options
client = DoclingClient(base_url="http://localhost:5001")
result = client.convert_file("document.pdf", options=options)
Async Usage
import asyncio
from docling_serve_sdk import DoclingClient
async def convert_document():
client = DoclingClient(base_url="http://localhost:5001")
# Check health
health = await client.health_check_async()
print(f"Status: {health.status}")
# Convert document
result = await client.convert_file_async("document.pdf")
print(f"Content: {result.document['md_content']}")
# Run async function
asyncio.run(convert_document())
Error Handling
from docling_serve_sdk import DoclingClient, DoclingError, DoclingAPIError
client = DoclingClient(base_url="http://localhost:5001")
try:
result = client.convert_file("document.pdf")
print(f"Success: {result.status}")
except DoclingError as e:
print(f"Docling error: {e}")
except DoclingAPIError as e:
print(f"API error: {e}")
print(f"Status code: {e.status_code}")
except Exception as e:
print(f"Unexpected error: {e}")
Configuration Options
ConvertDocumentsRequestOptions
| Option | Type | Default | Description |
|---|---|---|---|
from_formats |
List[InputFormat] | All formats | Input formats to accept |
to_formats |
List[OutputFormat] | [MD] |
Output formats to generate |
image_export_mode |
ImageRefMode | EMBEDDED |
How to handle images |
do_ocr |
bool | True |
Enable OCR processing |
force_ocr |
bool | False |
Force OCR over existing text |
ocr_engine |
OCREngine | EASYOCR |
OCR engine to use |
pdf_backend |
PdfBackend | DLPARSE_V4 |
PDF processing backend |
table_mode |
TableMode | ACCURATE |
Table processing mode |
include_images |
bool | True |
Include images in output |
images_scale |
float | 2.0 |
Image scale factor |
Supported Formats
Input Formats:
- PDF, DOCX, PPTX, HTML, MD, CSV, XLSX
- Images (PNG, JPG, etc.)
- XML (USPTO, JATS)
- Audio files
Output Formats:
- Markdown (MD)
- HTML
- JSON
- Text
- DocTags
Testing
# Run tests
uv run python test_sdk.py
# Or with pytest
pytest test_sdk.py
Requirements
- Python 3.8+
- httpx
- pydantic
License
MIT License
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
Support
For issues and questions:
- Check the Docling Serve documentation
- Open an issue in this repository
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file docling_serve_sdk-1.1.0.tar.gz.
File metadata
- Download URL: docling_serve_sdk-1.1.0.tar.gz
- Upload date:
- Size: 11.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7d690d29c6c58724e9d1143100a2868225f56a0c09b9ad08517e497772c51839
|
|
| MD5 |
b11e5c4d9139f57ce67fad0326062b83
|
|
| BLAKE2b-256 |
38a4a556dcf48d707ac6d11e08ca19f84205ce75322c583c1fff5aeb2993eeae
|
File details
Details for the file docling_serve_sdk-1.1.0-py3-none-any.whl.
File metadata
- Download URL: docling_serve_sdk-1.1.0-py3-none-any.whl
- Upload date:
- Size: 10.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bc234116ce7b8608f6ac6efc8c4d7cc48055a2234d8f6f89eec6cf0e5e82dc6e
|
|
| MD5 |
770e31b8e74046e7b95ed288884ffb32
|
|
| BLAKE2b-256 |
85abce5f074cd3aa51bfa426fe860c65c5e9783e3d90cc3923b120d04419b8e8
|