Docling Document
This is an automatic generated API reference of the DoclingDocument type.
doc
Package for models defined by the Document type.
Classes:
-
DoclingDocument
βDoclingDocument.
-
DocumentOrigin
βFileSource.
-
DocItem
βDocItem.
-
DocItemLabel
βDocItemLabel.
-
ProvenanceItem
βProvenanceItem.
-
GroupItem
βGroupItem.
-
GroupLabel
βGroupLabel.
-
NodeItem
βNodeItem.
-
PageItem
βPageItem.
-
FloatingItem
βFloatingItem.
-
TextItem
βTextItem.
-
TableItem
βTableItem.
-
TableCell
βTableCell.
-
TableData
βBaseTableData.
-
TableCellLabel
βTableCellLabel.
-
KeyValueItem
βKeyValueItem.
-
SectionHeaderItem
βSectionItem.
-
PictureItem
βPictureItem.
-
ImageRef
βImageRef.
-
PictureClassificationClass
βPictureClassificationData.
-
PictureClassificationData
βPictureClassificationData.
-
RefItem
βRefItem.
-
BoundingBox
βBoundingBox.
-
CoordOrigin
βCoordOrigin.
-
ImageRefMode
βImageRefMode.
-
Size
βSize.
DoclingDocument
Bases: BaseModel
DoclingDocument.
Methods:
-
add_code
βadd_code.
-
add_form
βadd_form.
-
add_group
βadd_group.
-
add_heading
βadd_heading.
-
add_key_values
βadd_key_values.
-
add_list_item
βadd_list_item.
-
add_page
βadd_page.
-
add_picture
βadd_picture.
-
add_table
βadd_table.
-
add_text
βadd_text.
-
add_title
βadd_title.
-
check_version_is_compatible
βCheck if this document version is compatible with current version.
-
export_to_dict
βExport to dict.
-
export_to_document_tokens
βExports the document content to a DocumentToken format.
-
export_to_element_tree
βExport_to_element_tree.
-
export_to_html
βSerialize to HTML.
-
export_to_markdown
βSerialize to Markdown.
-
export_to_text
βexport_to_text.
-
iterate_items
βiterate_elements.
-
load_from_doctags
βLoad Docling document from lists of DocTags and Images.
-
load_from_json
βload_from_json.
-
load_from_yaml
βload_from_yaml.
-
num_pages
βnum_pages.
-
print_element_tree
βPrint_element_tree.
-
save_as_doctags
βSave the document content to DocTags format.
-
save_as_document_tokens
βSave the document content to a DocumentToken format.
-
save_as_html
βSave to HTML.
-
save_as_json
βSave as json.
-
save_as_markdown
βSave to markdown.
-
save_as_yaml
βSave as yaml.
-
transform_to_content_layer
βtransform_to_content_layer.
-
validate_document
βvalidate_document.
-
validate_tree
βvalidate_tree.
Attributes:
-
body
(GroupItem
) β -
form_items
(List[FormItem]
) β -
furniture
(Annotated[GroupItem, Field(deprecated=True)]
) β -
groups
(List[GroupItem]
) β -
key_value_items
(List[KeyValueItem]
) β -
name
(str
) β -
origin
(Optional[DocumentOrigin]
) β -
pages
(Dict[int, PageItem]
) β -
pictures
(List[PictureItem]
) β -
schema_name
(Literal['DoclingDocument']
) β -
tables
(List[TableItem]
) β -
texts
(List[Union[SectionHeaderItem, ListItem, TextItem, CodeItem]]
) β -
version
(Annotated[str, StringConstraints(pattern=VERSION_PATTERN, strict=True)]
) β
form_items
form_items: List[FormItem] = []
furniture
furniture: Annotated[GroupItem, Field(deprecated=True)] = (
GroupItem(
name="_root_",
self_ref="#/furniture",
content_layer=FURNITURE,
)
)
name
name: str
schema_name
schema_name: Literal['DoclingDocument'] = 'DoclingDocument'
version
version: Annotated[
str,
StringConstraints(pattern=VERSION_PATTERN, strict=True),
] = CURRENT_VERSION
add_code
add_code(
text: str,
code_language: Optional[CodeLanguageLabel] = None,
orig: Optional[str] = None,
caption: Optional[Union[TextItem, RefItem]] = None,
prov: Optional[ProvenanceItem] = None,
parent: Optional[NodeItem] = None,
content_layer: Optional[ContentLayer] = None,
)
add_code.
Parameters:
-
text
(str
) βstr:
-
code_language
(Optional[CodeLanguageLabel]
, default:None
) βOptional[str]: (Default value = None)
-
orig
(Optional[str]
, default:None
) βOptional[str]: (Default value = None)
-
caption
(Optional[Union[TextItem, RefItem]]
, default:None
) βOptional[Union[TextItem:
-
RefItem]]
β(Default value = None)
-
prov
(Optional[ProvenanceItem]
, default:None
) βOptional[ProvenanceItem]: (Default value = None)
-
parent
(Optional[NodeItem]
, default:None
) βOptional[NodeItem]: (Default value = None)
add_form
add_form(
graph: GraphData,
prov: Optional[ProvenanceItem] = None,
parent: Optional[NodeItem] = None,
)
add_form.
Parameters:
-
graph
(GraphData
) βGraphData:
-
prov
(Optional[ProvenanceItem]
, default:None
) βOptional[ProvenanceItem]: (Default value = None)
-
parent
(Optional[NodeItem]
, default:None
) βOptional[NodeItem]: (Default value = None)
add_group
add_group(
label: Optional[GroupLabel] = None,
name: Optional[str] = None,
parent: Optional[NodeItem] = None,
content_layer: Optional[ContentLayer] = None,
) -> GroupItem
add_group.
Parameters:
-
label
(Optional[GroupLabel]
, default:None
) βOptional[GroupLabel]: (Default value = None)
-
name
(Optional[str]
, default:None
) βOptional[str]: (Default value = None)
-
parent
(Optional[NodeItem]
, default:None
) βOptional[NodeItem]: (Default value = None)
add_heading
add_heading(
text: str,
orig: Optional[str] = None,
level: LevelNumber = 1,
prov: Optional[ProvenanceItem] = None,
parent: Optional[NodeItem] = None,
content_layer: Optional[ContentLayer] = None,
)
add_heading.
Parameters:
-
label
βDocItemLabel:
-
text
(str
) βstr:
-
orig
(Optional[str]
, default:None
) βOptional[str]: (Default value = None)
-
level
(LevelNumber
, default:1
) βLevelNumber: (Default value = 1)
-
prov
(Optional[ProvenanceItem]
, default:None
) βOptional[ProvenanceItem]: (Default value = None)
-
parent
(Optional[NodeItem]
, default:None
) βOptional[NodeItem]: (Default value = None)
add_key_values
add_key_values(
graph: GraphData,
prov: Optional[ProvenanceItem] = None,
parent: Optional[NodeItem] = None,
)
add_key_values.
Parameters:
-
graph
(GraphData
) βGraphData:
-
prov
(Optional[ProvenanceItem]
, default:None
) βOptional[ProvenanceItem]: (Default value = None)
-
parent
(Optional[NodeItem]
, default:None
) βOptional[NodeItem]: (Default value = None)
add_list_item
add_list_item(
text: str,
enumerated: bool = False,
marker: Optional[str] = None,
orig: Optional[str] = None,
prov: Optional[ProvenanceItem] = None,
parent: Optional[NodeItem] = None,
content_layer: Optional[ContentLayer] = None,
)
add_list_item.
Parameters:
-
label
βstr:
-
text
(str
) βstr:
-
orig
(Optional[str]
, default:None
) βOptional[str]: (Default value = None)
-
prov
(Optional[ProvenanceItem]
, default:None
) βOptional[ProvenanceItem]: (Default value = None)
-
parent
(Optional[NodeItem]
, default:None
) βOptional[NodeItem]: (Default value = None)
add_page
add_picture
add_picture(
annotations: List[PictureDataType] = [],
image: Optional[ImageRef] = None,
caption: Optional[Union[TextItem, RefItem]] = None,
prov: Optional[ProvenanceItem] = None,
parent: Optional[NodeItem] = None,
content_layer: Optional[ContentLayer] = None,
)
add_picture.
Parameters:
-
data
βList[PictureData]: (Default value = [])
-
caption
(Optional[Union[TextItem, RefItem]]
, default:None
) βOptional[Union[TextItem:
-
RefItem]]
β(Default value = None)
-
prov
(Optional[ProvenanceItem]
, default:None
) βOptional[ProvenanceItem]: (Default value = None)
-
parent
(Optional[NodeItem]
, default:None
) βOptional[NodeItem]: (Default value = None)
add_table
add_table(
data: TableData,
caption: Optional[Union[TextItem, RefItem]] = None,
prov: Optional[ProvenanceItem] = None,
parent: Optional[NodeItem] = None,
label: DocItemLabel = TABLE,
content_layer: Optional[ContentLayer] = None,
)
add_table.
Parameters:
-
data
(TableData
) βTableData:
-
caption
(Optional[Union[TextItem, RefItem]]
, default:None
) βOptional[Union[TextItem, RefItem]]: (Default value = None)
-
prov
(Optional[ProvenanceItem]
, default:None
) βOptional[ProvenanceItem]: (Default value = None)
-
parent
(Optional[NodeItem]
, default:None
) βOptional[NodeItem]: (Default value = None)
-
label
(DocItemLabel
, default:TABLE
) βDocItemLabel: (Default value = DocItemLabel.TABLE)
add_text
add_text(
label: DocItemLabel,
text: str,
orig: Optional[str] = None,
prov: Optional[ProvenanceItem] = None,
parent: Optional[NodeItem] = None,
content_layer: Optional[ContentLayer] = None,
)
add_text.
Parameters:
-
label
(DocItemLabel
) βstr:
-
text
(str
) βstr:
-
orig
(Optional[str]
, default:None
) βOptional[str]: (Default value = None)
-
prov
(Optional[ProvenanceItem]
, default:None
) βOptional[ProvenanceItem]: (Default value = None)
-
parent
(Optional[NodeItem]
, default:None
) βOptional[NodeItem]: (Default value = None)
add_title
add_title(
text: str,
orig: Optional[str] = None,
prov: Optional[ProvenanceItem] = None,
parent: Optional[NodeItem] = None,
content_layer: Optional[ContentLayer] = None,
)
add_title.
Parameters:
-
text
(str
) βstr:
-
orig
(Optional[str]
, default:None
) βOptional[str]: (Default value = None)
-
prov
(Optional[ProvenanceItem]
, default:None
) βOptional[ProvenanceItem]: (Default value = None)
-
parent
(Optional[NodeItem]
, default:None
) βOptional[NodeItem]: (Default value = None)
check_version_is_compatible
check_version_is_compatible(v: str) -> str
Check if this document version is compatible with current version.
export_to_dict
export_to_dict(
mode: str = "json",
by_alias: bool = True,
exclude_none: bool = True,
) -> Dict
Export to dict.
export_to_document_tokens
export_to_document_tokens(
delim: str = "",
from_element: int = 0,
to_element: int = maxsize,
labels: set[
DocItemLabel
] = DOCUMENT_TOKENS_EXPORT_LABELS,
xsize: int = 500,
ysize: int = 500,
add_location: bool = True,
add_content: bool = True,
add_page_index: bool = True,
add_table_cell_location: bool = False,
add_table_cell_text: bool = True,
) -> str
Exports the document content to a DocumentToken format.
Operates on a slice of the document's body as defined through arguments from_element and to_element; defaulting to the whole main_text.
Parameters:
-
delim
(str
, default:''
) βstr: (Default value = "")
-
from_element
(int
, default:0
) βint: (Default value = 0)
-
to_element
(int
, default:maxsize
) βOptional[int]: (Default value = None)
-
labels
(set[DocItemLabel]
, default:DOCUMENT_TOKENS_EXPORT_LABELS
) βset[DocItemLabel]
-
xsize
(int
, default:500
) βint: (Default value = 500)
-
ysize
(int
, default:500
) βint: (Default value = 500)
-
add_location
(bool
, default:True
) βbool: (Default value = True)
-
add_content
(bool
, default:True
) βbool: (Default value = True)
-
add_page_index
(bool
, default:True
) βbool: (Default value = True)
-
add_table_cell_text
(bool
, default:True
) βbool: (Default value = True)
Returns:
-
str
βThe content of the document formatted as a DocTags string.
export_to_element_tree
export_to_element_tree() -> str
Export_to_element_tree.
export_to_html
export_to_html(
from_element: int = 0,
to_element: int = maxsize,
labels: set[DocItemLabel] = DEFAULT_EXPORT_LABELS,
image_mode: ImageRefMode = PLACEHOLDER,
formula_to_mathml: bool = True,
page_no: Optional[int] = None,
html_lang: str = "en",
html_head: str = _HTML_DEFAULT_HEAD,
included_content_layers: set[
ContentLayer
] = DEFAULT_CONTENT_LAYERS,
) -> str
Serialize to HTML.
export_to_markdown
export_to_markdown(
delim: str = "\n\n",
from_element: int = 0,
to_element: int = maxsize,
labels: set[DocItemLabel] = DEFAULT_EXPORT_LABELS,
strict_text: bool = False,
escaping_underscores: bool = True,
image_placeholder: str = "<!-- image -->",
image_mode: ImageRefMode = PLACEHOLDER,
indent: int = 4,
text_width: int = -1,
page_no: Optional[int] = None,
included_content_layers: set[
ContentLayer
] = DEFAULT_CONTENT_LAYERS,
) -> str
Serialize to Markdown.
Operates on a slice of the document's body as defined through arguments from_element and to_element; defaulting to the whole document.
Parameters:
-
delim
(str
, default:'\n\n'
) βDelimiter to use when concatenating the various Markdown parts. (Default value = "\n").
-
from_element
(int
, default:0
) βBody slicing start index (inclusive). (Default value = 0).
-
to_element
(int
, default:maxsize
) βBody slicing stop index (exclusive). (Default value = maxint).
-
labels
(set[DocItemLabel]
, default:DEFAULT_EXPORT_LABELS
) βThe set of document labels to include in the export.
-
strict_text
(bool
, default:False
) βbool: Whether to only include the text content of the document. (Default value = False).
-
escaping_underscores
(bool
, default:True
) βbool: Whether to escape underscores in the text content of the document. (Default value = True).
-
image_placeholder
(str
, default:'<!-- image -->'
) βThe placeholder to include to position images in the markdown. (Default value = "\<!-- image -->").
-
image_mode
(ImageRefMode
, default:PLACEHOLDER
) βThe mode to use for including images in the markdown. (Default value = ImageRefMode.PLACEHOLDER).
-
indent
(int
, default:4
) βThe indent in spaces of the nested lists. (Default value = 4).
Returns:
-
str
βThe exported Markdown representation.
export_to_text
export_to_text(
delim: str = "\n\n",
from_element: int = 0,
to_element: int = 1000000,
labels: set[DocItemLabel] = DEFAULT_EXPORT_LABELS,
) -> str
export_to_text.
iterate_items
iterate_items(
root: Optional[NodeItem] = None,
with_groups: bool = False,
traverse_pictures: bool = False,
page_no: Optional[int] = None,
included_content_layers: set[
ContentLayer
] = DEFAULT_CONTENT_LAYERS,
_level: int = 0,
) -> Iterable[Tuple[NodeItem, int]]
iterate_elements.
Parameters:
-
root
(Optional[NodeItem]
, default:None
) βOptional[NodeItem]: (Default value = None)
-
with_groups
(bool
, default:False
) βbool: (Default value = False)
-
traverse_pictures
(bool
, default:False
) βbool: (Default value = False)
-
page_no
(Optional[int]
, default:None
) βOptional[int]: (Default value = None)
-
_level
(int
, default:0
) β(Default value = 0)
load_from_doctags
load_from_doctags(
doctag_document: DocTagsDocument,
) -> DoclingDocument
Load Docling document from lists of DocTags and Images.
load_from_json
load_from_json(filename: Path) -> DoclingDocument
load_from_json.
Parameters:
-
filename
(Path
) βThe filename to load a saved DoclingDocument from a .json.
Returns:
-
DoclingDocument
βThe loaded DoclingDocument.
load_from_yaml
load_from_yaml(filename: Path) -> DoclingDocument
load_from_yaml.
Args: filename: The filename to load a YAML-serialized DoclingDocument from.
Returns: DoclingDocument: the loaded DoclingDocument
num_pages
num_pages()
num_pages.
print_element_tree
print_element_tree()
Print_element_tree.
save_as_doctags
save_as_doctags(
filename: Path,
delim: str = "",
from_element: int = 0,
to_element: int = maxsize,
labels: set[
DocItemLabel
] = DOCUMENT_TOKENS_EXPORT_LABELS,
xsize: int = 500,
ysize: int = 500,
add_location: bool = True,
add_content: bool = True,
add_page_index: bool = True,
add_table_cell_location: bool = False,
add_table_cell_text: bool = True,
)
Save the document content to DocTags format.
save_as_document_tokens
save_as_document_tokens(*args, **kwargs)
Save the document content to a DocumentToken format.
save_as_html
save_as_html(
filename: Path,
artifacts_dir: Optional[Path] = None,
from_element: int = 0,
to_element: int = maxsize,
labels: set[DocItemLabel] = DEFAULT_EXPORT_LABELS,
image_mode: ImageRefMode = PLACEHOLDER,
formula_to_mathml: bool = True,
page_no: Optional[int] = None,
html_lang: str = "en",
html_head: str = _HTML_DEFAULT_HEAD,
included_content_layers: set[
ContentLayer
] = DEFAULT_CONTENT_LAYERS,
)
Save to HTML.
save_as_json
save_as_json(
filename: Path,
artifacts_dir: Optional[Path] = None,
image_mode: ImageRefMode = EMBEDDED,
indent: int = 2,
)
Save as json.
save_as_markdown
save_as_markdown(
filename: Path,
artifacts_dir: Optional[Path] = None,
delim: str = "\n\n",
from_element: int = 0,
to_element: int = maxsize,
labels: set[DocItemLabel] = DEFAULT_EXPORT_LABELS,
strict_text: bool = False,
escaping_underscores: bool = True,
image_placeholder: str = "<!-- image -->",
image_mode: ImageRefMode = PLACEHOLDER,
indent: int = 4,
text_width: int = -1,
page_no: Optional[int] = None,
included_content_layers: set[
ContentLayer
] = DEFAULT_CONTENT_LAYERS,
)
Save to markdown.
save_as_yaml
save_as_yaml(
filename: Path,
artifacts_dir: Optional[Path] = None,
image_mode: ImageRefMode = EMBEDDED,
default_flow_style: bool = False,
)
Save as yaml.
transform_to_content_layer
transform_to_content_layer(data: dict) -> dict
transform_to_content_layer.
validate_tree
validate_tree(root) -> bool
validate_tree.
DocumentOrigin
Bases: BaseModel
FileSource.
Methods:
-
parse_hex_string
βparse_hex_string.
-
validate_mimetype
βvalidate_mimetype.
Attributes:
-
binary_hash
(Uint64
) β -
filename
(str
) β -
mimetype
(str
) β -
uri
(Optional[AnyUrl]
) β
binary_hash
binary_hash: Uint64
filename
filename: str
mimetype
mimetype: str
uri
uri: Optional[AnyUrl] = None
parse_hex_string
parse_hex_string(value)
parse_hex_string.
validate_mimetype
validate_mimetype(v)
validate_mimetype.
DocItem
Bases: NodeItem
DocItem.
Methods:
-
get_image
βReturns the image of this DocItem.
-
get_location_tokens
βGet the location string for the BaseCell.
-
get_ref
βget_ref.
Attributes:
-
children
(List[RefItem]
) β -
content_layer
(ContentLayer
) β -
label
(DocItemLabel
) β -
model_config
β -
parent
(Optional[RefItem]
) β -
prov
(List[ProvenanceItem]
) β -
self_ref
(str
) β
content_layer
content_layer: ContentLayer = BODY
model_config
model_config = ConfigDict(extra='forbid')
self_ref
self_ref: str = Field(pattern=_JSON_POINTER_REGEX)
get_image
get_image(doc: DoclingDocument) -> Optional[Image]
Returns the image of this DocItem.
The function returns None if this DocItem has no valid provenance or if a valid image of the page containing this DocItem is not available in doc.
get_location_tokens
get_location_tokens(
doc: DoclingDocument,
new_line: str,
xsize: int = 500,
ysize: int = 500,
) -> str
Get the location string for the BaseCell.
get_ref
get_ref()
get_ref.
DocItemLabel
Bases: str
, Enum
DocItemLabel.
Methods:
-
get_color
βReturn the RGB color associated with a given label.
Attributes:
-
CAPTION
β -
CHECKBOX_SELECTED
β -
CHECKBOX_UNSELECTED
β -
CODE
β -
DOCUMENT_INDEX
β -
FOOTNOTE
β -
FORM
β -
FORMULA
β -
KEY_VALUE_REGION
β -
LIST_ITEM
β -
PAGE_FOOTER
β -
PAGE_HEADER
β -
PARAGRAPH
β -
PICTURE
β -
REFERENCE
β -
SECTION_HEADER
β -
TABLE
β -
TEXT
β -
TITLE
β
CAPTION
CAPTION = 'caption'
CHECKBOX_SELECTED
CHECKBOX_SELECTED = 'checkbox_selected'
CHECKBOX_UNSELECTED
CHECKBOX_UNSELECTED = 'checkbox_unselected'
CODE
CODE = 'code'
DOCUMENT_INDEX
DOCUMENT_INDEX = 'document_index'
FOOTNOTE
FOOTNOTE = 'footnote'
FORM
FORM = 'form'
FORMULA
FORMULA = 'formula'
KEY_VALUE_REGION
KEY_VALUE_REGION = 'key_value_region'
LIST_ITEM
LIST_ITEM = 'list_item'
PAGE_FOOTER
PAGE_FOOTER = 'page_footer'
PAGE_HEADER
PAGE_HEADER = 'page_header'
PARAGRAPH
PARAGRAPH = 'paragraph'
PICTURE
PICTURE = 'picture'
REFERENCE
REFERENCE = 'reference'
SECTION_HEADER
SECTION_HEADER = 'section_header'
TABLE
TABLE = 'table'
TEXT
TEXT = 'text'
TITLE
TITLE = 'title'
get_color
get_color(label: DocItemLabel) -> Tuple[int, int, int]
Return the RGB color associated with a given label.
ProvenanceItem
Bases: BaseModel
ProvenanceItem.
Attributes:
-
bbox
(BoundingBox
) β -
charspan
(Tuple[int, int]
) β -
page_no
(int
) β
GroupItem
Bases: NodeItem
GroupItem.
Methods:
-
get_ref
βget_ref.
Attributes:
-
children
(List[RefItem]
) β -
content_layer
(ContentLayer
) β -
label
(GroupLabel
) β -
model_config
β -
name
(str
) β -
parent
(Optional[RefItem]
) β -
self_ref
(str
) β
content_layer
content_layer: ContentLayer = BODY
model_config
model_config = ConfigDict(extra='forbid')
name
name: str = 'group'
self_ref
self_ref: str = Field(pattern=_JSON_POINTER_REGEX)
get_ref
get_ref()
get_ref.
GroupLabel
Bases: str
, Enum
GroupLabel.
Attributes:
-
CHAPTER
β -
COMMENT_SECTION
β -
FORM_AREA
β -
INLINE
β -
KEY_VALUE_AREA
β -
LIST
β -
ORDERED_LIST
β -
SECTION
β -
SHEET
β -
SLIDE
β -
UNSPECIFIED
β
CHAPTER
CHAPTER = 'chapter'
COMMENT_SECTION
COMMENT_SECTION = 'comment_section'
FORM_AREA
FORM_AREA = 'form_area'
INLINE
INLINE = 'inline'
KEY_VALUE_AREA
KEY_VALUE_AREA = 'key_value_area'
LIST
LIST = 'list'
ORDERED_LIST
ORDERED_LIST = 'ordered_list'
SECTION
SECTION = 'section'
SHEET
SHEET = 'sheet'
SLIDE
SLIDE = 'slide'
UNSPECIFIED
UNSPECIFIED = 'unspecified'
NodeItem
Bases: BaseModel
NodeItem.
Methods:
-
get_ref
βget_ref.
Attributes:
-
children
(List[RefItem]
) β -
content_layer
(ContentLayer
) β -
model_config
β -
parent
(Optional[RefItem]
) β -
self_ref
(str
) β
PageItem
FloatingItem
Bases: DocItem
FloatingItem.
Methods:
-
caption_text
βComputes the caption as a single text.
-
get_image
βReturns the image corresponding to this FloatingItem.
-
get_location_tokens
βGet the location string for the BaseCell.
-
get_ref
βget_ref.
Attributes:
-
captions
(List[RefItem]
) β -
children
(List[RefItem]
) β -
content_layer
(ContentLayer
) β -
footnotes
(List[RefItem]
) β -
image
(Optional[ImageRef]
) β -
label
(DocItemLabel
) β -
model_config
β -
parent
(Optional[RefItem]
) β -
prov
(List[ProvenanceItem]
) β -
references
(List[RefItem]
) β -
self_ref
(str
) β
content_layer
content_layer: ContentLayer = BODY
model_config
model_config = ConfigDict(extra='forbid')
self_ref
self_ref: str = Field(pattern=_JSON_POINTER_REGEX)
get_image
get_image(doc: DoclingDocument) -> Optional[Image]
Returns the image corresponding to this FloatingItem.
This function returns the PIL image from self.image if one is available. Otherwise, it uses DocItem.get_image to get an image of this FloatingItem.
In particular, when self.image is None, the function returns None if this FloatingItem has no valid provenance or the doc does not contain a valid image for the required page.
get_location_tokens
get_location_tokens(
doc: DoclingDocument,
new_line: str,
xsize: int = 500,
ysize: int = 500,
) -> str
Get the location string for the BaseCell.
get_ref
get_ref()
get_ref.
TextItem
Bases: DocItem
TextItem.
Methods:
-
export_to_document_tokens
βExport text element to document tokens format.
-
get_image
βReturns the image of this DocItem.
-
get_location_tokens
βGet the location string for the BaseCell.
-
get_ref
βget_ref.
Attributes:
-
children
(List[RefItem]
) β -
content_layer
(ContentLayer
) β -
label
(Literal[CAPTION, CHECKBOX_SELECTED, CHECKBOX_UNSELECTED, FOOTNOTE, FORMULA, PAGE_FOOTER, PAGE_HEADER, PARAGRAPH, REFERENCE, TEXT, TITLE]
) β -
model_config
β -
orig
(str
) β -
parent
(Optional[RefItem]
) β -
prov
(List[ProvenanceItem]
) β -
self_ref
(str
) β -
text
(str
) β
content_layer
content_layer: ContentLayer = BODY
label
label: Literal[
CAPTION,
CHECKBOX_SELECTED,
CHECKBOX_UNSELECTED,
FOOTNOTE,
FORMULA,
PAGE_FOOTER,
PAGE_HEADER,
PARAGRAPH,
REFERENCE,
TEXT,
TITLE,
]
model_config
model_config = ConfigDict(extra='forbid')
orig
orig: str
self_ref
self_ref: str = Field(pattern=_JSON_POINTER_REGEX)
text
text: str
export_to_document_tokens
export_to_document_tokens(
doc: DoclingDocument,
new_line: str = "",
xsize: int = 500,
ysize: int = 500,
add_location: bool = True,
add_content: bool = True,
)
Export text element to document tokens format.
Parameters:
-
doc
(DoclingDocument
) β"DoclingDocument":
-
new_line
(str
, default:''
) βstr (Default value = "")
-
xsize
(int
, default:500
) βint: (Default value = 500)
-
ysize
(int
, default:500
) βint: (Default value = 500)
-
add_location
(bool
, default:True
) βbool: (Default value = True)
-
add_content
(bool
, default:True
) βbool: (Default value = True)
get_image
get_image(doc: DoclingDocument) -> Optional[Image]
Returns the image of this DocItem.
The function returns None if this DocItem has no valid provenance or if a valid image of the page containing this DocItem is not available in doc.
get_location_tokens
get_location_tokens(
doc: DoclingDocument,
new_line: str,
xsize: int = 500,
ysize: int = 500,
) -> str
Get the location string for the BaseCell.
get_ref
get_ref()
get_ref.
TableItem
Bases: FloatingItem
TableItem.
Methods:
-
caption_text
βComputes the caption as a single text.
-
export_to_dataframe
βExport the table as a Pandas DataFrame.
-
export_to_document_tokens
βExport table to document tokens format.
-
export_to_html
βExport the table as html.
-
export_to_markdown
βExport the table as markdown.
-
export_to_otsl
βExport the table as OTSL.
-
get_image
βReturns the image corresponding to this FloatingItem.
-
get_location_tokens
βGet the location string for the BaseCell.
-
get_ref
βget_ref.
Attributes:
-
captions
(List[RefItem]
) β -
children
(List[RefItem]
) β -
content_layer
(ContentLayer
) β -
data
(TableData
) β -
footnotes
(List[RefItem]
) β -
image
(Optional[ImageRef]
) β -
label
(Literal[DOCUMENT_INDEX, TABLE]
) β -
model_config
β -
parent
(Optional[RefItem]
) β -
prov
(List[ProvenanceItem]
) β -
references
(List[RefItem]
) β -
self_ref
(str
) β
content_layer
content_layer: ContentLayer = BODY
model_config
model_config = ConfigDict(extra='forbid')
self_ref
self_ref: str = Field(pattern=_JSON_POINTER_REGEX)
export_to_dataframe
export_to_dataframe() -> DataFrame
Export the table as a Pandas DataFrame.
export_to_document_tokens
export_to_document_tokens(
doc: DoclingDocument,
new_line: str = "",
xsize: int = 500,
ysize: int = 500,
add_location: bool = True,
add_cell_location: bool = True,
add_cell_text: bool = True,
add_caption: bool = True,
)
Export table to document tokens format.
Parameters:
-
doc
(DoclingDocument
) β"DoclingDocument":
-
new_line
(str
, default:''
) βstr (Default value = "")
-
xsize
(int
, default:500
) βint: (Default value = 500)
-
ysize
(int
, default:500
) βint: (Default value = 500)
-
add_location
(bool
, default:True
) βbool: (Default value = True)
-
add_cell_location
(bool
, default:True
) βbool: (Default value = True)
-
add_cell_text
(bool
, default:True
) βbool: (Default value = True)
-
add_caption
(bool
, default:True
) βbool: (Default value = True)
export_to_html
export_to_html(
doc: Optional[DoclingDocument] = None,
add_caption: bool = True,
) -> str
Export the table as html.
export_to_markdown
export_to_markdown() -> str
Export the table as markdown.
export_to_otsl
export_to_otsl(
doc: DoclingDocument,
add_cell_location: bool = True,
add_cell_text: bool = True,
xsize: int = 500,
ysize: int = 500,
) -> str
Export the table as OTSL.
get_image
get_image(doc: DoclingDocument) -> Optional[Image]
Returns the image corresponding to this FloatingItem.
This function returns the PIL image from self.image if one is available. Otherwise, it uses DocItem.get_image to get an image of this FloatingItem.
In particular, when self.image is None, the function returns None if this FloatingItem has no valid provenance or the doc does not contain a valid image for the required page.
get_location_tokens
get_location_tokens(
doc: DoclingDocument,
new_line: str,
xsize: int = 500,
ysize: int = 500,
) -> str
Get the location string for the BaseCell.
get_ref
get_ref()
get_ref.
TableCell
Bases: BaseModel
TableCell.
Methods:
-
from_dict_format
βfrom_dict_format.
Attributes:
-
bbox
(Optional[BoundingBox]
) β -
col_span
(int
) β -
column_header
(bool
) β -
end_col_offset_idx
(int
) β -
end_row_offset_idx
(int
) β -
row_header
(bool
) β -
row_section
(bool
) β -
row_span
(int
) β -
start_col_offset_idx
(int
) β -
start_row_offset_idx
(int
) β -
text
(str
) β
col_span
col_span: int = 1
column_header
column_header: bool = False
end_col_offset_idx
end_col_offset_idx: int
end_row_offset_idx
end_row_offset_idx: int
row_header
row_header: bool = False
row_section
row_section: bool = False
row_span
row_span: int = 1
start_col_offset_idx
start_col_offset_idx: int
start_row_offset_idx
start_row_offset_idx: int
text
text: str
from_dict_format
from_dict_format(data: Any) -> Any
from_dict_format.
TableData
TableCellLabel
Bases: str
, Enum
TableCellLabel.
Attributes:
-
BODY
β -
COLUMN_HEADER
β -
ROW_HEADER
β -
ROW_SECTION
β
BODY
BODY = 'body'
COLUMN_HEADER
COLUMN_HEADER = 'col_header'
ROW_HEADER
ROW_HEADER = 'row_header'
ROW_SECTION
ROW_SECTION = 'row_section'
KeyValueItem
Bases: FloatingItem
KeyValueItem.
Methods:
-
caption_text
βComputes the caption as a single text.
-
get_image
βReturns the image corresponding to this FloatingItem.
-
get_location_tokens
βGet the location string for the BaseCell.
-
get_ref
βget_ref.
Attributes:
-
captions
(List[RefItem]
) β -
children
(List[RefItem]
) β -
content_layer
(ContentLayer
) β -
footnotes
(List[RefItem]
) β -
graph
(GraphData
) β -
image
(Optional[ImageRef]
) β -
label
(Literal[KEY_VALUE_REGION]
) β -
model_config
β -
parent
(Optional[RefItem]
) β -
prov
(List[ProvenanceItem]
) β -
references
(List[RefItem]
) β -
self_ref
(str
) β
content_layer
content_layer: ContentLayer = BODY
graph
graph: GraphData
model_config
model_config = ConfigDict(extra='forbid')
self_ref
self_ref: str = Field(pattern=_JSON_POINTER_REGEX)
get_image
get_image(doc: DoclingDocument) -> Optional[Image]
Returns the image corresponding to this FloatingItem.
This function returns the PIL image from self.image if one is available. Otherwise, it uses DocItem.get_image to get an image of this FloatingItem.
In particular, when self.image is None, the function returns None if this FloatingItem has no valid provenance or the doc does not contain a valid image for the required page.
get_location_tokens
get_location_tokens(
doc: DoclingDocument,
new_line: str,
xsize: int = 500,
ysize: int = 500,
) -> str
Get the location string for the BaseCell.
get_ref
get_ref()
get_ref.
SectionHeaderItem
Bases: TextItem
SectionItem.
Methods:
-
export_to_document_tokens
βExport text element to document tokens format.
-
get_image
βReturns the image of this DocItem.
-
get_location_tokens
βGet the location string for the BaseCell.
-
get_ref
βget_ref.
Attributes:
-
children
(List[RefItem]
) β -
content_layer
(ContentLayer
) β -
label
(Literal[SECTION_HEADER]
) β -
level
(LevelNumber
) β -
model_config
β -
orig
(str
) β -
parent
(Optional[RefItem]
) β -
prov
(List[ProvenanceItem]
) β -
self_ref
(str
) β -
text
(str
) β
content_layer
content_layer: ContentLayer = BODY
level
level: LevelNumber = 1
model_config
model_config = ConfigDict(extra='forbid')
orig
orig: str
self_ref
self_ref: str = Field(pattern=_JSON_POINTER_REGEX)
text
text: str
export_to_document_tokens
export_to_document_tokens(
doc: DoclingDocument,
new_line: str = "",
xsize: int = 500,
ysize: int = 500,
add_location: bool = True,
add_content: bool = True,
)
Export text element to document tokens format.
Parameters:
-
doc
(DoclingDocument
) β"DoclingDocument":
-
new_line
(str
, default:''
) βstr (Default value = "")
-
xsize
(int
, default:500
) βint: (Default value = 500)
-
ysize
(int
, default:500
) βint: (Default value = 500)
-
add_location
(bool
, default:True
) βbool: (Default value = True)
-
add_content
(bool
, default:True
) βbool: (Default value = True)
get_image
get_image(doc: DoclingDocument) -> Optional[Image]
Returns the image of this DocItem.
The function returns None if this DocItem has no valid provenance or if a valid image of the page containing this DocItem is not available in doc.
get_location_tokens
get_location_tokens(
doc: DoclingDocument,
new_line: str,
xsize: int = 500,
ysize: int = 500,
) -> str
Get the location string for the BaseCell.
get_ref
get_ref()
get_ref.
PictureItem
Bases: FloatingItem
PictureItem.
Methods:
-
caption_text
βComputes the caption as a single text.
-
export_to_document_tokens
βExport picture to document tokens format.
-
export_to_html
βExport picture to HTML format.
-
export_to_markdown
βExport picture to Markdown format.
-
get_image
βReturns the image corresponding to this FloatingItem.
-
get_location_tokens
βGet the location string for the BaseCell.
-
get_ref
βget_ref.
Attributes:
-
annotations
(List[PictureDataType]
) β -
captions
(List[RefItem]
) β -
children
(List[RefItem]
) β -
content_layer
(ContentLayer
) β -
footnotes
(List[RefItem]
) β -
image
(Optional[ImageRef]
) β -
label
(Literal[PICTURE]
) β -
model_config
β -
parent
(Optional[RefItem]
) β -
prov
(List[ProvenanceItem]
) β -
references
(List[RefItem]
) β -
self_ref
(str
) β
annotations
annotations: List[PictureDataType] = []
content_layer
content_layer: ContentLayer = BODY
model_config
model_config = ConfigDict(extra='forbid')
self_ref
self_ref: str = Field(pattern=_JSON_POINTER_REGEX)
export_to_document_tokens
export_to_document_tokens(
doc: DoclingDocument,
new_line: str = "",
xsize: int = 500,
ysize: int = 500,
add_location: bool = True,
add_caption: bool = True,
add_content: bool = True,
)
Export picture to document tokens format.
Parameters:
-
doc
(DoclingDocument
) β"DoclingDocument":
-
new_line
(str
, default:''
) βstr (Default value = "")
-
xsize
(int
, default:500
) βint: (Default value = 500)
-
ysize
(int
, default:500
) βint: (Default value = 500)
-
add_location
(bool
, default:True
) βbool: (Default value = True)
-
add_caption
(bool
, default:True
) βbool: (Default value = True)
-
add_content
(bool
, default:True
) βbool: (Default value = True)
export_to_html
export_to_html(
doc: DoclingDocument,
add_caption: bool = True,
image_mode: ImageRefMode = PLACEHOLDER,
) -> str
Export picture to HTML format.
export_to_markdown
export_to_markdown(
doc: DoclingDocument,
add_caption: bool = True,
image_mode: ImageRefMode = EMBEDDED,
image_placeholder: str = "<!-- image -->",
) -> str
Export picture to Markdown format.
get_image
get_image(doc: DoclingDocument) -> Optional[Image]
Returns the image corresponding to this FloatingItem.
This function returns the PIL image from self.image if one is available. Otherwise, it uses DocItem.get_image to get an image of this FloatingItem.
In particular, when self.image is None, the function returns None if this FloatingItem has no valid provenance or the doc does not contain a valid image for the required page.
get_location_tokens
get_location_tokens(
doc: DoclingDocument,
new_line: str,
xsize: int = 500,
ysize: int = 500,
) -> str
Get the location string for the BaseCell.
get_ref
get_ref()
get_ref.
ImageRef
Bases: BaseModel
ImageRef.
Methods:
-
from_pil
βConstruct ImageRef from a PIL Image.
-
validate_mimetype
βvalidate_mimetype.
Attributes:
-
dpi
(int
) β -
mimetype
(str
) β -
pil_image
(Optional[Image]
) βReturn the PIL Image.
-
size
(Size
) β -
uri
(Union[AnyUrl, Path]
) β
dpi
dpi: int
mimetype
mimetype: str
pil_image
pil_image: Optional[Image]
Return the PIL Image.
uri
uri: Union[AnyUrl, Path] = Field(union_mode="left_to_right")
from_pil
from_pil(image: Image, dpi: int) -> Self
Construct ImageRef from a PIL Image.
validate_mimetype
validate_mimetype(v)
validate_mimetype.
PictureClassificationClass
Bases: BaseModel
PictureClassificationData.
Attributes:
-
class_name
(str
) β -
confidence
(float
) β
class_name
class_name: str
confidence
confidence: float
PictureClassificationData
Bases: BasePictureData
PictureClassificationData.
Attributes:
-
kind
(Literal['classification']
) β -
predicted_classes
(List[PictureClassificationClass]
) β -
provenance
(str
) β
kind
kind: Literal['classification'] = 'classification'
provenance
provenance: str
RefItem
Bases: BaseModel
RefItem.
Methods:
Attributes:
-
cref
(str
) β -
model_config
β
cref
cref: str = Field(alias="$ref", pattern=_JSON_POINTER_REGEX)
model_config
model_config = ConfigDict(populate_by_name=True)
get_ref
get_ref()
get_ref.
BoundingBox
Bases: BaseModel
BoundingBox.
Methods:
-
area
βarea.
-
as_tuple
βas_tuple.
-
enclosing_bbox
βCreate a bounding box that covers all of the given boxes.
-
expand_by_scale
βexpand_to_size.
-
from_tuple
βfrom_tuple.
-
intersection_area_with
βCalculate the intersection area with another bounding box.
-
intersection_over_self
βintersection_over_self.
-
intersection_over_union
βintersection_over_union.
-
is_above
βis_above.
-
is_horizontally_connected
βis_horizontally_connected.
-
is_left_of
βis_left_of.
-
is_strictly_above
βis_strictly_above.
-
is_strictly_left_of
βis_strictly_left_of.
-
normalized
βnormalized.
-
overlaps
βoverlaps.
-
overlaps_horizontally
βCheck if two bounding boxes overlap horizontally.
-
overlaps_vertically
βCheck if two bounding boxes overlap vertically.
-
overlaps_vertically_with_iou
βoverlaps_y_with_iou.
-
resize_by_scale
βresize_by_scale.
-
scale_to_size
βscale_to_size.
-
scaled
βscaled.
-
to_bottom_left_origin
βto_bottom_left_origin.
-
to_top_left_origin
βto_top_left_origin.
Attributes:
-
b
(float
) β -
coord_origin
(CoordOrigin
) β -
height
βheight.
-
l
(float
) β -
r
(float
) β -
t
(float
) β -
width
βwidth.
b
b: float
height
height
height.
l
l: float
r
r: float
t
t: float
width
width
width.
area
area() -> float
area.
as_tuple
as_tuple() -> Tuple[float, float, float, float]
as_tuple.
enclosing_bbox
enclosing_bbox(boxes: List[BoundingBox]) -> BoundingBox
Create a bounding box that covers all of the given boxes.
from_tuple
from_tuple(coord: Tuple[float, ...], origin: CoordOrigin)
from_tuple.
Parameters:
-
coord
(Tuple[float, ...]
) βTuple[float:
-
...]
β -
origin
(CoordOrigin
) βCoordOrigin:
intersection_area_with
intersection_area_with(other: BoundingBox) -> float
Calculate the intersection area with another bounding box.
intersection_over_self
intersection_over_self(
other: BoundingBox, eps: float = 1e-06
) -> float
intersection_over_self.
intersection_over_union
intersection_over_union(
other: BoundingBox, eps: float = 1e-06
) -> float
intersection_over_union.
is_horizontally_connected
is_horizontally_connected(
elem_i: BoundingBox, elem_j: BoundingBox
) -> bool
is_horizontally_connected.
is_strictly_above
is_strictly_above(
other: BoundingBox, eps: float = 0.001
) -> bool
is_strictly_above.
is_strictly_left_of
is_strictly_left_of(
other: BoundingBox, eps: float = 0.001
) -> bool
is_strictly_left_of.
overlaps_horizontally
overlaps_horizontally(other: BoundingBox) -> bool
Check if two bounding boxes overlap horizontally.
overlaps_vertically
overlaps_vertically(other: BoundingBox) -> bool
Check if two bounding boxes overlap vertically.
overlaps_vertically_with_iou
overlaps_vertically_with_iou(
other: BoundingBox, iou: float
) -> bool
overlaps_y_with_iou.
resize_by_scale
resize_by_scale(x_scale: float, y_scale: float)
resize_by_scale.
scaled
scaled(scale: float)
scaled.
to_bottom_left_origin
to_bottom_left_origin(page_height: float) -> BoundingBox
to_bottom_left_origin.
Parameters:
-
page_height
(float
) β
to_top_left_origin
to_top_left_origin(page_height: float) -> BoundingBox
to_top_left_origin.
Parameters:
-
page_height
(float
) β
CoordOrigin
Bases: str
, Enum
CoordOrigin.
Attributes:
-
BOTTOMLEFT
β -
TOPLEFT
β
BOTTOMLEFT
BOTTOMLEFT = 'BOTTOMLEFT'
TOPLEFT
TOPLEFT = 'TOPLEFT'
ImageRefMode
Bases: str
, Enum
ImageRefMode.
Attributes:
-
EMBEDDED
β -
PLACEHOLDER
β -
REFERENCED
β
EMBEDDED
EMBEDDED = 'embedded'
PLACEHOLDER
PLACEHOLDER = 'placeholder'
REFERENCED
REFERENCED = 'referenced'