Results, enums and exceptions
Guide: The result: ProcessedDocument.
ProcessedDocument
- class doc2mark.ProcessedDocument(content, metadata, images=None, tables=None, sections=None, json_content=None)[source]
Container for processed document data.
Fields:
content(str),metadata(DocumentMetadata),images,tables,sectionsandjson_content(lists of dicts orNone).tablesandsectionslist the tables and headings ofjson_content(The result: ProcessedDocument); they areNonefor files without content items (text, data, markup and e-mail files).- Parameters:
content (str)
metadata (DocumentMetadata)
images (List[Dict[str, Any]] | None)
tables (List[Dict[str, Any]] | None)
sections (List[Dict[str, Any]] | None)
json_content (List[Dict[str, Any]] | None)
- get_chunks(config=None)[source]
Split document into section-aware chunks for RAG.
- Parameters:
config – Optional
ChunkingConfig. Uses defaults whenNone.- Returns:
List of
Chunkobjects.
- property markdown: str
Get content as markdown.
- property text: str
Get content as plain text.
DocumentMetadata
- class doc2mark.DocumentMetadata(filename, format, size_bytes, page_count=None, word_count=None, language=None, creation_date=None, modification_date=None, author=None, title=None, sheet_names=None, slide_count=None, line_count=None, header_count=None, link_count=None, image_count=None, total_cells=None, encoding=None, delimiter=None, record_count=None, row_count=None, column_count=None, element_count=None, root_tag=None, frontmatter=None, data_type=None, item_count=None, extra=<factory>)[source]
Metadata for a processed document.
- Parameters:
filename (str)
format (DocumentFormat)
size_bytes (int)
page_count (int | None)
word_count (int | None)
language (str | None)
creation_date (str | None)
modification_date (str | None)
author (str | None)
title (str | None)
sheet_names (List[str] | None)
slide_count (int | None)
line_count (int | None)
header_count (int | None)
link_count (int | None)
image_count (int | None)
total_cells (int | None)
encoding (str | None)
delimiter (str | None)
record_count (int | None)
row_count (int | None)
column_count (int | None)
element_count (int | None)
root_tag (str | None)
frontmatter (Dict[str, Any] | None)
data_type (str | None)
item_count (int | None)
extra (Dict[str, Any])
filename, format (a DocumentFormat) and size_bytes are always set;
extra is a dict ({} by default) of conversion reports (The result: ProcessedDocument). The other fields
are None unless the format sets them:
Field |
Set by |
|---|---|
|
PDF (pages), Word (pages counted from page and section breaks), PowerPoint (slides), Excel (sheets), image files (1), legacy files. |
|
PDF, Word, text, Markdown, HTML, image files (OCR text). |
|
HTML ( |
|
PowerPoint (the number of slides, also for a deck read through the Office image route). |
|
Excel: every sheet in workbook order, and the number of cells that show a value (all sheets). |
|
Text and Markdown files. |
|
Markdown ( |
|
HTML and Markdown; |
|
Text, CSV, JSON, JSONL, HTML, XML and Markdown files: the |
|
CSV and TSV ( |
|
JSONL. |
|
JSON ( |
|
XML. |
|
Not set by the default processors. |
Enums
- class doc2mark.DocumentFormat(*values)[source]
Supported document formats.
- AVIF = 'avif'
- BMP = 'bmp'
- CSV = 'csv'
- DOC = 'doc'
- DOCX = 'docx'
- EML = 'eml'
- GIF = 'gif'
- HEIC = 'heic'
- HEIF = 'heif'
- HTML = 'html'
- JPEG = 'jpeg'
- JPG = 'jpg'
- JSON = 'json'
- JSONL = 'jsonl'
- MARKDOWN = 'md'
- PDF = 'pdf'
- PNG = 'png'
- PPS = 'pps'
- PPT = 'ppt'
- PPTX = 'pptx'
- RTF = 'rtf'
- TIF = 'tif'
- TIFF = 'tiff'
- TSV = 'tsv'
- TXT = 'txt'
- WEBP = 'webp'
- XLS = 'xls'
- XLSX = 'xlsx'
- XML = 'xml'
Exceptions
ProcessingError is the base class of the library’s own exceptions.
load() raises UnsupportedFormatError
for an unknown extension and wraps every failure during conversion in a ProcessingError
whose __cause__ chain leads to the original error (for example OCREngineError, a
subclass of OCRError, or ConversionError). A missing file
raises
FileNotFoundError and an unknown output_format raises ValueError.
from doc2mark import ProcessingError, UnsupportedFormatError, load
for name in ["archive.7z", "legacy.doc", "report.pdf"]:
try:
result = load(name)
print(name, "ok", len(result.content))
except UnsupportedFormatError as exc:
print(name, "unsupported:", exc)
except ProcessingError as exc:
print(name, "failed:", exc, "| cause:", repr(exc.__cause__))