Home

Quickstart

From install to RAG-ready chunks in a few minutes.


Install

pip install docslicer

To parse URLs and JS-rendered HTML pages, install the browser extras and the Chromium runtime:

pip install 'docslicer[html]'
playwright install chromium

PDF, DOCX, and PPTX work with the base install — Playwright is only needed for HTML.


Parse a document

parse_document takes a file path, URL, raw bytes, or file-like object and auto-detects the format, so the same call handles PDF, DOCX, PPTX, and HTML:

import docslicer
 
result = docslicer.parse_document("report.pdf")
 
print(f"{len(result.chunks)} chunks across {result.metadata.page_count} pages")
for chunk in result.chunks[:3]:
    print(chunk.heading, "—", chunk.text[:80])

result.chunks is a list of Chunk objects — each a semantically coherent slice of the document, sized to fit an embedding model's context window.


Pull the right chunks — no embeddings needed

For a single document you often don't need a vector store at all. DocSlicer builds a heading outline deterministically, so an LLM agent can read the outline, decide which section is relevant, and pull only those chunks:

# 1. Show the outline — small and cheap to drop into an LLM prompt
print(result.hierarchy.to_outline())
 
# 2. Pull only the chunks under the section you (or the agent) picked
node = result.find_heading("Risk Factors")[0]
chunks = result.chunks_under(node)
 
context = "\n\n".join(c.text for c in chunks)

No embeddings, no similarity search — just the document's own structure. See Hierarchy for navigating by heading, page, or level.


Export chunks to JSONL for a RAG pipeline

When you do want to embed across many documents, write the chunks straight to JSONL — one JSON object per chunk, each carrying its text plus heading, path, page, and section:

# Write a file
result.export_chunks_jsonl("chunks.jsonl")
 
# Or get the JSONL as a string, no file I/O
jsonl = result.chunks_to_jsonl()

Load those lines into your embedding step and vector store as-is.


Export to Markdown

Need the whole document as clean Markdown — for feeding an LLM directly, or diffing document versions?

md = result.export_to_markdown()
 
with open("report.md", "w") as f:
    f.write(md)

Headings, paragraphs, and tables, rendered from the parsed structure rather than scraped text.


Next steps

  • Overview — the four-object model behind every parse
  • parse_document — full parameter reference
  • Chunking — how chunks are built and how to tune their size