Skip to content

A python library to define and validate data types in Docling.

License

Notifications You must be signed in to change notification settings

DS4SD/docling-core

Repository files navigation

Docling Core

PyPI version Python Poetry Code style: black Imports: isort Checked with mypy Pydantic v2 pre-commit License MIT

Docling Core is a library that defines the data types in Docling, leveraging pydantic models.

Installation

To use Docling Core, simply install docling-core from your package manager, e.g. pip:

pip install docling-core

Development setup

To develop for Docling Core, you need Python 3.9 / 3.10 / 3.11 / 3.12 / 3.13 and Poetry. You can then install from your local clone's root dir:

poetry install

To run the pytest suite, execute:

poetry run pytest test

Basic Usage

  • You can validate your JSON objects using the pydantic class definition.

    from docling_core.types import DoclingDocument
    
    data_dict = {...}  # here the object you want to validate, as a dictionary
    DoclingDocument.model_validate(data_dict)
    
    data_str = {...}  # here the object as a JSON string
    DoclingDocument.model_validate_json(data_str)
  • You can generate the JSON schema of a model with the script generate_jsonschema.

    # for the `DoclingDocument` type
    generate_jsonschema DoclingDocument
    
    # for the use `Record` type
    generate_jsonschema Record

Documentation

Docling Core contains 3 top-level data types:

  • DoclingDocument for publications like books, articles, reports, or patents. The JSON that can be exported using Docling follows this schema. The DoclingDocument type also models the metadata that may be attached to the converted document. Check DoclingDocument for the full JSON schema.
  • Record for structured database records, centered on an entity or subject that is provided with a list of attributes. Related to records, the statements can represent annotations on text by Natural Language Processing (NLP) tools. Check Record for the full JSON schema.
  • Generic for any data representation, ensuring minimal configuration and maximum flexibility. Check Generic for the full JSON schema.

The data schemas are defined using pydantic models, which provide built-in processes to support the creation of data that adhere to those models.

Contributing

Please read Contributing to Docling Core for details.

References

If you use Docling Core in your projects, please consider citing the following:

@techreport{Docling,
  author = "Deep Search Team",
  month = 8,
  title = "Docling Technical Report",
  url = "https://arxiv.org/abs/2408.09869",
  eprint = "2408.09869",
  doi = "10.48550/arXiv.2408.09869",
  version = "1.0.0",
  year = 2024
}

License

The Docling Core codebase is under MIT license. For individual model usage, please refer to the model licenses found in the original packages.