Home

Block

A single structural element extracted from one page — one heading, one paragraph, or one table — before any chunking happens. result.blocks is a list of these, ordered as they appear in the document. For the concept and how blocks relate to chunks, see Blocks.

result = docslicer.parse_document("report.pdf")
 
for block in result.blocks:
    print(block.type, block.page_number, block.text[:80])

Fields

FieldTypeDescription
idstrUnique identifier for this block within the result.
typestrThe kind of content this block holds — paragraph, heading, table, exhibits, navigation, and so on. See Block types for the full vocabulary.
textstrThe block's text. For table blocks this is the serialised table, rendered per the chosen table representation.
char_countintCharacter count of text.
page_numberint1-based physical page number the block appears on.
page_labelstr | NonePrinted page label, e.g. "iv", "A-6". Differs from page_number when documents use Roman numerals, lettered appendices, or custom numbering. None when no label was detected.
sectionstrDocument region this block belongs to (body, front_matter, an appendix, …). See Sections for the full list.
chunk_idstr | NoneID of the chunk this block was merged into. None when the block was not assigned to a chunk — for example when parsed with chunking=False.
bboxBBox | NoneBounding box of the block on the page. Populated for PDF and for HTML rendered via Playwright; None for DOCX, PPTX, and HTML parsed without Playwright.
link_urllist[str]Unique URLs found within this block's text. Empty list when none were detected.
table_idslist[str]IDs of tables whose content appears in this block. Use these to look up the full Table object from result.tables; for a table block this points to its own table.
extradictAdditional pipeline fields requested via extra_fields on the parse call. Empty dict by default.

Unlike Chunk, a block has no heading, path, or token_count — those are chunk-level. Instead it carries type (what kind of element it is) and chunk_id (the chunk it ended up in).


Examples

Filter by type

block.type names the kind of element. Pull just the tables, or just the headings:

tables   = [b for b in result.blocks if b.type == "table"]
headings = [b for b in result.blocks if b.type == "heading"]

See Block types for every value.

Group blocks back into their chunks

block.chunk_id links each block to the chunk it was merged into:

from collections import defaultdict
 
blocks_by_chunk = defaultdict(list)
for block in result.blocks:
    blocks_by_chunk[block.chunk_id].append(block)

link_url carries any URLs found in the block — handy for SEC filings, where the exhibit index links straight to each exhibit document:

for block in result.blocks:
    if block.type == "exhibits":
        for url in block.link_url:
            print(block.text, "→", url)

See Browsing SEC exhibits for a worked example.

Use extra fields

result = docslicer.parse_document("report.pdf", extra_fields=["is_bold", "font_size"])
 
for block in result.blocks:
    print(block.extra["font_size"], block.text[:80])

Methods

to_dict()

Serialize the block to a plain dict. All fields are included.

d = block.to_dict()

Block.from_dict(d)

Reconstruct a Block from a dict produced by to_dict().

block = Block.from_dict(d)