Skip to main content

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

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests
  5. Submit a pull request

Support

For issues and questions:

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

docling_serve_sdk-1.0.0.tar.gz (10.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

docling_serve_sdk-1.0.0-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

Details for the file docling_serve_sdk-1.0.0.tar.gz.

File metadata

  • Download URL: docling_serve_sdk-1.0.0.tar.gz
  • Upload date:
  • Size: 10.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.18

File hashes

Hashes for docling_serve_sdk-1.0.0.tar.gz
Algorithm Hash digest
SHA256 abee8cdee2ec5b0c568818c9113f84a6e985321d70ef803e3dcaa884cc57379e
MD5 a93a768a91a85e6df590089493608d0a
BLAKE2b-256 0189028f05342b839bf9b1d5e87faaeef4fd2e80cbad63bd1ca9f1cc46816545

See more details on using hashes here.

File details

Details for the file docling_serve_sdk-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for docling_serve_sdk-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8de3a15006c730462ce59192c7ef93300f750ccd69240331a6b2ef7d81daa12e
MD5 7702fe15f9500daf7ff5da1a615b523c
BLAKE2b-256 2fd678650370ce5604a58b02951fb4f909a774b4418b3524b2624f2a1cc8f7f9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page