Skip to main content

Lumberjack logo: an axe, document, trees, and a tree ring

Lumberjack

PyPI Python Docs CI

Turn documents and flat records into retrieval-ready chunks with structure and provenance intact.

Lumberjack is a Python library and CLI for RAG preprocessing. It reads a document tree instead of cutting plain text, preserves headings and source metadata, respects tables and fenced code, and keeps every chunk within a token budget whenever its content can be split safely.

中文说明 · Documentation · PyPI

Why Lumberjack?

  • Context survives splitting. Chunks separate heading metadata from body content, so retrieval can retain the section that introduced an answer.
  • Structure stays honest. Markdown/HTML/DOCX become heading trees; CSV/TSV, JSONL, and logs remain ordered records rather than fabricated sections.
  • Budgets are practical. The default splitter plans with fast incremental estimates, then records an authoritative final token count.
  • Topology is your choice. Pack sibling sections, preserve subtrees, or process each section body independently.

Input formats: now and planned

Lumberjack currently supports the formats below. A “planned” entry is a design commitment, not an installation promise: do not pass it to format or rely on automatic detection until it is marked supported in a release.

Format family Formats Status Intended structural model
Markup documents Markdown (.md, .markdown), HTML (.html, .htm) Supported Headings, blocks, tables, lists, code, and source lines.
Word-processing documents DOCX (.docx) Supported Heading styles, paragraphs, tables, lists, and document properties.
Plain and rich text TXT (.txt, .text), text logs (.log) Supported TXT paragraphs/lines; logs are atomic ordered records. RTF remains planned.
OpenDocument and legacy word processing ODT, DOC Planned Headings and blocks when the source format exposes them.
Spreadsheets and delimited data CSV (.csv), TSV (.tsv), XLSX (.xlsx, spreadsheets extra) Supported Header schema plus atomic rows with sheet/row/column provenance. XLS and ODS remain planned.
Semi-structured data JSON (.json), JSONL (.jsonl, .ndjson), XML (.xml), YAML (.yaml, .yml), TOML (.toml) Supported Scalar key paths, record lines, and XML leaf-element paths; all remain ordered records.
Analytical and database exports SQLite (.sqlite, .sqlite3, .db), SQL dump (.sql) Supported SQLite table/row provenance and ordered SQL statements. Parquet, Avro, and ORC are deferred.
Source code and notebooks Python, JavaScript/TypeScript, Bash, C/C++, C#, Go, Java, Kotlin, Lua, PHP, Ruby, Rust, Swift, Zig, and Jupyter notebooks Supported Install code-parsing for Tree-sitter declaration boundaries, syntax-error recovery, and source locations. Other languages are deferred.
Presentations and ebooks PPTX, PPT, ODP, EPUB Planned Slides/pages, titles, notes, and ordered content blocks.
Messages and archives EML, MSG, MBOX Planned Message headers, body, attachments, and thread provenance.
PDFs and images PDF, PNG, JPG/JPEG, TIFF, WebP Planned Native PDF text/layout where available; OCR/layout blocks and page provenance otherwise.

Flat data is a first-class design case, not a disguised heading tree. CSV, TSV, JSONL, Parquet, and record-oriented JSON will use ordered record/row units with schema and field-path provenance. Heading-oriented policies such as sibling section packing are not meaningful for those inputs; their adapters must select row/record-aware packing, preserve complete protected rows when configured, and report logical locations such as row number, column name, JSON path, page, or sheet. This behavior is planned; it is not implemented by the current three parsers.

Inspect every pipeline stage

Today, Lumberjack.saw() returns SplitResult(document, chunks), and the public parser, splitter, and finalizer can be called individually when an integration needs an intermediate DocTree or ChunkDraft.

