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–Base type for any element that carries content, can be a leaf node.
-
DocItemLabel–DocItemLabel.
-
ProvenanceItem–Provenance information for elements extracted from a textual document.
-
GroupItem–GroupItem.
-
GroupLabel–GroupLabel.
-
NodeItem–NodeItem.
-
PageItem–PageItem.
-
FloatingItem–FloatingItem.
-
TextItem–TextItem.
-
TableItem–TableItem.
-
TableCell–A cell of a table, positioned in the table grid by row and column offsets.
-
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_comment–Adds a comment to the document, assigning it to the given targets.
-
add_document–Adds the content from the body of a DoclingDocument to this document under a specific parent.
-
add_field_heading–add_kv_heading.
-
add_field_hint–add_field_hint.
-
add_field_item–add_kv_entry.
-
add_field_key–add_field_key.
-
add_field_region–add_field_region.
-
add_field_value–add_field_value.
-
add_form–add_form.
-
add_formula–add_formula.
-
add_group–add_group.
-
add_heading–add_heading.
-
add_inline_group–Add an inline group, whose children are runs of one visual line of text.
-
add_key_values–add_key_values.
-
add_list_group–add_list_group.
-
add_list_item–add_list_item.
-
add_marker–add_marker.
-
add_node_items–Adds multiple NodeItems and their children under a parent in this document.
-
add_ordered_list–add_ordered_list.
-
add_page–add_page.
-
add_picture–add_picture.
-
add_table–add_table.
-
add_table_cell–Add a table cell to the table.
-
add_text–add_text.
-
add_title–add_title.
-
add_track–Add a track: a time-aligned media transcript.
-
add_unordered_list–add_unordered_list.
-
append_child_item–Adds an item.
-
check_version_is_compatible–Check if this document version is compatible with SDK schema version.
-
concatenate–Concatenate multiple documents into a single document.
-
delete_items–Deletes an item, given its instance or ref, and any children it has.
-
delete_items_range–Deletes all NodeItems and their children in the range from the start NodeItem to the end NodeItem.
-
export_to_dict–Export to dict.
-
export_to_doclang–Export to DocLang.
-
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 plain text.
-
export_to_vtt–Serializes the Docling document to WebVTT format.
-
extract_items_range–Extracts NodeItems and children in the range from the start NodeItem to the end as a new DoclingDocument.
-
filter–Create a new document based on the provided filter parameters.
-
get_min_page_size–Get the smallest page size that contains all content of a page.
-
get_min_page_sizes–Get the smallest page size that contains all content, for every page with content.
-
get_visualization–Get visualization of the document as images by page.
-
insert_code–Creates a new CodeItem item and inserts it into the document.
-
insert_document–Inserts the content from the body of a DoclingDocument into this document at a specific position.
-
insert_form–Creates a new FormItem item and inserts it into the document.
-
insert_formula–Creates a new FormulaItem item and inserts it into the document.
-
insert_group–Creates a new GroupItem item and inserts it into the document.
-
insert_heading–Creates a new SectionHeaderItem item and inserts it into the document.
-
insert_inline_group–Creates a new InlineGroup item and inserts it into the document.
-
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.
-
insert_key_values–Creates a new KeyValueItem item and inserts it into the document.
-
insert_list_group–Creates a new ListGroup item and inserts it into the document.
-
insert_list_item–Creates a new ListItem item and inserts it into the document.
-
insert_node_items–Insert multiple NodeItems and their children at a specific position in the document.
-
insert_picture–Creates a new PictureItem item and inserts it into the document.
-
insert_table–Creates a new TableItem item and inserts it into the document.
-
insert_text–Creates a new TextItem item and inserts it into the document.
-
insert_title–Creates a new TitleItem item and inserts it into the document.
-
insert_track–Creates a new TrackItem item and inserts it into the document.
-
iterate_items–Iterate elements with level.
-
load_from_doclang_archive–Load a DoclingDocument from a DocLang OPC archive (
.dclx). -
load_from_doctags–Load Docling document from lists of DocTags and Images.
-
load_from_json–load_from_json.
-
load_from_yaml–load_from_yaml.
-
load_local_images–Read all images referenced by a local path into memory.
-
num_pages–num_pages.
-
print_element_tree–Print_element_tree.
-
replace_item–Replace item with new item.
-
save_as_doclang–Save the document as DocLang (see
export_to_doclangfor the options). -
save_as_doclang_archive–Save the document as a DocLang OPC archive (
.dclx). -
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 the document to a JSON file.
-
save_as_markdown–Save to markdown.
-
save_as_vtt–Saves the Docling document to a file in WebVTT format.
-
save_as_yaml–Save as yaml.
-
transform_to_content_layer–transform_to_content_layer.
-
validate_document–validate_document.
-
validate_misplaced_list_items–validate_misplaced_list_items.
-
validate_tree–Validate that the subtree under
rootis a consistent tree.
Attributes:
-
body(GroupItem) – -
field_items(list[FieldItem]) – -
field_regions(list[FieldRegionItem]) – -
form_items(list[FormItem]) – -
furniture(Annotated[GroupItem, Field(deprecated=True)]) – -
groups(list[ListGroup | InlineGroup | GroupItem]) – -
key_value_items(list[KeyValueItem]) – -
name(str) – -
origin(DocumentOrigin | None) – -
pages(dict[int, PageItem]) – -
pictures(list[PictureItem]) – -
schema_name(Literal['DoclingDocument']) – -
tables(list[TableItem]) – -
texts(list[TitleItem | SectionHeaderItem | ListItem | CodeItem | FormulaItem | FieldHeadingItem | FieldValueItem | TextItem]) – -
tracks(list[TrackItem]) – -
version(Annotated[str, StringConstraints(pattern=VERSION_PATTERN, strict=True)]) –
field_items
field_items: list[FieldItem] = []
field_regions
field_regions: list[FieldRegionItem] = []
form_items
form_items: list[FormItem] = []
furniture
furniture: Annotated[GroupItem, Field(deprecated=True)] = (
GroupItem(
name="_root_",
self_ref="#/furniture",
content_layer=ContentLayer.FURNITURE,
)
)
name
name: str
schema_name
schema_name: Literal['DoclingDocument'] = 'DoclingDocument'
texts
texts: list[
TitleItem
| SectionHeaderItem
| ListItem
| CodeItem
| FormulaItem
| FieldHeadingItem
| FieldValueItem
| TextItem
] = []
tracks
tracks: list[TrackItem] = []
version
version: Annotated[
str,
StringConstraints(pattern=VERSION_PATTERN, strict=True),
] = CURRENT_VERSION
add_code
add_code(
text: str,
code_language: CodeLanguageLabel | None = None,
orig: str | None = None,
caption: TextItem | RefItem | None = None,
prov: ProvenanceItem | None = None,
parent: NodeItem | None = None,
content_layer: ContentLayer | None = None,
formatting: Formatting | None = None,
hyperlink: AnyUrl | Path | None = None,
*,
source: SourceType | None = None,
)
add_code.
Parameters:
-
text(str) –str:
-
code_language(CodeLanguageLabel | None, default:None) –Optional[CodeLanguageLabel]: (Default value = None)
-
orig(str | None, default:None) –Optional[str]: (Default value = None)
-
caption(TextItem | RefItem | None, default:None) –Optional[Union[TextItem:
-
RefItem]]–(Default value = None)
-
prov(ProvenanceItem | None, default:None) –Optional[ProvenanceItem]: (Default value = None)
-
parent(NodeItem | None, default:None) –Optional[NodeItem]: (Default value = None)
add_comment
add_comment(
*,
text: str,
prov: ProvenanceItem | None = None,
parent: NodeItem | None = None,
targets: list[DocItem | tuple[DocItem, tuple[int, int]]]
| None = None,
source: SourceType | None = None,
)
Adds a comment to the document, assigning it to the given targets.
Parameters:
-
text(str) –str:
-
prov(ProvenanceItem | None, default:None) –Optional[ProvenanceItem]: (Default value = None)
-
parent(NodeItem | None, default:None) –Optional[NodeItem]: (Default value = None)
-
targets(list[DocItem | tuple[DocItem, tuple[int, int]]] | None, default:None) –list[Union[DocItem, tuple[DocItem, tuple[int, int]]]]: (Default value = None) Each list element can be either a single DocItem or a tuple of a DocItem and a span range (start_inclusive, end_exclusive).
add_document
add_document(
doc: DoclingDocument, parent: NodeItem | None = None
) -> None
Adds the content from the body of a DoclingDocument to this document under a specific parent.
Parameters:
-
doc(DoclingDocument) –DoclingDocument: The document whose content will be added
-
parent(NodeItem | None, default:None) –Optional[NodeItem]: The parent NodeItem under which new items are added (Default value = None)
Returns:
-
None–None
add_field_heading
add_field_heading(
text: str,
orig: str | None = None,
level: LevelNumber = 1,
prov: ProvenanceItem | None = None,
parent: NodeItem | None = None,
content_layer: ContentLayer | None = None,
formatting: Formatting | None = None,
hyperlink: AnyUrl | Path | None = None,
*,
source: SourceType | None = None,
)
add_kv_heading.
Parameters:
-
label–DocItemLabel:
-
text(str) –str:
-
orig(str | None, default:None) –Optional[str]: (Default value = None)
-
level(LevelNumber, default:1) –LevelNumber: (Default value = 1)
-
prov(ProvenanceItem | None, default:None) –Optional[ProvenanceItem]: (Default value = None)
-
parent(NodeItem | None, default:None) –Optional[NodeItem]: (Default value = None)
-
content_layer(ContentLayer | None, default:None) –Optional[ContentLayer]: (Default value = None)
-
formatting(Formatting | None, default:None) –Optional[Formatting]: (Default value = None)
-
hyperlink(AnyUrl | Path | None, default:None) –Optional[Union[AnyUrl, Path]]: (Default value = None)
add_field_hint
add_field_hint(
text: str,
orig: str | None = None,
prov: ProvenanceItem | None = None,
parent: NodeItem | None = None,
content_layer: ContentLayer | None = None,
formatting: Formatting | None = None,
hyperlink: AnyUrl | Path | None = None,
*,
source: SourceType | None = None,
)
add_field_hint.
Parameters:
-
text(str) –str:
-
orig(str | None, default:None) –Optional[str]: (Default value = None)
-
prov(ProvenanceItem | None, default:None) –Optional[ProvenanceItem]: (Default value = None)
-
parent(NodeItem | None, default:None) –Optional[NodeItem]: (Default value = None)
-
content_layer(ContentLayer | None, default:None) –Optional[ContentLayer]: (Default value = None)
-
formatting(Formatting | None, default:None) –Optional[Formatting]: (Default value = None)
-
hyperlink(AnyUrl | Path | None, default:None) –Optional[Union[AnyUrl, Path]]: (Default value = None)
add_field_item
add_field_item(
prov: ProvenanceItem | None = None,
parent: NodeItem | None = None,
content_layer: ContentLayer | None = None,
*,
source: SourceType | None = None,
) -> FieldItem
add_kv_entry.
add_field_key
add_field_key(
text: str,
orig: str | None = None,
prov: ProvenanceItem | None = None,
parent: NodeItem | None = None,
content_layer: ContentLayer | None = None,
formatting: Formatting | None = None,
hyperlink: AnyUrl | Path | None = None,
*,
source: SourceType | None = None,
)
add_field_key.
Parameters:
-
label–DocItemLabel:
-
text(str) –str:
-
orig(str | None, default:None) –Optional[str]: (Default value = None)
-
prov(ProvenanceItem | None, default:None) –Optional[ProvenanceItem]: (Default value = None)
-
parent(NodeItem | None, default:None) –Optional[NodeItem]: (Default value = None)
-
content_layer(ContentLayer | None, default:None) –Optional[ContentLayer]: (Default value = None)
-
formatting(Formatting | None, default:None) –Optional[Formatting]: (Default value = None)
-
hyperlink(AnyUrl | Path | None, default:None) –Optional[Union[AnyUrl, Path]]: (Default value = None)
add_field_region
add_field_region(
prov: ProvenanceItem | None = None,
parent: NodeItem | None = None,
*,
source: SourceType | None = None,
) -> FieldRegionItem
add_field_region.
Parameters:
-
prov(ProvenanceItem | None, default:None) –Optional[ProvenanceItem]: (Default value = None)
-
parent(NodeItem | None, default:None) –Optional[NodeItem]: (Default value = None)
add_field_value
add_field_value(
text: str,
orig: str | None = None,
prov: ProvenanceItem | None = None,
parent: NodeItem | None = None,
content_layer: ContentLayer | None = None,
formatting: Formatting | None = None,
hyperlink: AnyUrl | Path | None = None,
kind: Literal["read_only", "fillable"]
| None = "read_only",
*,
source: SourceType | None = None,
)
add_field_value.
Parameters:
-
label–DocItemLabel:
-
text(str) –str:
-
orig(str | None, default:None) –Optional[str]: (Default value = None)
-
level–LevelNumber: (Default value = 1)
-
prov(ProvenanceItem | None, default:None) –Optional[ProvenanceItem]: (Default value = None)
-
parent(NodeItem | None, default:None) –Optional[NodeItem]: (Default value = None)
-
content_layer(ContentLayer | None, default:None) –Optional[ContentLayer]: (Default value = None)
-
formatting(Formatting | None, default:None) –Optional[Formatting]: (Default value = None)
-
hyperlink(AnyUrl | Path | None, default:None) –Optional[Union[AnyUrl, Path]]: (Default value = None)
-
kind(Literal['read_only', 'fillable'] | None, default:'read_only') –Optional[typing.Literal["read_only", "fillable", "fillable_with_hint"]]: (Default value = "read_only")
add_form
add_form(
graph: GraphData,
prov: ProvenanceItem | None = None,
parent: NodeItem | None = None,
*,
source: SourceType | None = None,
)
add_form.
Parameters:
-
graph(GraphData) –GraphData:
-
prov(ProvenanceItem | None, default:None) –Optional[ProvenanceItem]: (Default value = None)
-
parent(NodeItem | None, default:None) –Optional[NodeItem]: (Default value = None)
add_formula
add_formula(
text: str,
orig: str | None = None,
prov: ProvenanceItem | None = None,
parent: NodeItem | None = None,
content_layer: ContentLayer | None = None,
formatting: Formatting | None = None,
hyperlink: AnyUrl | Path | None = None,
*,
source: SourceType | None = None,
)
add_formula.
Parameters:
-
text(str) –str:
-
orig(str | None, default:None) –Optional[str]: (Default value = None)
-
level–LevelNumber: (Default value = 1)
-
prov(ProvenanceItem | None, default:None) –Optional[ProvenanceItem]: (Default value = None)
-
parent(NodeItem | None, default:None) –Optional[NodeItem]: (Default value = None)
add_group
add_group(
label: GroupLabel | None = None,
name: str | None = None,
parent: NodeItem | None = None,
content_layer: ContentLayer | None = None,
) -> GroupItem
add_group.
Parameters:
-
label(GroupLabel | None, default:None) –Optional[GroupLabel]: (Default value = None)
-
name(str | None, default:None) –Optional[str]: (Default value = None)
-
parent(NodeItem | None, default:None) –Optional[NodeItem]: (Default value = None)
add_heading
add_heading(
text: str,
orig: str | None = None,
level: LevelNumber = 1,
prov: ProvenanceItem | None = None,
parent: NodeItem | None = None,
content_layer: ContentLayer | None = None,
formatting: Formatting | None = None,
hyperlink: AnyUrl | Path | None = None,
*,
source: SourceType | None = None,
)
add_heading.
Parameters:
-
label–DocItemLabel:
-
text(str) –str:
-
orig(str | None, default:None) –Optional[str]: (Default value = None)
-
level(LevelNumber, default:1) –LevelNumber: (Default value = 1)
-
prov(ProvenanceItem | None, default:None) –Optional[ProvenanceItem]: (Default value = None)
-
parent(NodeItem | None, default:None) –Optional[NodeItem]: (Default value = None)
add_inline_group
add_inline_group(
name: str | None = None,
parent: NodeItem | None = None,
content_layer: ContentLayer | None = None,
) -> InlineGroup
Add an inline group, whose children are runs of one visual line of text.
Whitespace contract: each run carries its own significant whitespace and serializers
concatenate the runs faithfully, with no separator of their own. A producer that omits
the boundary whitespace gets merged words (["H", "2", "O"] renders as H2O), so
put the boundary in the run text: ["Advanced Topics", " in ", "Machine Learning"].
Whitespace at the edge of a formatted run is fine -- the serializers move it outside the
emphasis markers and hyperlink.
Children of a text item are block structure: serializers keep a parent text item's own text apart from this group (by a space or a block break). To put text flush against the runs, make it a run of the group.
add_key_values
add_key_values(
graph: GraphData,
prov: ProvenanceItem | None = None,
parent: NodeItem | None = None,
*,
source: SourceType | None = None,
)
add_key_values.
Parameters:
-
graph(GraphData) –GraphData:
-
prov(ProvenanceItem | None, default:None) –Optional[ProvenanceItem]: (Default value = None)
-
parent(NodeItem | None, default:None) –Optional[NodeItem]: (Default value = None)
add_list_group
add_list_group(
name: str | None = None,
parent: NodeItem | None = None,
content_layer: ContentLayer | None = None,
) -> ListGroup
add_list_group.
add_list_item
add_list_item(
text: str,
enumerated: bool = False,
marker: str | None = None,
orig: str | None = None,
prov: ProvenanceItem | None = None,
parent: NodeItem | None = None,
content_layer: ContentLayer | None = None,
formatting: Formatting | None = None,
hyperlink: AnyUrl | Path | None = None,
*,
source: SourceType | None = None,
)
add_list_item.
Parameters:
-
label–str:
-
text(str) –str:
-
orig(str | None, default:None) –Optional[str]: (Default value = None)
-
prov(ProvenanceItem | None, default:None) –Optional[ProvenanceItem]: (Default value = None)
-
parent(NodeItem | None, default:None) –Optional[NodeItem]: (Default value = None)
add_marker
add_marker(
text: str,
orig: str | None = None,
prov: ProvenanceItem | None = None,
parent: NodeItem | None = None,
content_layer: ContentLayer | None = None,
formatting: Formatting | None = None,
hyperlink: AnyUrl | Path | None = None,
*,
source: SourceType | None = None,
)
add_marker.
Parameters:
-
text(str) –str:
-
orig(str | None, default:None) –Optional[str]: (Default value = None)
-
prov(ProvenanceItem | None, default:None) –Optional[ProvenanceItem]: (Default value = None)
-
parent(NodeItem | None, default:None) –Optional[NodeItem]: (Default value = None)
-
content_layer(ContentLayer | None, default:None) –Optional[ContentLayer]: (Default value = None)
-
formatting(Formatting | None, default:None) –Optional[Formatting]: (Default value = None)
-
hyperlink(AnyUrl | Path | None, default:None) –Optional[Union[AnyUrl, Path]]: (Default value = None)
add_node_items
add_node_items(
node_items: list[NodeItem],
doc: DoclingDocument,
parent: NodeItem | None = None,
) -> None
Adds multiple NodeItems and their children under a parent in this document.
Parameters:
-
node_items(list[NodeItem]) –list[NodeItem]: The NodeItems to be added
-
doc(DoclingDocument) –DoclingDocument: The document to which the NodeItems and their children belong
-
parent(NodeItem | None, default:None) –Optional[NodeItem]: The parent NodeItem under which new items are added (Default value = None)
Returns:
-
None–None
add_ordered_list
add_ordered_list(
name: str | None = None,
parent: NodeItem | None = None,
content_layer: ContentLayer | None = None,
) -> GroupItem
add_ordered_list.
add_page
add_picture
add_picture(
annotations: list[PictureDataType] | None = None,
image: ImageRef | None = None,
caption: TextItem | RefItem | None = None,
prov: ProvenanceItem | None = None,
parent: NodeItem | None = None,
content_layer: ContentLayer | None = None,
*,
source: SourceType | None = None,
)
add_picture.
Parameters:
-
data–Optional[list[PictureData]]: (Default value = None)
-
caption(TextItem | RefItem | None, default:None) –Optional[Union[TextItem:
-
RefItem]]–(Default value = None)
-
prov(ProvenanceItem | None, default:None) –Optional[ProvenanceItem]: (Default value = None)
-
parent(NodeItem | None, default:None) –Optional[NodeItem]: (Default value = None)
add_table
add_table(
data: TableData,
caption: TextItem | RefItem | None = None,
prov: ProvenanceItem | None = None,
parent: NodeItem | None = None,
label: DocItemLabel = TABLE,
content_layer: ContentLayer | None = None,
annotations: list[TableAnnotationType] | None = None,
*,
source: SourceType | None = None,
)
add_table.
Parameters:
-
data(TableData) –TableData:
-
caption(TextItem | RefItem | None, default:None) –Optional[Union[TextItem, RefItem]]: (Default value = None)
-
prov(ProvenanceItem | None, default:None) –Optional[ProvenanceItem]: (Default value = None)
-
parent(NodeItem | None, default:None) –Optional[NodeItem]: (Default value = None)
-
label(DocItemLabel, default:TABLE) –DocItemLabel: (Default value = DocItemLabel.TABLE)
add_table_cell
Add a table cell to the table.
add_text
add_text(
label: DocItemLabel,
text: str,
orig: str | None = None,
prov: ProvenanceItem | None = None,
parent: NodeItem | None = None,
content_layer: ContentLayer | None = None,
formatting: Formatting | None = None,
hyperlink: AnyUrl | Path | None = None,
*,
source: SourceType | None = None,
**kwargs: Any,
)
add_text.
Parameters:
-
label(DocItemLabel) –str:
-
text(str) –str:
-
orig(str | None, default:None) –Optional[str]: (Default value = None)
-
prov(ProvenanceItem | None, default:None) –Optional[ProvenanceItem]: (Default value = None)
-
parent(NodeItem | None, default:None) –Optional[NodeItem]: (Default value = None)
add_title
add_title(
text: str,
orig: str | None = None,
prov: ProvenanceItem | None = None,
parent: NodeItem | None = None,
content_layer: ContentLayer | None = None,
formatting: Formatting | None = None,
hyperlink: AnyUrl | Path | None = None,
*,
source: SourceType | None = None,
)
add_title.
Parameters:
-
text(str) –str:
-
orig(str | None, default:None) –Optional[str]: (Default value = None)
-
level–LevelNumber: (Default value = 1)
-
prov(ProvenanceItem | None, default:None) –Optional[ProvenanceItem]: (Default value = None)
-
parent(NodeItem | None, default:None) –Optional[NodeItem]: (Default value = None)
add_track
add_track(
image: ImageRef | None = None,
caption: TextItem | RefItem | None = None,
prov: ProvenanceItem | None = None,
parent: NodeItem | None = None,
content_layer: ContentLayer | None = None,
audio: MediaRef | None = None,
video: MediaRef | None = None,
) -> TrackItem
Add a track: a time-aligned media transcript.
Add the cues of the track as its children, e.g. with add_text(...,
parent=track, source=TrackSource(...)).
Parameters:
-
image(ImageRef | None, default:None) –Optional[ImageRef]: The cover of the track. (Default value = None)
-
caption(TextItem | RefItem | None, default:None) –Optional[Union[TextItem, RefItem]]: (Default value = None)
-
prov(ProvenanceItem | None, default:None) –Optional[ProvenanceItem]: The location of the track. (Default value = None)
-
parent(NodeItem | None, default:None) –Optional[NodeItem]: (Default value = None)
-
content_layer(ContentLayer | None, default:None) –Optional[ContentLayer]: (Default value = None)
-
audio(MediaRef | None, default:None) –Optional[MediaRef]: The audio recording. (Default value = None)
-
video(MediaRef | None, default:None) –Optional[MediaRef]: The video recording. (Default value = None)
Returns:
-
TrackItem–TrackItem: The newly created TrackItem.
add_unordered_list
add_unordered_list(
name: str | None = None,
parent: NodeItem | None = None,
content_layer: ContentLayer | None = 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 SDK schema version.
concatenate
concatenate(
docs: Sequence[DoclingDocument],
) -> DoclingDocument
Concatenate multiple documents into a single document.
delete_items
delete_items(*, node_items: list[NodeItem]) -> None
Deletes an item, given its instance or ref, and any children it has.
delete_items_range
delete_items_range(
*,
start: NodeItem,
end: NodeItem,
start_inclusive: bool = True,
end_inclusive: bool = True,
) -> None
Deletes all NodeItems and their children in the range from the start NodeItem to the end NodeItem.
Parameters:
-
start(NodeItem) –NodeItem: The starting NodeItem of the range
-
end(NodeItem) –NodeItem: The ending NodeItem of the range
-
start_inclusive(bool, default:True) –bool: (Default value = True): If True, the start NodeItem will also be deleted
-
end_inclusive(bool, default:True) –bool: (Default value = True): If True, the end NodeItem will also be deleted
Returns:
-
None–None
export_to_dict
export_to_dict(
mode: str = "json",
by_alias: bool = True,
exclude_none: bool = True,
coord_precision: int | None = None,
confid_precision: int | None = None,
) -> dict[str, Any]
Export to dict.
export_to_doclang
export_to_doclang(
*,
add_named_groups: bool = False,
image_mode: ImageRefMode = PLACEHOLDER,
xsize: int | None = None,
ysize: int | None = None,
) -> str
Export to DocLang.
Args:
add_named_groups: When True, a plain GroupItem is emitted as a
<group name="..."> element instead of being transparent, so
the grouping survives a round trip.
image_mode: How picture images are included: PLACEHOLDER emits no
picture source, REFERENCED the pictures' existing image URIs and
EMBEDDED the images as data URIs.
xsize: Width of the location coordinate grid (default: DocLang default resolution).
ysize: Height of the location coordinate grid (default: DocLang default resolution).
export_to_doctags
export_to_doctags(
delim: str = "",
from_element: int = 0,
to_element: int = maxsize,
labels: set[DocItemLabel] | None = 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,
pages: set[int] | None = None,
) -> 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(set[DocItemLabel] | None, 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)
-
flagsadd_table_cell_location–bool
-
add_table_cell_text(bool, default:True) –bool: (Default value = True)
-
minified(bool, default:False) –bool: (Default value = False)
-
pages(set[int] | None, default:None) –set[int]: (Default value = None)
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: set[DocItemLabel] | None = None,
enable_chart_tables: bool = True,
image_mode: ImageRefMode = PLACEHOLDER,
formula_to_mathml: bool = True,
page_no: int | None = None,
html_lang: str = "en",
html_head: str = "null",
included_content_layers: set[ContentLayer]
| None = None,
split_page_view: bool = False,
include_annotations: bool = True,
image_dir: str | Path | None = None,
image_uri_prefix: str | None = None,
) -> 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] | None = None,
strict_text: bool = False,
escape_html: bool = True,
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: int | None = None,
included_content_layers: set[ContentLayer]
| None = None,
page_break_placeholder: str | None = None,
include_annotations: bool = True,
mark_annotations: bool = False,
compact_tables: bool = False,
traverse_pictures: bool = False,
image_dir: str | Path | None = None,
image_uri_prefix: str | None = None,
*,
use_legacy_annotations: bool | None = None,
allowed_meta_names: set[str] | None = None,
blocked_meta_names: set[str] | None = None,
mark_meta: bool = False,
include_picture_classification: bool = True,
caption_placement: CaptionPlacement = STANDARD,
formatting_fallback_mode: FormattingFallbackMode = NONE,
) -> 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(set[DocItemLabel] | None, 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_html(bool, default:True) –bool: Whether to escape HTML reserved characters in the text content of the document. (Default value = True).
-
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(set[ContentLayer] | None, default:None) –The set of layels to include in the export. None falls back to the system-defined default.
-
page_break_placeholder(str | None, 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; only considered if item does not have meta. (Default value = True).
-
mark_annotations(bool, default:False) –bool: Whether to mark annotations in the export; only considered if item does not have meta. (Default value = False).
-
compact_tables(bool, default:False) –bool: Whether to use compact table format without column padding. (Default value = False).
-
traverse_pictures(bool, default:False) –bool: Whether to traverse into picture items and serialize their text children. Must be set to True for scanned/image-based PDFs processed with full-page OCR, where the layout model places all OCR text as children of a top-level PictureItem. (Default value = False).
-
image_dir(str | Path | None, default:None) –Optional directory path where images will be saved when using ImageRefMode.REFERENCED. If provided, images are automatically saved to this directory and referenced in the markdown output. (Default value = None).
-
image_uri_prefix(str | None, default:None) –Optional prefix prepended to each saved image's file name to build a portable image URI in the output (e.g. "images/" or "https://cdn/assets/"). If None, the referenced image path is used as-is, which may be an absolute filesystem path. (Default value = None).
-
use_legacy_annotations(bool | None, default:None) –bool: Deprecated; legacy annotations considered only when meta not present.
-
mark_meta(bool, default:False) –bool: Whether to mark meta in the export
-
allowed_meta_names(set[str] | None, default:None) –Optional[set[str]]: Meta names to allow; None means all meta names are allowed.
-
blocked_meta_names(set[str] | None, default:None) –Optional[set[str]]: Meta names to block; takes precedence over allowed_meta_names.
-
include_picture_classification(bool, default:True) –bool: Whether to include the picture classification prediction (the image's predicted class) in the export. (Default value = True).
-
caption_placement(CaptionPlacement, default:STANDARD) –Where captions go relative to their item: "standard" keeps the per-type order (before tables and pictures, after code and formulas); "layout" places a caption after its item if the caption's bbox center is lower on the page, else before, falling back to "standard" when positions are unavailable. (Default value = CaptionPlacement.STANDARD).
-
formatting_fallback_mode(FormattingFallbackMode, default:NONE) –How to render formatting that has no Markdown syntax (underline, subscript, superscript): drop it (NONE) or use HTML tags (HTML). (Default value = FormattingFallbackMode.NONE).
Returns:
-
str–The exported Markdown representation.
export_to_text
export_to_text(
delim: str = "\n\n",
from_element: int = 0,
to_element: int = maxsize,
labels: set[DocItemLabel] | None = None,
page_no: int | None = None,
included_content_layers: set[ContentLayer]
| None = None,
page_break_placeholder: str | None = None,
traverse_pictures: bool = False,
) -> str
Export to plain text.
Produces clean plain text without any Markdown decoration. Heading
markers (#), bold/italic markers, and hyperlink syntax are all
stripped. List bullets (-), ordered list numbers, and table-cell
separators (|) are preserved as they aid readability.
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(set[DocItemLabel] | None, default:None) –The set of document labels to include in the export. None falls back to the system-defined default.
-
page_no(int | None, default:None) –If set, only content from this page is exported.
-
included_content_layers(set[ContentLayer] | None, default:None) –The set of layers to include. None falls back to the system-defined default.
-
page_break_placeholder(str | None, default:None) –String inserted at page boundaries. None means no page-break marker is emitted.
-
traverse_pictures(bool, default:False) –bool: Whether to traverse into picture items and include their text children. Must be set to True for scanned/image-based PDFs processed with full-page OCR, where the layout model places all OCR text as children of a top-level PictureItem. (Default value = False).
Returns:
-
str–The exported plain-text representation.
export_to_vtt
export_to_vtt(
included_content_layers: set[ContentLayer]
| None = None,
omit_hours_if_zero: bool = False,
omit_voice_end: bool = False,
) -> str
Serializes the Docling document to WebVTT format.
Args:
included_content_layers: The content layers to serialize. If omitted, the DEFAULT_CONTENT_LAYERS will
be serialized.
omit_hours_if_zero: If True, omit hours when they are 0 in the timings.
omit_voice_end: If True and cue blocks have a WebVTT cue voice span as the only component, omit the voice
end tag for brevity.
Returns: A string representation of the Docling document in WebVTT format.
extract_items_range
extract_items_range(
*,
start: NodeItem,
end: NodeItem,
start_inclusive: bool = True,
end_inclusive: bool = True,
delete: bool = False,
) -> DoclingDocument
Extracts NodeItems and children in the range from the start NodeItem to the end as a new DoclingDocument.
Parameters:
-
start(NodeItem) –NodeItem: The starting NodeItem of the range (must be a direct child of the document body)
-
end(NodeItem) –NodeItem: The ending NodeItem of the range (must be a direct child of the document body)
-
start_inclusive(bool, default:True) –bool: (Default value = True): If True, the start NodeItem will also be extracted
-
end_inclusive(bool, default:True) –bool: (Default value = True): If True, the end NodeItem will also be extracted
-
delete(bool, default:False) –bool: (Default value = False): If True, extracted items are deleted in the original document
Returns:
-
DoclingDocument–DoclingDocument: A new document containing the extracted NodeItems and their children
filter
filter(page_nrs: set[int] | None = None) -> DoclingDocument
Create a new document based on the provided filter parameters.
get_min_page_size
get_min_page_size(page_no: int) -> Size
Get the smallest page size that contains all content of a page.
See get_min_page_sizes, which computes all pages in one pass.
Args: page_no: 1-based page number to measure.
Returns:
The minimum page size, Size(width=0, height=0) if the page has
no bounding boxes.
get_min_page_sizes
get_min_page_sizes() -> dict[int, Size]
Get the smallest page size that contains all content, for every page with content.
The size of a page is the largest horizontal and vertical coordinate
over all bounding boxes anchored on it: item provenances, table cell
bboxes and key-value/form graph cell provenances, in every content
layer. Coordinates are measured from 0, as the page-bounds
validation does, so with these sizes validation does not clamp any
content bbox from above. Negative coordinates are not accounted for and
are still clamped to 0.
Returns: A mapping from 1-based page number to minimum page size, for each page that has at least one bounding box.
get_visualization
get_visualization(
show_label: bool = True,
show_branch_numbering: bool = False,
viz_mode: Literal[
"reading_order", "key_value"
] = "reading_order",
show_cell_id: bool = False,
) -> dict[int | None, Image]
Get visualization of the document as images by page.
Parameters:
-
show_label(bool, default:True) –Show labels on elements (applies to all visualizers).
-
show_branch_numbering(bool, default:False) –Show branch numbering (reading order visualizer only).
-
visualizer(str) –Which visualizer to use. One of 'reading_order' (default), 'key_value'.
-
show_cell_id(bool, default:False) –Show cell IDs (key value visualizer only).
Returns:
-
dict[Optional[int], PILImage.Image]–Dictionary mapping page numbers to PIL images.
insert_code
insert_code(
sibling: NodeItem,
text: str,
code_language: CodeLanguageLabel | None = None,
orig: str | None = None,
caption: TextItem | RefItem | None = None,
prov: ProvenanceItem | None = None,
content_layer: ContentLayer | None = None,
formatting: Formatting | None = None,
hyperlink: AnyUrl | Path | None = None,
after: bool = True,
) -> CodeItem
Creates a new CodeItem item and inserts it into the document.
Parameters:
-
sibling(NodeItem) –NodeItem:
-
text(str) –str:
-
code_language(CodeLanguageLabel | None, default:None) –Optional[str]: (Default value = None)
-
orig(str | None, default:None) –Optional[str]: (Default value = None)
-
caption(TextItem | RefItem | None, default:None) –Optional[Union[TextItem, RefItem]]: (Default value = None)
-
prov(ProvenanceItem | None, default:None) –Optional[ProvenanceItem]: (Default value = None)
-
content_layer(ContentLayer | None, default:None) –Optional[ContentLayer]: (Default value = None)
-
formatting(Formatting | None, default:None) –Optional[Formatting]: (Default value = None)
-
hyperlink(AnyUrl | Path | None, default:None) –Optional[Union[AnyUrl, Path]]: (Default value = None)
-
after(bool, default:True) –bool: (Default value = True)
Returns:
-
CodeItem–CodeItem: The newly created CodeItem item.
insert_document
insert_document(
doc: DoclingDocument,
sibling: NodeItem,
after: bool = True,
) -> None
Inserts the content from the body of a DoclingDocument into this document at a specific position.
Parameters:
-
doc(DoclingDocument) –DoclingDocument: The document whose content will be inserted
-
sibling(NodeItem) –NodeItem: The NodeItem after/before which the new items will be inserted
-
after(bool, default:True) –bool: If True, insert after the sibling; if False, insert before (Default value = True)
Returns:
-
None–None
insert_form
insert_form(
sibling: NodeItem,
graph: GraphData,
prov: ProvenanceItem | None = None,
after: bool = True,
) -> FormItem
Creates a new FormItem item and inserts it into the document.
Parameters:
-
sibling(NodeItem) –NodeItem:
-
graph(GraphData) –GraphData:
-
prov(ProvenanceItem | None, default:None) –Optional[ProvenanceItem]: (Default value = None)
-
after(bool, default:True) –bool: (Default value = True)
Returns:
-
FormItem–FormItem: The newly created FormItem item.
insert_formula
insert_formula(
sibling: NodeItem,
text: str,
orig: str | None = None,
prov: ProvenanceItem | None = None,
content_layer: ContentLayer | None = None,
formatting: Formatting | None = None,
hyperlink: AnyUrl | Path | None = None,
after: bool = True,
) -> FormulaItem
Creates a new FormulaItem item and inserts it into the document.
Parameters:
-
sibling(NodeItem) –NodeItem:
-
text(str) –str:
-
orig(str | None, default:None) –Optional[str]: (Default value = None)
-
prov(ProvenanceItem | None, default:None) –Optional[ProvenanceItem]: (Default value = None)
-
content_layer(ContentLayer | None, default:None) –Optional[ContentLayer]: (Default value = None)
-
formatting(Formatting | None, default:None) –Optional[Formatting]: (Default value = None)
-
hyperlink(AnyUrl | Path | None, default:None) –Optional[Union[AnyUrl, Path]]: (Default value = None)
-
after(bool, default:True) –bool: (Default value = True)
Returns:
-
FormulaItem–FormulaItem: The newly created FormulaItem item.
insert_group
insert_group(
sibling: NodeItem,
label: GroupLabel | None = None,
name: str | None = None,
content_layer: ContentLayer | None = None,
after: bool = True,
) -> GroupItem
Creates a new GroupItem item and inserts it into the document.
Parameters:
-
sibling(NodeItem) –NodeItem:
-
label(GroupLabel | None, default:None) –Optional[GroupLabel]: (Default value = None)
-
name(str | None, default:None) –Optional[str]: (Default value = None)
-
content_layer(ContentLayer | None, default:None) –Optional[ContentLayer]: (Default value = None)
-
after(bool, default:True) –bool: (Default value = True)
Returns:
-
GroupItem–GroupItem: The newly created GroupItem.
insert_heading
insert_heading(
sibling: NodeItem,
text: str,
orig: str | None = None,
level: LevelNumber = 1,
prov: ProvenanceItem | None = None,
content_layer: ContentLayer | None = None,
formatting: Formatting | None = None,
hyperlink: AnyUrl | Path | None = None,
after: bool = True,
) -> SectionHeaderItem
Creates a new SectionHeaderItem item and inserts it into the document.
Parameters:
-
sibling(NodeItem) –NodeItem:
-
text(str) –str:
-
orig(str | None, default:None) –Optional[str]: (Default value = None)
-
level(LevelNumber, default:1) –LevelNumber: (Default value = 1)
-
prov(ProvenanceItem | None, default:None) –Optional[ProvenanceItem]: (Default value = None)
-
content_layer(ContentLayer | None, default:None) –Optional[ContentLayer]: (Default value = None)
-
formatting(Formatting | None, default:None) –Optional[Formatting]: (Default value = None)
-
hyperlink(AnyUrl | Path | None, default:None) –Optional[Union[AnyUrl, Path]]: (Default value = None)
-
after(bool, default:True) –bool: (Default value = True)
Returns:
-
SectionHeaderItem–SectionHeaderItem: The newly created SectionHeaderItem item.
insert_inline_group
insert_inline_group(
sibling: NodeItem,
name: str | None = None,
content_layer: ContentLayer | None = None,
after: bool = True,
) -> InlineGroup
Creates a new InlineGroup item and inserts it into the document.
Parameters:
-
sibling(NodeItem) –NodeItem:
-
name(str | None, default:None) –Optional[str]: (Default value = None)
-
content_layer(ContentLayer | None, default:None) –Optional[ContentLayer]: (Default value = None)
-
after(bool, default:True) –bool: (Default value = True)
Returns:
-
InlineGroup–InlineGroup: The newly created InlineGroup item.
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.
insert_key_values
insert_key_values(
sibling: NodeItem,
graph: GraphData,
prov: ProvenanceItem | None = None,
after: bool = True,
) -> KeyValueItem
Creates a new KeyValueItem item and inserts it into the document.
Parameters:
-
sibling(NodeItem) –NodeItem:
-
graph(GraphData) –GraphData:
-
prov(ProvenanceItem | None, default:None) –Optional[ProvenanceItem]: (Default value = None)
-
after(bool, default:True) –bool: (Default value = True)
Returns:
-
KeyValueItem–KeyValueItem: The newly created KeyValueItem item.
insert_list_group
insert_list_group(
sibling: NodeItem,
name: str | None = None,
content_layer: ContentLayer | None = None,
after: bool = True,
) -> ListGroup
Creates a new ListGroup item and inserts it into the document.
Parameters:
-
sibling(NodeItem) –NodeItem:
-
name(str | None, default:None) –Optional[str]: (Default value = None)
-
content_layer(ContentLayer | None, default:None) –Optional[ContentLayer]: (Default value = None)
-
after(bool, default:True) –bool: (Default value = True)
Returns:
-
ListGroup–ListGroup: The newly created ListGroup item.
insert_list_item
insert_list_item(
sibling: NodeItem,
text: str,
enumerated: bool = False,
marker: str | None = None,
orig: str | None = None,
prov: ProvenanceItem | None = None,
content_layer: ContentLayer | None = None,
formatting: Formatting | None = None,
hyperlink: AnyUrl | Path | None = None,
after: bool = True,
) -> ListItem
Creates a new ListItem item and inserts it into the document.
Parameters:
-
sibling(NodeItem) –NodeItem:
-
text(str) –str:
-
enumerated(bool, default:False) –bool: (Default value = False)
-
marker(str | None, default:None) –Optional[str]: (Default value = None)
-
orig(str | None, default:None) –Optional[str]: (Default value = None)
-
prov(ProvenanceItem | None, default:None) –Optional[ProvenanceItem]: (Default value = None)
-
content_layer(ContentLayer | None, default:None) –Optional[ContentLayer]: (Default value = None)
-
formatting(Formatting | None, default:None) –Optional[Formatting]: (Default value = None)
-
hyperlink(AnyUrl | Path | None, default:None) –Optional[Union[AnyUrl, Path]]: (Default value = None)
-
after(bool, default:True) –bool: (Default value = True)
Returns:
-
ListItem–ListItem: The newly created ListItem item.
insert_node_items
insert_node_items(
sibling: NodeItem,
node_items: list[NodeItem],
doc: DoclingDocument,
after: bool = True,
) -> None
Insert multiple NodeItems and their children at a specific position in the document.
Parameters:
-
sibling(NodeItem) –NodeItem: The NodeItem after/before which the new items will be inserted
-
node_items(list[NodeItem]) –list[NodeItem]: The NodeItems to be inserted
-
doc(DoclingDocument) –DoclingDocument: The document to which the NodeItems and their children belong
-
after(bool, default:True) –bool: If True, insert after the sibling; if False, insert before (Default value = True)
Returns:
-
None–None
insert_picture
insert_picture(
sibling: NodeItem,
annotations: list[PictureDataType] | None = None,
image: ImageRef | None = None,
caption: TextItem | RefItem | None = None,
prov: ProvenanceItem | None = None,
content_layer: ContentLayer | None = None,
after: bool = True,
) -> PictureItem
Creates a new PictureItem item and inserts it into the document.
Parameters:
-
sibling(NodeItem) –NodeItem:
-
annotations(list[PictureDataType] | None, default:None) –Optional[list[PictureDataType]]: (Default value = None)
-
image(ImageRef | None, default:None) –Optional[ImageRef]: (Default value = None)
-
caption(TextItem | RefItem | None, default:None) –Optional[Union[TextItem, RefItem]]: (Default value = None)
-
prov(ProvenanceItem | None, default:None) –Optional[ProvenanceItem]: (Default value = None)
-
content_layer(ContentLayer | None, default:None) –Optional[ContentLayer]: (Default value = None)
-
after(bool, default:True) –bool: (Default value = True)
Returns:
-
PictureItem–PictureItem: The newly created PictureItem item.
insert_table
insert_table(
sibling: NodeItem,
data: TableData,
caption: TextItem | RefItem | None = None,
prov: ProvenanceItem | None = None,
label: DocItemLabel = TABLE,
content_layer: ContentLayer | None = None,
annotations: list[TableAnnotationType] | None = None,
after: bool = True,
) -> TableItem
Creates a new TableItem item and inserts it into the document.
Parameters:
-
sibling(NodeItem) –NodeItem:
-
data(TableData) –TableData:
-
caption(TextItem | RefItem | None, default:None) –Optional[Union[TextItem, RefItem]]: (Default value = None)
-
prov(ProvenanceItem | None, default:None) –Optional[ProvenanceItem]: (Default value = None)
-
label(DocItemLabel, default:TABLE) –DocItemLabel: (Default value = DocItemLabel.TABLE)
-
content_layer(ContentLayer | None, default:None) –Optional[ContentLayer]: (Default value = None)
-
annotations(list[TableAnnotationType] | None, default:None) –Optional[list[TableAnnotationType]]: (Default value = None)
-
after(bool, default:True) –bool: (Default value = True)
Returns:
-
TableItem–TableItem: The newly created TableItem item.
insert_text
insert_text(
sibling: NodeItem,
label: DocItemLabel,
text: str,
orig: str | None = None,
prov: ProvenanceItem | None = None,
content_layer: ContentLayer | None = None,
formatting: Formatting | None = None,
hyperlink: AnyUrl | Path | None = None,
after: bool = True,
) -> TextItem
Creates a new TextItem item and inserts it into the document.
Parameters:
-
sibling(NodeItem) –NodeItem:
-
label(DocItemLabel) –DocItemLabel:
-
text(str) –str:
-
orig(str | None, default:None) –Optional[str]: (Default value = None)
-
prov(ProvenanceItem | None, default:None) –Optional[ProvenanceItem]: (Default value = None)
-
content_layer(ContentLayer | None, default:None) –Optional[ContentLayer]: (Default value = None)
-
formatting(Formatting | None, default:None) –Optional[Formatting]: (Default value = None)
-
hyperlink(AnyUrl | Path | None, default:None) –Optional[Union[AnyUrl, Path]]: (Default value = None)
-
after(bool, default:True) –bool: (Default value = True)
Returns:
-
TextItem–TextItem: The newly created TextItem item.
insert_title
insert_title(
sibling: NodeItem,
text: str,
orig: str | None = None,
prov: ProvenanceItem | None = None,
content_layer: ContentLayer | None = None,
formatting: Formatting | None = None,
hyperlink: AnyUrl | Path | None = None,
after: bool = True,
) -> TitleItem
Creates a new TitleItem item and inserts it into the document.
Parameters:
-
sibling(NodeItem) –NodeItem:
-
text(str) –str:
-
orig(str | None, default:None) –Optional[str]: (Default value = None)
-
prov(ProvenanceItem | None, default:None) –Optional[ProvenanceItem]: (Default value = None)
-
content_layer(ContentLayer | None, default:None) –Optional[ContentLayer]: (Default value = None)
-
formatting(Formatting | None, default:None) –Optional[Formatting]: (Default value = None)
-
hyperlink(AnyUrl | Path | None, default:None) –Optional[Union[AnyUrl, Path]]: (Default value = None)
-
after(bool, default:True) –bool: (Default value = True)
Returns:
-
TitleItem–TitleItem: The newly created TitleItem item.
insert_track
insert_track(
sibling: NodeItem,
image: ImageRef | None = None,
caption: TextItem | RefItem | None = None,
prov: ProvenanceItem | None = None,
content_layer: ContentLayer | None = None,
after: bool = True,
audio: MediaRef | None = None,
video: MediaRef | None = None,
) -> TrackItem
Creates a new TrackItem item and inserts it into the document.
Parameters:
-
sibling(NodeItem) –NodeItem:
-
image(ImageRef | None, default:None) –Optional[ImageRef]: The cover of the track. (Default value = None)
-
caption(TextItem | RefItem | None, default:None) –Optional[Union[TextItem, RefItem]]: (Default value = None)
-
prov(ProvenanceItem | None, default:None) –Optional[ProvenanceItem]: The location of the track. (Default value = None)
-
content_layer(ContentLayer | None, default:None) –Optional[ContentLayer]: (Default value = None)
-
after(bool, default:True) –bool: (Default value = True)
-
audio(MediaRef | None, default:None) –Optional[MediaRef]: The audio recording. (Default value = None)
-
video(MediaRef | None, default:None) –Optional[MediaRef]: The video recording. (Default value = None)
Returns:
-
TrackItem–TrackItem: The newly created TrackItem.
iterate_items
iterate_items(
root: NodeItem | None = None,
with_groups: bool = False,
traverse_pictures: bool = False,
page_no: int | None = None,
included_content_layers: set[ContentLayer]
| None = None,
_level: int = 0,
) -> Iterable[tuple[NodeItem, int]]
Iterate elements with level.
load_from_doclang_archive
load_from_doclang_archive(
filename: str | Path,
*,
artifacts_dir: Path | None = None,
validate: bool = False,
max_member_size: int = 512 * 1024 * 1024,
max_total_size: int = 2 * 1024 * 1024 * 1024,
) -> DoclingDocument
Load a DoclingDocument from a DocLang OPC archive (.dclx).
By default nothing is written next to the archive: it is extracted to a temporary
directory, which is removed once the document is loaded. Picture and page images
are then held as data: URIs, and the audio and video of tracks as bytes
(MediaRef.from_bytes), so the whole package is kept in memory.
With artifacts_dir, the archive is extracted there and kept: images and media
reference the extracted files, and large media is not held in memory.
Args:
filename: Path to the .dclx archive.
artifacts_dir: Optional directory to extract the package members to, and to keep
them in. A relative path is taken from the folder of the .dclx file.
validate: When True, run DocLang XSD/Schematron validation on document.xml.
max_member_size: Maximum uncompressed size in bytes for any single archive member
(default: 512 MiB).
max_total_size: Maximum cumulative uncompressed size in bytes for all members
(default: 2 GiB).
Notes:
document.xml is additionally capped by settings.max_doclang_xml_bytes before
parsing. Archive assets/ and pages/ images are capped by
settings.max_image_decoded_size before Pillow opens them.
The bytes of the audio and video of tracks are not part of the document's JSON
(see ``MediaRef.from_bytes``). Without ``artifacts_dir``, the in-memory copy is the
only one: a document saved as JSON keeps the media type and the path inside the
archive, but not the recording. To convert a ``.dclx`` with media to JSON, load it
with ``artifacts_dir`` (and save it with ``allow_local_media`` later), or keep the
archive.
Unlike JSON, DocLang carries no schema version, so archives written by docling-core
before schema 1.11.0 (the inline whitespace contract) are loaded as current: their
inline runs were stored without boundary whitespace and now join without a separator
(``Normal**bold**tail``). Re-convert the source, or keep JSON for long-term storage.
load_from_doctags
load_from_doctags(
doctag_document: DocTagsDocument,
document_name: str = "Document",
) -> DoclingDocument
Load Docling document from lists of DocTags and Images.
Limitation: DocTags stores each <inline> run trimmed, so the boundary whitespace that
the inline whitespace contract expects in the runs (see add_inline_group) is not in the
source and is not restored. Serializing such an inline group joins its runs without spaces.
load_from_json
load_from_json(
filename: str | Path, allow_local_images: bool = False
) -> DoclingDocument
load_from_json.
Parameters:
-
filename(str | Path) –The filename to load a saved DoclingDocument from a .json.
-
allow_local_images(bool, default:False) –For trusted documents only: read images referenced by a local path (relative to the file's directory) into memory, see
load_local_images.
Returns:
-
DoclingDocument–The loaded DoclingDocument.
load_from_yaml
load_from_yaml(
filename: str | Path, allow_local_images: bool = False
) -> DoclingDocument
load_from_yaml.
Args:
filename: The filename to load a YAML-serialized DoclingDocument from.
allow_local_images: For trusted documents only: read images referenced
by a local path (relative to the file's directory) into memory, see
load_local_images.
Returns: DoclingDocument: the loaded DoclingDocument
load_local_images
load_local_images(base_dir: Path | None = None) -> None
Read all images referenced by a local path into memory.
Images of items and pages may reference a local file, either as a
file:// URI or as a filesystem path. Since these paths come from the
document content, reading them is disabled by default (see
settings.allow_image_file_uri). Calling this method is an explicit
opt-in for a trusted document: the images are read now and kept in memory,
so later exports do not access these paths again.
Args: base_dir: Directory to resolve relative paths against; defaults to the current working directory. Absolute paths are used as they are.
Raises:
ValueError: If a referenced path is not a regular file or exceeds
settings.max_image_decoded_size.
num_pages
num_pages()
num_pages.
print_element_tree
print_element_tree()
Print_element_tree.
replace_item
Replace item with new item.
save_as_doclang
save_as_doclang(
filename: str | Path,
*,
add_named_groups: bool = False,
image_mode: ImageRefMode = PLACEHOLDER,
xsize: int | None = None,
ysize: int | None = None,
) -> None
Save the document as DocLang (see export_to_doclang for the options).
save_as_doclang_archive
save_as_doclang_archive(
filename: str | Path,
*,
artifacts_dir: Path | None = None,
validate: bool = False,
add_named_groups: bool = False,
include_namespace: bool = False,
image_mode: ImageRefMode = REFERENCED,
xsize: int | None = None,
ysize: int | None = None,
allow_local_media: bool = False,
source: Path | bytes | None = None,
) -> None
Save the document as a DocLang OPC archive (.dclx).
Picture and page images are always stored outside the markup, under
assets/ and pages/ in the archive respectively.
DocLang does not record page numbers: the n-th page of the markup is the n-th
page of the document. Pages are therefore numbered consecutively from 1 in the
archive, and pages/{n}.png holds the image of the n-th page in ascending
page-number order. Gaps and a first page number other than 1 are not preserved
when the archive is loaded.
image_mode controls the picture images: REFERENCED (default) stores each
picture's image (cropped from its page image if it has none of its own) under
assets/ and references it from the picture, PLACEHOLDER stores and
references none. EMBEDDED is not supported, as the archive keeps images
outside the markup. Page images are stored in either case.
add_named_groups emits plain GroupItems as <group name="...">
elements so the grouping survives a round trip.
xsize / ysize set the location coordinate grid (default: DocLang default resolution).
The audio and video of each track are stored as audio/{N}.* and
video/{N}.*, where N is the position of its <track>. A media file is
read if its MediaRef was made with from_file or comes from a loaded archive,
and media made with from_bytes is written as is.
Other local paths are document content, and are read only with allow_local_media
(for trusted documents) or settings.allow_media_file_uri. Media that cannot be
read is left out, with a warning.
source is the original document the content was converted from, as a file path
or as bytes. It is stored unchanged in the archive, which records its file name and
media type from origin (for a path without origin, its own name and the media
type guessed from it). A source that is also stored as the media of a track is not
stored twice.
include_namespace declares the DocLang namespace on the root element. It is
required for validate to pass, as the schema only declares the namespaced root.
Note that validate also runs the Schematron rules, which need a Schematron backend
to be installed for doclang.
save_as_doctags
save_as_doctags(
filename: str | Path,
delim: str = "",
from_element: int = 0,
to_element: int = maxsize,
labels: set[DocItemLabel] | None = 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: str | Path,
artifacts_dir: Path | None = None,
from_element: int = 0,
to_element: int = maxsize,
labels: set[DocItemLabel] | None = None,
image_mode: ImageRefMode = PLACEHOLDER,
formula_to_mathml: bool = True,
page_no: int | None = None,
html_lang: str = "en",
html_head: str = "null",
included_content_layers: set[ContentLayer]
| None = None,
split_page_view: bool = False,
include_annotations: bool = True,
)
Save to HTML.
save_as_json
save_as_json(
filename: str | Path,
artifacts_dir: Path | None = None,
image_mode: ImageRefMode = EMBEDDED,
indent: int = 2,
coord_precision: int | None = None,
confid_precision: int | None = None,
*,
ensure_ascii: bool = True,
sort_keys: bool = False,
) -> None
Save the document to a JSON file.
Args:
filename: Output file path.
artifacts_dir: Directory for referenced image artifacts. Defaults to a
subdirectory next to filename.
image_mode: How to handle embedded images.
indent: Indentation level passed to json.dumps.
coord_precision: Decimal precision for bounding-box coordinates. If
None, full precision is used.
confid_precision: Decimal precision for confidence scores. If None,
full precision is used.
ensure_ascii: When True (the default), non-ASCII characters are
escaped as \uXXXX sequences. Set to False to write literal
Unicode characters.
sort_keys: When True, object keys are sorted alphabetically,
producing deterministic output suitable for diffing.
save_as_markdown
save_as_markdown(
filename: str | Path,
artifacts_dir: Path | None = None,
delim: str = "\n\n",
from_element: int = 0,
to_element: int = maxsize,
labels: set[DocItemLabel] | None = None,
strict_text: bool = False,
escape_html: bool = True,
escaping_underscores: bool = True,
image_placeholder: str = "<!-- image -->",
image_mode: ImageRefMode = PLACEHOLDER,
indent: int = 4,
text_width: int = -1,
page_no: int | None = None,
included_content_layers: set[ContentLayer]
| None = None,
page_break_placeholder: str | None = None,
include_annotations: bool = True,
compact_tables: bool = False,
*,
enable_chart_tables: bool = True,
traverse_pictures: bool = False,
mark_meta: bool = False,
use_legacy_annotations: bool | None = None,
include_picture_classification: bool = True,
caption_placement: CaptionPlacement = STANDARD,
formatting_fallback_mode: FormattingFallbackMode = NONE,
)
Save to markdown.
save_as_vtt
save_as_vtt(
filename: str | Path,
included_content_layers: set[ContentLayer]
| None = None,
omit_hours_if_zero: bool = False,
omit_voice_end: bool = True,
) -> None
Saves the Docling document to a file in WebVTT format.
Args:
filename: The path to the WebVTT file.
included_content_layers: The content layers to serialize. If omitted, the DEFAULT_CONTENT_LAYERS will
be serialized.
omit_hours_if_zero: If True, omit hours when they are 0 in the timings.
omit_voice_end: If True and cue blocks have a WebVTT cue voice span as the only component, omit the voice
end tag for brevity.
save_as_yaml
save_as_yaml(
filename: str | Path,
artifacts_dir: Path | None = None,
image_mode: ImageRefMode = EMBEDDED,
default_flow_style: bool = False,
coord_precision: int | None = None,
confid_precision: int | None = None,
)
Save as yaml.
transform_to_content_layer
transform_to_content_layer(data: Any) -> Any
transform_to_content_layer.
validate_document
validate_document() -> Self
validate_document.
validate_misplaced_list_items
validate_misplaced_list_items() -> Self
validate_misplaced_list_items.
validate_tree
validate_tree(
root: NodeItem,
raise_on_error: bool = False,
_visited: set[str] | None = None,
) -> bool
Validate that the subtree under root is a consistent tree.
Every child must point back to its parent and be reachable through exactly one reference. The latter keeps the traversal linear, since a node listed more than once would otherwise be walked once per reference (exponential for nested repeats).
Args:
root: The node whose subtree is validated.
raise_on_error: Raise a ValueError instead of returning False.
_visited: Internal. Refs of the nodes already reached in this traversal.
Returns: True if the subtree is a valid tree, False otherwise.
Raises:
ValueError: If the subtree is invalid and raise_on_error is set.
DocumentOrigin
Bases: BaseModel
FileSource.
Methods:
-
parse_hex_string–parse_hex_string.
-
validate_mimetype–validate_mimetype.
Attributes:
-
binary_hash(Uint64) – -
filename(str) – -
mimetype(str) – -
uri(AnyUrl | None) –
binary_hash
binary_hash: Uint64
filename
filename: str
mimetype
mimetype: str
uri
uri: AnyUrl | None = None
parse_hex_string
parse_hex_string(value)
parse_hex_string.
validate_mimetype
validate_mimetype(v)
validate_mimetype.
DocItem
Bases: NodeItem
Base type for any element that carries content, can be a leaf node.
Methods:
-
get_annotations–Get the annotations of this DocItem.
-
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]) – -
comments(list[FineRef]) – -
content_layer(ContentLayer) – -
label(DocItemLabel) – -
meta(BaseMeta | None) – -
model_config– -
parent(RefItem | None) – -
prov(list[ProvenanceItem]) – -
self_ref(str) – -
source(Annotated[list[SourceType], Field(description='The provenance of this document item. Currently, it is only used for media track provenance.')]) –
comments
comments: list[FineRef] = []
content_layer
content_layer: ContentLayer = ContentLayer.BODY
meta
meta: BaseMeta | None = None
model_config
model_config = ConfigDict(extra='forbid')
self_ref
self_ref: str = Field(pattern=_JSON_POINTER_REGEX)
source
source: Annotated[
list[SourceType],
Field(
description="The provenance of this document item. Currently, it is only used for media track provenance."
),
] = []
get_annotations
get_annotations() -> Sequence[BaseAnnotation]
Get the annotations of this DocItem.
get_image
get_image(
doc: DoclingDocument, prov_index: int = 0
) -> Image | None
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,
self_closing: bool = False,
) -> 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– -
EMPTY_VALUE– -
FIELD_HEADING– -
FIELD_HINT– -
FIELD_ITEM– -
FIELD_KEY– -
FIELD_REGION– -
FIELD_VALUE– -
FOOTNOTE– -
FORM– -
FORMULA– -
GRADING_SCALE– -
HANDWRITTEN_TEXT– -
KEY_VALUE_REGION– -
LIST_ITEM– -
MARKER– -
PAGE_FOOTER– -
PAGE_HEADER– -
PARAGRAPH– -
PICTURE– -
REFERENCE– -
SECTION_HEADER– -
TABLE– -
TEXT– -
TITLE– -
TRACK–
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'
EMPTY_VALUE
EMPTY_VALUE = 'empty_value'
FIELD_HEADING
FIELD_HEADING = 'field_heading'
FIELD_HINT
FIELD_HINT = 'field_hint'
FIELD_ITEM
FIELD_ITEM = 'field_item'
FIELD_KEY
FIELD_KEY = 'field_key'
FIELD_REGION
FIELD_REGION = 'field_region'
FIELD_VALUE
FIELD_VALUE = 'field_value'
FOOTNOTE
FOOTNOTE = 'footnote'
FORM
FORM = 'form'
FORMULA
FORMULA = 'formula'
GRADING_SCALE
GRADING_SCALE = 'grading_scale'
HANDWRITTEN_TEXT
HANDWRITTEN_TEXT = 'handwritten_text'
KEY_VALUE_REGION
KEY_VALUE_REGION = 'key_value_region'
LIST_ITEM
LIST_ITEM = 'list_item'
MARKER
MARKER = 'marker'
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'
TRACK
TRACK = 'track'
get_color
get_color(label: DocItemLabel) -> tuple[int, int, int]
Return the RGB color associated with a given label.
ProvenanceItem
Bases: BaseModel
Provenance information for elements extracted from a textual document.
A ProvenanceItem object acts as a lightweight pointer back into the original
document for an extracted element. It applies to documents with an explicit
or implicit layout, such as PDF, HTML, docx, or pptx.
Attributes:
-
bbox(Annotated[BoundingBox, Field(description='Bounding box')]) – -
charspan(CharSpan) – -
page_no(Annotated[int, Field(description='Page number')]) –
charspan
charspan: CharSpan
page_no
page_no: Annotated[int, Field(description='Page number')]
GroupItem
Bases: NodeItem
GroupItem.
Methods:
-
get_ref–get_ref.
Attributes:
-
children(list[RefItem]) – -
content_layer(ContentLayer) – -
label(GroupLabel) – -
meta(BaseMeta | None) – -
model_config– -
name(str) – -
parent(RefItem | None) – -
self_ref(str) –
content_layer
content_layer: ContentLayer = ContentLayer.BODY
meta
meta: BaseMeta | None = None
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) – -
meta(BaseMeta | None) – -
model_config– -
parent(RefItem | None) – -
self_ref(str) –
content_layer
content_layer: ContentLayer = ContentLayer.BODY
meta
meta: BaseMeta | None = None
model_config
model_config = ConfigDict(extra='forbid')
self_ref
self_ref: str = Field(pattern=_JSON_POINTER_REGEX)
PageItem
FloatingItem
Bases: DocItem
FloatingItem.
Methods:
-
caption_text–Computes the caption as a single text.
-
get_annotations–Get the annotations of this DocItem.
-
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]) – -
comments(list[FineRef]) – -
content_layer(ContentLayer) – -
footnotes(list[RefItem]) – -
image(ImageRef | None) – -
label(DocItemLabel) – -
meta(FloatingMeta | None) – -
model_config– -
parent(RefItem | None) – -
prov(list[ProvenanceItem]) – -
references(list[RefItem]) – -
self_ref(str) – -
source(Annotated[list[SourceType], Field(description='The provenance of this document item. Currently, it is only used for media track provenance.')]) –
comments
comments: list[FineRef] = []
content_layer
content_layer: ContentLayer = ContentLayer.BODY
meta
meta: FloatingMeta | None = None
model_config
model_config = ConfigDict(extra='forbid')
self_ref
self_ref: str = Field(pattern=_JSON_POINTER_REGEX)
source
source: Annotated[
list[SourceType],
Field(
description="The provenance of this document item. Currently, it is only used for media track provenance."
),
] = []
get_annotations
get_annotations() -> Sequence[BaseAnnotation]
Get the annotations of this DocItem.
get_image
get_image(
doc: DoclingDocument, prov_index: int = 0
) -> Image | None
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,
self_closing: bool = False,
) -> 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_annotations–Get the annotations of this DocItem.
-
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]) – -
comments(list[FineRef]) – -
content_layer(ContentLayer) – -
formatting(Formatting | None) – -
hyperlink(AnyUrl | Path | None) – -
label(Literal[CAPTION, CHECKBOX_SELECTED, CHECKBOX_UNSELECTED, FOOTNOTE, PAGE_FOOTER, PAGE_HEADER, PARAGRAPH, REFERENCE, TEXT, EMPTY_VALUE, FIELD_KEY, FIELD_HINT, MARKER, HANDWRITTEN_TEXT]) – -
meta(BaseMeta | None) – -
model_config– -
orig(str) – -
parent(RefItem | None) – -
prov(list[ProvenanceItem]) – -
self_ref(str) – -
source(Annotated[list[SourceType], Field(description='The provenance of this document item. Currently, it is only used for media track provenance.')]) – -
text(str) –
comments
comments: list[FineRef] = []
content_layer
content_layer: ContentLayer = ContentLayer.BODY
formatting
formatting: Formatting | None = None
hyperlink
hyperlink: AnyUrl | Path | None = Field(
union_mode="left_to_right", default=None
)
label
label: Literal[
CAPTION,
CHECKBOX_SELECTED,
CHECKBOX_UNSELECTED,
FOOTNOTE,
PAGE_FOOTER,
PAGE_HEADER,
PARAGRAPH,
REFERENCE,
TEXT,
EMPTY_VALUE,
FIELD_KEY,
FIELD_HINT,
MARKER,
HANDWRITTEN_TEXT,
]
meta
meta: BaseMeta | None = None
model_config
model_config = ConfigDict(extra='forbid')
orig
orig: str
self_ref
self_ref: str = Field(pattern=_JSON_POINTER_REGEX)
source
source: Annotated[
list[SourceType],
Field(
description="The provenance of this document item. Currently, it is only used for media track provenance."
),
] = []
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_annotations
get_annotations() -> Sequence[BaseAnnotation]
Get the annotations of this DocItem.
get_image
get_image(
doc: DoclingDocument, prov_index: int = 0
) -> Image | None
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,
self_closing: bool = False,
) -> str
Get the location string for the BaseCell.
TableItem
Bases: FloatingItem
TableItem.
Methods:
-
add_annotation–Add an annotation to the table.
-
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_annotations–Get the annotations of this TableItem.
-
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(Annotated[list[TableAnnotationType], deprecated('Field `annotations` is deprecated; use `meta` instead.')]) – -
captions(list[RefItem]) – -
children(list[RefItem]) – -
comments(list[FineRef]) – -
content_layer(ContentLayer) – -
data(TableData) – -
footnotes(list[RefItem]) – -
image(ImageRef | None) – -
label(Literal[DOCUMENT_INDEX, TABLE]) – -
meta(FloatingMeta | None) – -
model_config– -
parent(RefItem | None) – -
prov(list[ProvenanceItem]) – -
references(list[RefItem]) – -
self_ref(str) – -
source(Annotated[list[SourceType], Field(description='The provenance of this document item. Currently, it is only used for media track provenance.')]) –
annotations
annotations: Annotated[
list[TableAnnotationType],
deprecated(
"Field `annotations` is deprecated; use `meta` instead."
),
] = []
comments
comments: list[FineRef] = []
content_layer
content_layer: ContentLayer = ContentLayer.BODY
meta
meta: FloatingMeta | None = None
model_config
model_config = ConfigDict(extra='forbid')
self_ref
self_ref: str = Field(pattern=_JSON_POINTER_REGEX)
source
source: Annotated[
list[SourceType],
Field(
description="The provenance of this document item. Currently, it is only used for media track provenance."
),
] = []
add_annotation
add_annotation(annotation: TableAnnotationType) -> None
Add an annotation to the table.
export_to_dataframe
export_to_dataframe(
doc: Optional[DoclingDocument] = None,
) -> 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,
self_closing: bool = False,
**kwargs: Any,
) -> str
Export the table as OTSL.
get_annotations
get_annotations() -> Sequence[BaseAnnotation]
Get the annotations of this TableItem.
get_image
get_image(
doc: DoclingDocument, prov_index: int = 0
) -> Image | None
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,
self_closing: bool = False,
) -> str
Get the location string for the BaseCell.
TableCell
Bases: BaseModel
A cell of a table, positioned in the table grid by row and column offsets.
The offset ranges are half-open: a cell covers the rows from start_row_offset_idx
up to, but not including, end_row_offset_idx, and likewise for columns.
Methods:
-
check_offset_ranges–Check that the row and column offset ranges are not inverted.
-
from_dict_format–Derive the cell text from the bounding box token when no
textis given.
Attributes:
-
bbox(Annotated[BoundingBox | None, Field(description='Bounding box of the cell on the page.')]) – -
col_span(Annotated[int, Field(description='Number of columns spanned by the cell.')]) – -
column_header(Annotated[bool, Field(description='Whether the cell is part of a column header.')]) – -
end_col_offset_idx(Annotated[int, Field(ge=0, description='Index of the last column covered by the cell (exclusive, 0-based).')]) – -
end_row_offset_idx(Annotated[int, Field(ge=0, description='Index of the last row covered by the cell (exclusive, 0-based).')]) – -
fillable(Annotated[bool, Field(description='Whether the cell is meant to be filled in, as in a form.')]) – -
row_header(Annotated[bool, Field(description='Whether the cell is part of a row header.')]) – -
row_section(Annotated[bool, Field(description='Whether the cell is a row section title.')]) – -
row_span(Annotated[int, Field(description='Number of rows spanned by the cell.')]) – -
start_col_offset_idx(Annotated[int, Field(ge=0, description='Index of the first column covered by the cell (inclusive, 0-based).')]) – -
start_row_offset_idx(Annotated[int, Field(ge=0, description='Index of the first row covered by the cell (inclusive, 0-based).')]) – -
text(Annotated[str, Field(description='Text content of the cell.')]) –
bbox
bbox: Annotated[
BoundingBox | None,
Field(
description="Bounding box of the cell on the page."
),
] = None
col_span
col_span: Annotated[
int,
Field(
description="Number of columns spanned by the cell."
),
] = 1
column_header
column_header: Annotated[
bool,
Field(
description="Whether the cell is part of a column header."
),
] = False
end_col_offset_idx
end_col_offset_idx: Annotated[
int,
Field(
ge=0,
description="Index of the last column covered by the cell (exclusive, 0-based).",
),
]
end_row_offset_idx
end_row_offset_idx: Annotated[
int,
Field(
ge=0,
description="Index of the last row covered by the cell (exclusive, 0-based).",
),
]
fillable
fillable: Annotated[
bool,
Field(
description="Whether the cell is meant to be filled in, as in a form."
),
] = False
row_header
row_header: Annotated[
bool,
Field(
description="Whether the cell is part of a row header."
),
] = False
row_section
row_section: Annotated[
bool,
Field(
description="Whether the cell is a row section title."
),
] = False
row_span
row_span: Annotated[
int,
Field(
description="Number of rows spanned by the cell."
),
] = 1
start_col_offset_idx
start_col_offset_idx: Annotated[
int,
Field(
ge=0,
description="Index of the first column covered by the cell (inclusive, 0-based).",
),
]
start_row_offset_idx
start_row_offset_idx: Annotated[
int,
Field(
ge=0,
description="Index of the first row covered by the cell (inclusive, 0-based).",
),
]
text
text: Annotated[
str, Field(description="Text content of the cell.")
]
check_offset_ranges
check_offset_ranges() -> Self
Check that the row and column offset ranges are not inverted.
Returns: The validated cell.
Raises: ValueError: If an end offset is smaller than its start offset.
from_dict_format
from_dict_format(data: Any) -> Any
Derive the cell text from the bounding box token when no text is given.
Supports cells produced by docling-ibm-models, where the text is carried by the
bbox token or by the text_cell_bboxes tokens.
Args: data: The raw input data of the cell.
Returns:
The input data, with the text key set when it was derived.
TableData
Bases: BaseModel
BaseTableData.
Methods:
-
add_row–Add a new row to the table from a list of strings.
-
add_rows–Add multiple new rows to the table from a list of lists of strings.
-
from_regions–Converts regions: rows, columns, merged cells into table_data structure.
-
get_column_bounding_boxes–Get the bounding box for each column in the table.
-
get_row_bounding_boxes–Get the bounding box for each row in the table.
-
insert_row–Insert a new row from a list of strings before/after a specific index in the table.
-
insert_rows–Insert multiple new rows from a list of lists of strings before/after a specific index in the table.
-
pop_row–Remove and return the last row from the table.
-
remove_row–Remove a row from the table by its index.
-
remove_rows–Remove rows from the table by their indices.
Attributes:
-
grid(list[list[TableCell]]) –Dense
num_rowsxnum_colsmatrix of the table cells. -
num_cols(int) – -
num_rows(int) – -
orientation(Orientation) – -
table_cells(list[AnyTableCell]) –
grid
grid: list[list[TableCell]]
Dense num_rows x num_cols matrix of the table cells.
A cell that spans several rows or columns is repeated at every position it
covers. When cells overlap, the one that appears last in table_cells
wins. Positions not covered by any cell hold new, empty cells.
Returns: The cell matrix, one list per row.
num_cols
num_cols: int = 0
num_rows
num_rows: int = 0
orientation
orientation: Orientation = Orientation.ROT_0
table_cells
table_cells: list[AnyTableCell] = []
add_row
add_row(row: list[str]) -> None
Add a new row to the table from a list of strings.
Parameters:
-
row(list[str]) –list[str]: A list of strings representing the content of the new row.
Returns:
-
None–None
add_rows
add_rows(rows: list[list[str]]) -> None
Add multiple new rows to the table from a list of lists of strings.
Parameters:
-
rows(list[list[str]]) –list[list[str]]: A list of lists, where each inner list represents the content of a new row.
Returns:
-
None–None
from_regions
from_regions(
table_bbox: BoundingBox,
rows: list[BoundingBox],
cols: list[BoundingBox],
merges: list[BoundingBox],
row_headers: list[BoundingBox] = [],
col_headers: list[BoundingBox] = [],
row_sections: list[BoundingBox] = [],
) -> Self
Converts regions: rows, columns, merged cells into table_data structure.
Adds semantics for regions of row_headers, col_headers, row_section
get_column_bounding_boxes
get_column_bounding_boxes(
*, minimal: bool = True
) -> dict[int, BoundingBox]
Get the bounding box for each column in the table.
Layout follows the table's orientation field: ROT_0 / ROT_180
keep columns running top-to-bottom on the page; ROT_90 / ROT_270
turn columns into horizontal stripes. This affects both the axis along
which span cells extend a column's bbox and, when minimal=False, the
axis equalized across columns.
Args: minimal: If True (default), returns the minimal bounding box for each column based on its cells. If False, all columns will have a uniform extent perpendicular to the column direction (t/b for ROT_0/ROT_180, l/r for ROT_90/ROT_270).
Returns: dict[int, BoundingBox]: A dictionary mapping column indices to their bounding boxes. Only columns with cells that have bounding boxes are included.
get_row_bounding_boxes
get_row_bounding_boxes(
*, minimal: bool = True
) -> dict[int, BoundingBox]
Get the bounding box for each row in the table.
Layout follows the table's orientation field: ROT_0 / ROT_180
keep rows running left-to-right on the page; ROT_90 / ROT_270
turn rows into vertical stripes. This affects both the axis along which
span cells extend a row's bbox and, when minimal=False, the axis
equalized across rows.
Args: minimal: If True (default), returns the minimal bounding box for each row based on its cells. If False, all rows will have a uniform extent perpendicular to the row direction (l/r for ROT_0/ROT_180, t/b for ROT_90/ROT_270).
Returns: dict[int, BoundingBox]: A dictionary mapping row indices to their bounding boxes. Only rows with cells that have bounding boxes are included.
insert_row
insert_row(
row_index: int, row: list[str], after: bool = False
) -> None
Insert a new row from a list of strings before/after a specific index in the table.
Parameters:
-
row_index(int) –int: The index at which to insert the new row. (Starting from 0)
-
row(list[str]) –list[str]: A list of strings representing the content of the new row.
-
after(bool, default:False) –bool: If True, insert the row after the specified index, otherwise before it. (Default is False)
Returns:
-
None–None
insert_rows
insert_rows(
row_index: int,
rows: list[list[str]],
after: bool = False,
) -> None
Insert multiple new rows from a list of lists of strings before/after a specific index in the table.
Parameters:
-
row_index(int) –int: The index at which to insert the new rows. (Starting from 0)
-
rows(list[list[str]]) –list[list[str]]: A list of lists, where each inner list represents the content of a new row.
-
after(bool, default:False) –bool: If True, insert the rows after the specified index, otherwise before it. (Default is False)
Returns:
-
None–None
pop_row
pop_row(
doc: Optional[DoclingDocument] = None,
) -> list[TableCell]
Remove and return the last row from the table.
Returns:
-
list[TableCell]–list[TableCell]: A list of TableCell objects representing the popped row.
remove_row
remove_row(
row_index: int, doc: Optional[DoclingDocument] = None
) -> list[TableCell]
Remove a row from the table by its index.
Parameters:
-
row_index(int) –int: The index of the row to remove. (Starting from 0)
Returns:
-
list[TableCell]–list[TableCell]: A list of TableCell objects representing the removed row.
remove_rows
remove_rows(
indices: list[int],
doc: Optional[DoclingDocument] = None,
) -> list[list[TableCell]]
Remove rows from the table by their indices.
Args: indices: Zero-based indices of the rows to remove. Duplicate indices are ignored. doc: The document that owns the table. Required to also delete the content of rich cells in the removed rows; otherwise that content is left dangling and a warning is logged.
Returns: The removed rows, each as a list of cells, ordered by descending row index.
Raises: IndexError: If any index is negative or not smaller than the number of rows.
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_annotations–Get the annotations of this DocItem.
-
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]) – -
comments(list[FineRef]) – -
content_layer(ContentLayer) – -
footnotes(list[RefItem]) – -
graph(GraphData) – -
image(ImageRef | None) – -
label(Literal[KEY_VALUE_REGION]) – -
meta(FloatingMeta | None) – -
model_config– -
parent(RefItem | None) – -
prov(list[ProvenanceItem]) – -
references(list[RefItem]) – -
self_ref(str) – -
source(Annotated[list[SourceType], Field(description='The provenance of this document item. Currently, it is only used for media track provenance.')]) –
comments
comments: list[FineRef] = []
content_layer
content_layer: ContentLayer = ContentLayer.BODY
graph
graph: GraphData
meta
meta: FloatingMeta | None = None
model_config
model_config = ConfigDict(extra='forbid')
self_ref
self_ref: str = Field(pattern=_JSON_POINTER_REGEX)
source
source: Annotated[
list[SourceType],
Field(
description="The provenance of this document item. Currently, it is only used for media track provenance."
),
] = []
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_annotations
get_annotations() -> Sequence[BaseAnnotation]
Get the annotations of this DocItem.
get_image
get_image(
doc: DoclingDocument, prov_index: int = 0
) -> Image | None
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,
self_closing: bool = False,
) -> 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_annotations–Get the annotations of this DocItem.
-
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]) – -
comments(list[FineRef]) – -
content_layer(ContentLayer) – -
formatting(Formatting | None) – -
hyperlink(AnyUrl | Path | None) – -
label(Literal[SECTION_HEADER]) – -
level(LevelNumber) – -
meta(BaseMeta | None) – -
model_config– -
orig(str) – -
parent(RefItem | None) – -
prov(list[ProvenanceItem]) – -
self_ref(str) – -
source(Annotated[list[SourceType], Field(description='The provenance of this document item. Currently, it is only used for media track provenance.')]) – -
text(str) –
comments
comments: list[FineRef] = []
content_layer
content_layer: ContentLayer = ContentLayer.BODY
formatting
formatting: Formatting | None = None
hyperlink
hyperlink: AnyUrl | Path | None = Field(
union_mode="left_to_right", default=None
)
level
level: LevelNumber = 1
meta
meta: BaseMeta | None = None
model_config
model_config = ConfigDict(extra='forbid')
orig
orig: str
self_ref
self_ref: str = Field(pattern=_JSON_POINTER_REGEX)
source
source: Annotated[
list[SourceType],
Field(
description="The provenance of this document item. Currently, it is only used for media track provenance."
),
] = []
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_annotations
get_annotations() -> Sequence[BaseAnnotation]
Get the annotations of this DocItem.
get_image
get_image(
doc: DoclingDocument, prov_index: int = 0
) -> Image | None
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,
self_closing: bool = False,
) -> 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_annotations–Get the annotations of this PictureItem.
-
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(Annotated[list[PictureDataType], deprecated('Field `annotations` is deprecated; use `meta` instead.')]) – -
captions(list[RefItem]) – -
children(list[RefItem]) – -
comments(list[FineRef]) – -
content_layer(ContentLayer) – -
footnotes(list[RefItem]) – -
image(ImageRef | None) – -
label(Literal[PICTURE, CHART]) – -
meta(PictureMeta | None) – -
model_config– -
parent(RefItem | None) – -
prov(list[ProvenanceItem]) – -
references(list[RefItem]) – -
self_ref(str) – -
source(Annotated[list[SourceType], Field(description='The provenance of this document item. Currently, it is only used for media track provenance.')]) –
annotations
annotations: Annotated[
list[PictureDataType],
deprecated(
"Field `annotations` is deprecated; use `meta` instead."
),
] = []
comments
comments: list[FineRef] = []
content_layer
content_layer: ContentLayer = ContentLayer.BODY
meta
meta: PictureMeta | None = None
model_config
model_config = ConfigDict(extra='forbid')
self_ref
self_ref: str = Field(pattern=_JSON_POINTER_REGEX)
source
source: Annotated[
list[SourceType],
Field(
description="The provenance of this document item. Currently, it is only used for media track provenance."
),
] = []
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_annotations
get_annotations() -> Sequence[BaseAnnotation]
Get the annotations of this PictureItem.
get_image
get_image(
doc: DoclingDocument, prov_index: int = 0
) -> Image | None
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,
self_closing: bool = False,
) -> 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(Image | None) –Return the PIL Image.
-
size(Size) – -
uri(AnyUrl | Path) –
dpi
dpi: int
mimetype
mimetype: str
pil_image
pil_image: Image | None
Return the PIL Image.
uri
uri: 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: BaseAnnotation
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.
-
get_intersection_bbox–Return the intersection bounding box with another bounding box or
Nonewhen disjoint. -
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:
get_intersection_bbox
get_intersection_bbox(
other: BoundingBox,
) -> Optional[BoundingBox]
Return the intersection bounding box with another bounding box or None when disjoint.
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'