Docling λ¬Έμ
DoclingDocument νμ μ μλ μμ±λ API μ°Έμ‘°μ λλ€.
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_formulaβadd_formula.
-
add_groupβadd_group.
-
add_headingβadd_heading.
-
add_inline_groupβadd_inline_group.
-
add_key_valuesβadd_key_values.
-
add_list_itemβadd_list_item.
-
add_ordered_listβadd_ordered_list.
-
add_pageβadd_page.
-
add_pictureβadd_picture.
-
add_tableβadd_table.
-
add_textβadd_text.
-
add_titleβadd_title.
-
add_unordered_listβadd_unordered_list.
-
append_child_itemβAdds an item.
-
check_version_is_compatibleβCheck if this document version is compatible with current version.
-
delete_itemsβDeletes an item, given its instance or ref, and any children it has.
-
export_to_dictβExport to dict.
-
export_to_doctagsβExports the document content to a DocumentToken format.
-
export_to_document_tokensβExport to DocTags 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.
-
get_visualizationβGet visualization of the document as images by page.
-
insert_item_after_siblingβInserts an item, given its node_item instance, after other as a sibling.
-
insert_item_before_siblingβInserts an item, given its node_item instance, before other as a sibling.
-
iterate_itemsβIterate elements with level.
-
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.
-
replace_itemβReplace item with new item.
-
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[Union[OrderedList, UnorderedList, InlineGroup, 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[TitleItem, SectionHeaderItem, ListItem, CodeItem, FormulaItem, TextItem]]) β -
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'
texts
texts: List[Union[TitleItem, SectionHeaderItem, ListItem, CodeItem, FormulaItem, TextItem]] = []
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, formatting: Optional[Formatting] = None, hyperlink: Optional[Union[AnyUrl, Path]] = 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_formula
add_formula(text: str, orig: Optional[str] = None, prov: Optional[ProvenanceItem] = None, parent: Optional[NodeItem] = None, content_layer: Optional[ContentLayer] = None, formatting: Optional[Formatting] = None, hyperlink: Optional[Union[AnyUrl, Path]] = None)
add_formula.
Parameters:
-
text(str) βstr:
-
orig(Optional[str], default:None) βOptional[str]: (Default value = None)
-
levelβ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_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, formatting: Optional[Formatting] = None, hyperlink: Optional[Union[AnyUrl, Path]] = 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_inline_group
add_inline_group(name: Optional[str] = None, parent: Optional[NodeItem] = None, content_layer: Optional[ContentLayer] = None) -> GroupItem
add_inline_group.
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, formatting: Optional[Formatting] = None, hyperlink: Optional[Union[AnyUrl, Path]] = 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_ordered_list
add_ordered_list(name: Optional[str] = None, parent: Optional[NodeItem] = None, content_layer: Optional[ContentLayer] = None) -> GroupItem
add_ordered_list.
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, formatting: Optional[Formatting] = None, hyperlink: Optional[Union[AnyUrl, Path]] = 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, formatting: Optional[Formatting] = None, hyperlink: Optional[Union[AnyUrl, Path]] = None)
add_title.
Parameters:
-
text(str) βstr:
-
orig(Optional[str], default:None) βOptional[str]: (Default value = None)
-
levelβ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_unordered_list
add_unordered_list(name: Optional[str] = None, parent: Optional[NodeItem] = None, content_layer: Optional[ContentLayer] = None) -> GroupItem
add_unordered_list.
append_child_item
Adds an item.
check_version_is_compatible
check_version_is_compatible(v: str) -> str
Check if this document version is compatible with current version.
delete_items
delete_items(*, node_items: List[NodeItem]) -> None
Deletes an item, given its instance or ref, and any children it has.
export_to_dict
export_to_dict(mode: str = 'json', by_alias: bool = True, exclude_none: bool = True) -> Dict[str, Any]
Export to dict.
export_to_doctags
export_to_doctags(delim: str = '', from_element: int = 0, to_element: int = maxsize, labels: Optional[set[DocItemLabel]] = None, 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, minified: bool = False) -> 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 = "") Deprecated
-
from_element(int, default:0) βint: (Default value = 0)
-
to_element(int, default:maxsize) βOptional[int]: (Default value = None)
-
labels(Optional[set[DocItemLabel]], default:None) β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)
-
minified(bool, default:False) βbool: (Default value = False)
Returns:
-
strβThe content of the document formatted as a DocTags string.
export_to_document_tokens
export_to_document_tokens(*args, **kwargs)
Export to DocTags format.
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: Optional[set[DocItemLabel]] = None, enable_chart_tables: bool = True, image_mode: ImageRefMode = PLACEHOLDER, formula_to_mathml: bool = True, page_no: Optional[int] = None, html_lang: str = 'en', html_head: str = 'null', included_content_layers: Optional[set[ContentLayer]] = None, split_page_view: bool = False, include_annotations: bool = True) -> str
Serialize to HTML.
export_to_markdown
export_to_markdown(delim: str = '\n\n', from_element: int = 0, to_element: int = maxsize, labels: Optional[set[DocItemLabel]] = None, strict_text: bool = False, escape_underscores: bool = True, image_placeholder: str = '<!-- image -->', enable_chart_tables: bool = True, image_mode: ImageRefMode = PLACEHOLDER, indent: int = 4, text_width: int = -1, page_no: Optional[int] = None, included_content_layers: Optional[set[ContentLayer]] = None, page_break_placeholder: Optional[str] = None, include_annotations: bool = True, mark_annotations: bool = False) -> 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') βDeprecated.
-
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(Optional[set[DocItemLabel]], default:None) βThe set of document labels to include in the export. None falls back to the system-defined default.
-
strict_text(bool, default:False) βDeprecated.
-
escape_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).
-
included_content_layers(Optional[set[ContentLayer]], default:None) βThe set of layels to include in the export. None falls back to the system-defined default.
-
page_break_placeholder(Optional[str], default:None) βThe placeholder to include for marking page breaks. None means no page break placeholder will be used.
-
include_annotations(bool, default:True) βbool: Whether to include annotations in the export. (Default value = True).
-
mark_annotations(bool, default:False) βbool: Whether to mark annotations in the export; only relevant if include_annotations is True. (Default value = False).
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: Optional[set[DocItemLabel]] = None) -> str
export_to_text.
get_visualization
get_visualization(show_label: bool = True) -> dict[Optional[int], Image]
Get visualization of the document as images by page.
insert_item_after_sibling
Inserts an item, given its node_item instance, after other as a sibling.
insert_item_before_sibling
Inserts an item, given its node_item instance, before other as a sibling.
iterate_items
iterate_items(root: Optional[NodeItem] = None, with_groups: bool = False, traverse_pictures: bool = False, page_no: Optional[int] = None, included_content_layers: Optional[set[ContentLayer]] = None, _level: int = 0) -> Iterable[Tuple[NodeItem, int]]
Iterate elements with level.
load_from_doctags
load_from_doctags(doctag_document: DocTagsDocument, document_name: str = 'Document') -> DoclingDocument
Load Docling document from lists of DocTags and Images.
load_from_json
load_from_json(filename: Union[str, Path]) -> DoclingDocument
load_from_json.
Parameters:
-
filename(Union[str, Path]) βThe filename to load a saved DoclingDocument from a .json.
Returns:
-
DoclingDocumentβThe loaded DoclingDocument.
load_from_yaml
load_from_yaml(filename: Union[str, 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.
replace_item
Replace item with new item.
save_as_doctags
save_as_doctags(filename: Union[str, Path], delim: str = '', from_element: int = 0, to_element: int = maxsize, labels: Optional[set[DocItemLabel]] = None, 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, minified: bool = False)
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: Union[str, Path], artifacts_dir: Optional[Path] = None, from_element: int = 0, to_element: int = maxsize, labels: Optional[set[DocItemLabel]] = None, image_mode: ImageRefMode = PLACEHOLDER, formula_to_mathml: bool = True, page_no: Optional[int] = None, html_lang: str = 'en', html_head: str = 'null', included_content_layers: Optional[set[ContentLayer]] = None, split_page_view: bool = False, include_annotations: bool = True)
Save to HTML.
save_as_json
save_as_json(filename: Union[str, Path], artifacts_dir: Optional[Path] = None, image_mode: ImageRefMode = EMBEDDED, indent: int = 2)
Save as json.
save_as_markdown
save_as_markdown(filename: Union[str, Path], artifacts_dir: Optional[Path] = None, delim: str = '\n\n', from_element: int = 0, to_element: int = maxsize, labels: Optional[set[DocItemLabel]] = None, 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: Optional[set[ContentLayer]] = None, page_break_placeholder: Optional[str] = None, include_annotations: bool = True)
Save to markdown.
save_as_yaml
save_as_yaml(filename: Union[str, 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, prov_index: int = 0) -> 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.
DocItemLabel
Bases: str, Enum
DocItemLabel.
Methods:
-
get_colorβReturn the RGB color associated with a given label.
Attributes:
-
CAPTIONβ -
CHARTβ -
CHECKBOX_SELECTEDβ -
CHECKBOX_UNSELECTEDβ -
CODEβ -
DOCUMENT_INDEXβ -
FOOTNOTEβ -
FORMβ -
FORMULAβ -
GRADING_SCALEβ -
KEY_VALUE_REGIONβ -
LIST_ITEMβ -
PAGE_FOOTERβ -
PAGE_HEADERβ -
PARAGRAPHβ -
PICTUREβ -
REFERENCEβ -
SECTION_HEADERβ -
TABLEβ -
TEXTβ -
TITLEβ
CAPTION
CAPTION = 'caption'
CHART
CHART = 'chart'
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'
GRADING_SCALE
GRADING_SCALE = 'grading_scale'
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)
GroupLabel
Bases: str, Enum
GroupLabel.
Attributes:
-
CHAPTERβ -
COMMENT_SECTIONβ -
FORM_AREAβ -
INLINEβ -
KEY_VALUE_AREAβ -
LISTβ -
ORDERED_LISTβ -
PICTURE_AREAβ -
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'
PICTURE_AREA
PICTURE_AREA = 'picture_area'
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, prov_index: int = 0) -> 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.
TextItem
Bases: DocItem
TextItem.
Methods:
-
export_to_doctagsβExport text element to document tokens format.
-
export_to_document_tokensβExport to DocTags 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) β -
formatting(Optional[Formatting]) β -
hyperlink(Optional[Union[AnyUrl, Path]]) β -
label(Literal[CAPTION, CHECKBOX_SELECTED, CHECKBOX_UNSELECTED, FOOTNOTE, PAGE_FOOTER, PAGE_HEADER, PARAGRAPH, REFERENCE, TEXT]) β -
model_configβ -
orig(str) β -
parent(Optional[RefItem]) β -
prov(List[ProvenanceItem]) β -
self_ref(str) β -
text(str) β
content_layer
content_layer: ContentLayer = BODY
formatting
formatting: Optional[Formatting] = None
hyperlink
hyperlink: Optional[Union[AnyUrl, Path]] = Field(union_mode='left_to_right', default=None)
label
label: Literal[CAPTION, CHECKBOX_SELECTED, CHECKBOX_UNSELECTED, FOOTNOTE, PAGE_FOOTER, PAGE_HEADER, PARAGRAPH, REFERENCE, TEXT]
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_doctags
export_to_doctags(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 = "") Deprecated
-
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)
export_to_document_tokens
export_to_document_tokens(*args, **kwargs)
Export to DocTags format.
get_image
get_image(doc: DoclingDocument, prov_index: int = 0) -> 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.
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_doctagsβExport table to document tokens format.
-
export_to_document_tokensβExport to DocTags 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_doctags
export_to_doctags(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 = "") Deprecated
-
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_document_tokens
export_to_document_tokens(*args, **kwargs)
Export to DocTags format.
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(doc: Optional[DoclingDocument] = None) -> 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, prov_index: int = 0) -> 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.
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.
Methods:
-
get_colorβReturn the RGB color associated with a given label.
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'
get_color
get_color(label: TableCellLabel) -> Tuple[int, int, int]
Return the RGB color associated with a given label.
KeyValueItem
Bases: FloatingItem
KeyValueItem.
Methods:
-
caption_textβComputes the caption as a single text.
-
export_to_document_tokensβExport key value item to document tokens 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:
-
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)
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 key value item to document tokens format.
Parameters:
-
doc(DoclingDocument) β"DoclingDocument":
-
new_line(str, default:'') βstr (Default value = "") Deprecated
-
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, prov_index: int = 0) -> 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.
SectionHeaderItem
Bases: TextItem
SectionItem.
Methods:
-
export_to_doctagsβExport text element to document tokens format.
-
export_to_document_tokensβExport to DocTags 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) β -
formatting(Optional[Formatting]) β -
hyperlink(Optional[Union[AnyUrl, Path]]) β -
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
formatting
formatting: Optional[Formatting] = None
hyperlink
hyperlink: Optional[Union[AnyUrl, Path]] = Field(union_mode='left_to_right', default=None)
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_doctags
export_to_doctags(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 = "") Deprecated
-
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)
export_to_document_tokens
export_to_document_tokens(*args, **kwargs)
Export to DocTags format.
get_image
get_image(doc: DoclingDocument, prov_index: int = 0) -> 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.
PictureItem
Bases: FloatingItem
PictureItem.
Methods:
-
caption_textβComputes the caption as a single text.
-
export_to_doctagsβExport picture to document tokens format.
-
export_to_document_tokensβExport to DocTags 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, CHART]) β -
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_doctags
export_to_doctags(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 = "") Deprecated
-
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_document_tokens
export_to_document_tokens(*args, **kwargs)
Export to DocTags format.
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, prov_index: int = 0) -> 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.
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.
-
union_area_withβCalculates the union area with another bounding box.
-
x_overlap_withβCalculates the horizontal overlap with another bounding box.
-
x_union_withβCalculates the horizontal union dimension with another bounding box.
-
y_overlap_withβCalculates the vertical overlap with another bounding box, respecting coordinate origin.
-
y_union_withβCalculates the vertical union dimension with another bounding box, respecting coordinate 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) β
union_area_with
union_area_with(other: BoundingBox) -> float
Calculates the union area with another bounding box.
x_overlap_with
x_overlap_with(other: BoundingBox) -> float
Calculates the horizontal overlap with another bounding box.
x_union_with
x_union_with(other: BoundingBox) -> float
Calculates the horizontal union dimension with another bounding box.
y_overlap_with
y_overlap_with(other: BoundingBox) -> float
Calculates the vertical overlap with another bounding box, respecting coordinate origin.
y_union_with
y_union_with(other: BoundingBox) -> float
Calculates the vertical union dimension with another bounding box, respecting coordinate origin.
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'