ParseResult
Returned by every parse function. Holds the chunks, blocks, tables, charts, metadata, and document hierarchy extracted from a document, plus methods for exporting and navigating the content.
result = docslicer.parse_document("report.pdf")
result.chunks # list[Chunk]
result.blocks # list[Block]
result.tables # list[Table]
result.charts # list[Chart]
result.metadata # DocumentMetadata
result.hierarchy # HierarchyTreeAttributes
| Attribute | Type | Description |
|---|---|---|
chunks | list[Chunk] | Semantically coherent text segments sized for embedding. The primary output for RAG pipelines. |
blocks | list[Block] | Raw structural units extracted from the document (paragraphs, headings, tables, …). More granular than chunks. |
tables | list[Table] | All detected tables with their cells and a pre-rendered markdown string. |
charts | list[Chart] | All embedded charts with their series and datapoints, plus a pre-rendered markdown table. Populated for DOCX and PPTX only — empty for other formats. See Chart. |
metadata | DocumentMetadata | Document-level metadata — title, author, language, page count, file size, and more. See Metadata below. |
hierarchy | HierarchyTree | Heading tree extracted from the document. See Navigation. |
pipeline_steps | dict[str, DataFrame] | Intermediate DataFrames from each pipeline stage. Populated only when debug=True. |
Metadata
result.metadata is a DocumentMetadata object holding document-level fields — title, author, language, page count, file size, OCR flags, and more.
print(result.metadata.title)
print(result.metadata.page_count)
print(result.metadata.processing_time)See DocumentMetadata for the full field list.
Text export
result.text
Property. Plain text of the document body, excluding headers, footers, and TOC. Equivalent to calling export_to_text() with default arguments.
print(result.text)export_to_markdown()
Render the document as Markdown using blocks as the source of truth. Headings become # prefixed by their detected level. Tables are rendered as aligned Markdown tables, and charts inline as whichever chart representation the parse used.
md = result.export_to_markdown(
include_page_markers=True, # <!-- page 4 --> comments between pages
include_tables=True,
include_toc=True,
include_furniture=True, # headers, footers, navigation elements
prettify=True, # align table columns
)export_to_text()
Render the document as plain text with no Markdown formatting. TOC is excluded by default.
text = result.export_to_text(
include_tables=True,
include_toc=False,
include_furniture=True,
)export_toc()
Return the document's table of contents as a Markdown string. Returns an empty string if no TOC was detected.
print(result.export_toc())export_toc() is not the same as result.hierarchy. The TOC is the literal table of contents printed in the document — it only exists if the author included one, and it typically only covers high-level sections (e.g. "Article I", "Chapter 3"). A legal agreement's TOC might list a dozen entries while the document itself has hundreds of subsections that never appear in it.
result.hierarchy is the navigable outline DocSlicer builds itself by detecting every heading in the document. It will always be available regardless of whether the document has a printed TOC, and it is generally far more detailed — especially in long documents. Use result.hierarchy for programmatic navigation; use export_toc() only if you specifically want to reproduce what the original author considered the top-level structure.
Save
save(path)
Flexible save method. Behaviour depends on whether path is a directory or a file:
# Directory: saves chunks, blocks, tables as Parquet + metadata.json
# (charts.parquet is written too when the document has charts)
result.save("output/")
# Specific file — stem determines the data level, suffix the format
result.save("output/result.json") # full document export as JSON
result.save("output/chunks.csv") # chunks as CSV
result.save("output/chunks.parquet") # chunks as Parquet
result.save("output/chunks.jsonl") # chunks as JSONL
result.save("output/charts.parquet") # charts as Parquet
result.save("output/metadata.json") # metadata onlySupported stems: chunks, blocks, tables, charts, metadata. Any other stem with .json produces a full document export. Supported formats: .json, .jsonl, .csv, .parquet.
save_debug(path)
Save intermediate pipeline DataFrames as CSV files to a directory. Requires debug=True on the original parse call.
result = docslicer.parse_document("report.pdf", debug=True)
result.save_debug("debug_output/")Chunk export
# In-memory JSONL string (no file I/O)
jsonl = result.chunks_to_jsonl()
# Files
result.export_chunks_csv("chunks.csv")
result.export_chunks_csv("chunks.csv", encoding="utf-8-sig") # Excel-friendly
result.export_chunks_jsonl("chunks.jsonl")
result.export_chunks_parquet("chunks.parquet") # falls back to CSV if pyarrow not installedTable export
result.export_tables_csv("tables.csv")
result.export_tables_csv("tables.csv", encoding="utf-8-sig") # Excel-friendlyEach table is written with a header row (table id + page), an optional caption row, and the cell grid with rowspan/colspan expanded.
Chart export
result.export_charts_csv("charts.csv")
result.export_charts_csv("charts.csv", encoding="utf-8-sig") # Excel-friendlyOne flat CSV with a row per datapoint — every ChartPoint field, with chart_id, chart_type, title, page_number, and page_label repeated onto each row. Same shape as charts_df().
DataFrames
df_chunks = result.chunks_df() # one row per chunk
df_blocks = result.blocks_df() # one row per block
df_tables = result.tables_df() # one row per table
df_charts = result.charts_df() # one row per chart datapointcharts_df() flattens across charts — chart-level metadata is repeated onto every point, so grouping by chart_id gets you back to a single chart:
df_charts.groupby("chart_id")["value"].sum()Navigation
Navigate content by heading or page without iterating manually.
By heading
# Find headings by text (case-insensitive by default)
nodes = result.find_heading("risk factors")
# Get all chunks / blocks / tables / charts under a heading
node = nodes[0]
chunks = result.chunks_under(node) # recursive by default
blocks = result.blocks_under(node)
tables = result.tables_under(node)
charts = result.charts_under(node)
# Shallow — only direct section, not subsections
chunks = result.chunks_under(node, recursive=False)Every *_under() method takes either a HierarchyNode or a bare heading_id int, so you can hold onto an id instead of the node:
result.chunks_under(node.heading_id)An unknown heading returns an empty list rather than raising.
How each one resolves:
| Method | Resolution |
|---|---|
chunks_under() | Collects chunk_ids from the node, plus descendants when recursive=True. |
blocks_under() | Uses the node's block_ids when present (exact). Falls back to a page-and-section range derived from the section's chunks when they're absent. |
tables_under() | Unions table_ids across the section's chunks; falls back to the blocks' table_ids when chunking was disabled. |
charts_under() | Same, over chart_ids. |
By page
# By page number (int) — slide number for PPTX
chunks = result.chunks_by_page(4)
blocks = result.blocks_by_page(4)
tables = result.tables_by_page(4)
charts = result.charts_by_page(4)
# By page label (str) — for labelled pages like "A-6" or "iv"
chunks = result.chunks_by_page("A-6")For hierarchy traversal methods (level(), flatten(), find_heading()) see HierarchyTree.
Serialisation
# JSON string
json_str = result.to_json()
json_str = result.to_json(indent=0)
# Dict
d = result.to_dict()
d = result.export_to_dict() # alias for to_dict()
# Reconstruct from dict or JSON file
result2 = ParseResult.from_dict(d)
result3 = ParseResult.load("output/result.json")to_dict()
Full round-trippable export of the result. Keys:
| Key | Contents |
|---|---|
schema | Always "DocSlicerResult" — lets you recognise the payload. |
version | The DocSlicer version that produced it. |
metadata | DocumentMetadata as a dict. |
chunks / blocks / tables / charts | Lists of dicts, one per element. |
hierarchy | The heading tree as nested dicts. |
export_to_dict() is an alias for the same thing.
pipeline_steps is not serialised — it holds live DataFrames and only exists on results parsed with debug=True. Use save_debug() to write those to disk instead.
to_json(indent=2)
The same payload as a JSON string, with non-ASCII characters preserved rather than escaped. Pass indent to control formatting.
ParseResult.from_dict(d)
Classmethod. Rebuilds a ParseResult from a to_dict() payload — chunks, blocks, tables, charts, metadata, and hierarchy are all reconstructed as their proper types.
ParseResult.load(path)
Classmethod. Reads a JSON file written by save() or to_json() and returns the reconstructed ParseResult.
result.save("output/result.json")
result = ParseResult.load("output/result.json")