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, sections and json_content (lists of dicts or None). tables and sections list the tables and headings of json_content (The result: ProcessedDocument); they are None for 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 when None.

Returns:

List of Chunk objects.

property markdown: str

Get content as markdown.

property text: str

Get content as plain text.

to_dict()[source]

Return a JSON-serializable representation of the processed document.

Return type:

Dict[str, Any]

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

page_count

PDF (pages), Word (pages counted from page and section breaks), PowerPoint (slides), Excel (sheets), image files (1), legacy files.

word_count

PDF, Word, text, Markdown, HTML, image files (OCR text).

title

HTML (<title>).

slide_count

PowerPoint (the number of slides, also for a deck read through the Office image route).

sheet_names, total_cells

Excel: every sheet in workbook order, and the number of cells that show a value (all sheets).

line_count

Text and Markdown files.

header_count, frontmatter

Markdown (frontmatter needs PyYAML).

link_count, image_count

HTML and Markdown; image_count also Word/PowerPoint/Excel (pictures kept as base64) and image files (1).

encoding

Text, CSV, JSON, JSONL, HTML, XML and Markdown files: the encoding argument (not detected).

delimiter, row_count, column_count

CSV and TSV (row_count includes the header row).

record_count

JSONL.

data_type, item_count

JSON (data_type is the Python type name: dict, list, …).

element_count, root_tag

XML.

language, creation_date, modification_date, author

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'
class doc2mark.OutputFormat(*values)[source]

Supported output formats.

JSON = 'json'
MARKDOWN = 'markdown'
TEXT = 'text'
class doc2mark.TableStyle(*values)

Table output style options for complex tables with merged cells.

MARKDOWN_GRID = 'markdown_grid'
MINIMAL_HTML = 'minimal_html'
STYLED_HTML = 'styled_html'
classmethod default()

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__))
exception doc2mark.ProcessingError[source]

Base exception for document processing errors.

exception doc2mark.UnsupportedFormatError[source]

Raised when attempting to process an unsupported format.

exception doc2mark.OCRError[source]

Raised when OCR processing fails.

exception doc2mark.ConversionError[source]

Raised when document conversion fails.