The planned pipeline trace API will make every built-in and optional parsing stage inspectable through one stable result: raw Document, extraction output (for example OCR/layout), normalized DocTree, ChunkDrafts, rendered text, normalized/transformed text, and final Chunks. Visual PDF parsers such as MinerU, Docling, PaddleOCR-VL, and dots.mocr will be optional integrations—not core dependencies—and will retain page, bounding-box, and parser provenance.

Install

pip install lumberjack-py

# Exact tokenizers, DOCX/XLSX, Tree-sitter code parsing, and the Web API
pip install "lumberjack-py[tokenizers,docx,spreadsheets,code-parsing,web]"

Requires Python 3.10 or newer.

Split your first document

from lumberjack import Lumberjack

result = Lumberjack(max_tokens=500).saw("""
# Deployment

Deploy the service through the approved release workflow.

## Rollback

Keep the previous image available until health checks pass.
""")

for chunk in result.chunks:
    print(chunk.own_heading, chunk.body, chunk.token_count)

result.document contains the parsed DocTree, title, metadata, and source provenance. Each Chunk includes its body, final token_count, heading context, and source line range when available. See the five-minute guide for file inputs, output handling, and optional dependencies.

Use the CLI

# Infer a supported format from the file extension.
lumber handbook.md --max-tokens 1200

# Preserve CSV rows as atomic records (also use this for TSV, JSONL, and logs).
lumber people.csv --splitter record --max-tokens 1200

# Emit JSON suitable for an ingestion job.
lumber report.docx --tokenizer tiktoken --splitter subtree > chunks.json

The CLI reference lists every option and its default.

Choose a splitter

Splitter Choose it when you need
sibling Well-filled chunks that may pack adjacent sibling sections with shared context.
subtree A whole section subtree to stay together whenever it fits.
section (default) Each section's direct body to be considered independently.
Counting mode Behavior
Unprefixed / incremental-* Fast running estimates while planning, followed by a final authoritative count.
exact-* Fully recount each rendered candidate during planning.

Tokenizer choice and counting mode are independent. For example, tiktoken works with incremental-sibling. Read the splitter decision guide before tuning a production pipeline.

Web API

lumberjack-serve --reload

With the web extra installed, the service exposes POST /lumber/api/split/text for UTF-8 Markdown, HTML, TXT, LOG, CSV/TSV, JSON/JSONL, XML, and YAML requests, and POST /lumber/api/split/file for those formats plus DOCX and XLSX (install spreadsheets for XLSX). Select splitter: "record" for LOG, CSV/TSV/XLSX, JSON/JSONL, XML, and YAML. The remaining planned formats above are not accepted yet. FastAPI serves interactive OpenAPI documentation at /docs while the server is running.

Learn more

Benchmark reporting is under construction; this project does not make unverified quality or performance claims.

Release files for lumberjack-py 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lumberjack-py 0.5.0
File Size Uploaded
lumberjack_py-0.5.0.tar.gz 904.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for lumberjack-py 0.5.0
File Interpreter ABI Platform
lumberjack_py-0.5.0-py3-none-any.whl Python 3 none any Details

Total release size:1.1 MB

Release files / lumberjack_py-0.5.0.tar.gz

Download URL lumberjack_py-0.5.0.tar.gz
Size 904.6 kB
Tags Source
SHA-256 checksum
How to use checksums
cbf1c9c3377e870cbc5cd2c4851f95307bf38aefc46621a0e0d065cf23ba6d42
BLAKE2b-256 checksum
How to use checksums
8ee5f51127c69334db265aaa0f5244901912b080983854f676e97869eec1144a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 11, 2026.

Transparency log

Release files / lumberjack_py-0.5.0-py3-none-any.whl

Download URL lumberjack_py-0.5.0-py3-none-any.whl
Size 147.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0064b9166dc6fab9fb8f211954ab67e41ced0e0fcd93f4ebd9b03d60cde6268f
BLAKE2b-256 checksum
How to use checksums
5fa872481f903fac706542cc4097751644ae6f0ef709c831d3705383e4ba1ed2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 11, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.5.0 This release

2 release files

0.4.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page