Docling Core

2.73.0 · active · verified Fri Apr 10

Docling Core is a Python library for defining, validating, and structuring data types and schemas. It's designed to align with the Docling specification, offering robust data validation capabilities. Currently at version 2.73.0, it undergoes frequent updates, often with daily or weekly releases in its 2.x series.

Warnings

Install

Imports

Quickstart

This example defines a `User` data type with `Field` validators for name, age, and email. It demonstrates how to instantiate a `DataType` with valid data and handles validation errors for invalid input.

from docling_core import Field, DataType

class User(DataType):
    name = Field(str, description="The user's full name")
    age = Field(int, min_value=0, description="The user's age")
    email = Field(str, format="email", description="The user's email address")

user_data = {
    "name": "John Doe",
    "age": 30,
    "email": "john.doe@example.com"
}

try:
    user = User(user_data)
    print(f"Validated user: {user.name}, {user.age}, {user.email}")
except Exception as e:
    print(f"Validation error: {e}")

# Example of invalid data
invalid_user_data = {
    "name": "Jane Doe",
    "age": -5,  # Invalid age
    "email": "invalid-email"
}

try:
    User(invalid_user_data)
except Exception as e:
    print(f"Validation error for invalid data: {e}")

view raw JSON →