Skip to main content

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

Lumberjack

PyPI Python Docs CI

Lumberjack is a document preprocessing library for retrieval-augmented generation (RAG). It converts documents into token-budgeted chunks, preserves document structure and source metadata, and splits tables by row with configurable header repetition.

Lumberjack can be used through the Python API, command-line interface, or Web API. Optional adapters support integration with LangChain, LlamaIndex, and Haystack.

中文说明 · Documentation · PyPI

Three ways to use Lumberjack

1. Python API

Pass text, bytes, a file path, or a Document to Lumberjack.saw(). The result contains the parsed document and finalized chunks.

from lumberjack import Lumberjack

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

Deploy through the approved release workflow.
""")

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

For multiple documents, saw_many() returns results as an iterator. See the Python API reference.

2. Command line

Pass a file, directory, or glob to lumber. The command-line interface emits JSON and supports batch output, with one result file per input document.

pip install lumberjack-py
lumber handbook.md --max-tokens 1200
lumber 'docs/**/*.md' --recursive --output-dir chunks/

Use --input-format to select a parser explicitly. For row- or record-oriented inputs such as CSV, TSV, JSONL, and logs, select --splitter record. See the CLI reference.

3. Web API

Install the web extra and start the service. Submit text or upload a file; the response contains the resulting chunks in JSON format.

pip install 'lumberjack-py[web]'
lumberjack-serve --host 127.0.0.1 --port 9612

The API provides POST /lumber/api/split/text and POST /lumber/api/split/file. Interactive request documentation is available at http://127.0.0.1:9612/docs while the service is running.

What it does well

  • Broad format support. Markdown, HTML, DOCX, PDF, EPUB, PPTX/PPT/ODP, EML/MSG/MBOX, plain text and logs, CSV/TSV, JSON/JSONL, XML, YAML/TOML, XLSX, SQLite/SQL, source code, and Jupyter notebooks are parsed into a shared document model. Model-based tokenizers and enhanced code parsing require optional dependencies.
  • Structure and provenance. Heading context is retained with each chunk. Record-oriented inputs preserve row, field, sheet, and source-location metadata rather than being represented as artificial sections.
  • Row-aware table splitting. Markdown and HTML tables are split at row boundaries. Table headers are repeated in each generated chunk by default and can be configured by table type.
  • Content-aware splitting. Code fences retain their delimiters when split. Lists and other block types have dedicated handling. Protected blocks that cannot be split safely may exceed the configured token budget.
  • Configurable chunk organization. Select sibling-section packing, subtree-first grouping, per-section processing, or record-aware packing for flat inputs.
  • Token-budget controls. The default approximate tokenizer requires no model download. Optional tiktoken and Transformers tokenizers provide model-based counts. Exact and incremental counting modes can be selected independently.

Supported input formats

Family Formats Notes
Documents Markdown, HTML, DOCX, PDF, EPUB EPUB follows spine order; the pdf extra converts text-layer PDFs locally with MarkItDown. Scanned PDFs require a separate visual parser.
Presentations PPTX, PPT, ODP Slides and notes retain page provenance. PPTX needs presentations; legacy PPT also needs local LibreOffice.
Mail EML, MSG, MBOX Headers, body, attachments, and thread identifiers are retained. MSG needs the msg extra.
Text and records TXT, LOG, CSV, TSV, JSON, JSONL, XML, YAML, TOML Record formats preserve logical row/field paths; use the record splitter for flat record packing.
Spreadsheets and databases XLSX, SQLite, SQL dumps SQLite uses the standard library.
Code and notebooks Python, JavaScript/TypeScript, Bash, C/C++, C#, Go, Java, Kotlin, Lua, PHP, Ruby, Rust, Swift, Zig, Jupyter notebooks The code-parsing extra adds Tree-sitter declaration boundaries and syntax-error recovery.

RTF, ODT, legacy Excel, image, and columnar formats are not currently supported.

Table splitting

Tables are treated as structured blocks. When a table exceeds its block budget, Lumberjack groups complete rows into separate chunks and repeats the Markdown header and delimiter, or the HTML table header, by default. Set repeat_header=False to omit the header from subsequent chunks. A row that individually exceeds the budget is preserved intact and may cause its chunk to exceed that budget.

Python callers configure tables with typed options:

from lumberjack import Lumberjack
from lumberjack.block import MarkdownTableConfig
from lumberjack.splitter import SectionSplitter
from lumberjack.tokenizer import ApproxByteTokenizer

tokenizer = ApproxByteTokenizer()
splitter = SectionSplitter(
    tokenizer,
    max_tokens=500,
    block_options=[MarkdownTableConfig(repeat_header=True, max_tokens=300)],
)
result = Lumberjack(tokenizer=tokenizer, splitter=splitter).saw("report.md")

The CLI accepts equivalent settings, for example --block table:repeat-header=false,max-tokens=300. HTML tables use HTMLTableConfig in Python or html_table in CLI configuration.

Choosing a splitter

Splitter Behavior
section (default) Processes each section's direct body independently.
subtree Keeps a section subtree together when it fits.
sibling Packs adjacent sibling sections when they fit.
record Packs flat rows or records, for CSV/TSV, JSONL, logs, and similar inputs.

The exact-* variants recount candidate text during planning. The default and incremental-* variants use incremental counts during planning and report a final authoritative count. Tokenizer choice is independent of counting mode.

Install optional features

# PDF, presentation, and MSG parsing, model tokenizers, Web API, and Tree-sitter parsing
pip install 'lumberjack-py[pdf,presentations,msg,tokenizers,web,code-parsing]'

# Optional framework adapters
pip install 'lumberjack-py[langchain,llama-index,haystack]'

Framework adapters are available under lumberjack.integrations. They convert chunks to framework documents or nodes and provide native splitter or parser components. See the integration guides.

Learn more

Metadata

Release files for lumberjack-py 0.6.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.6.0
File Size Uploaded
lumberjack_py-0.6.0.tar.gz 927.8 kB Details

Built distribution (wheel)

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

Total release size: 1.1 MB

Release files / lumberjack_py-0.6.0.tar.gz

Download URL lumberjack_py-0.6.0.tar.gz
Size 927.8 kB
Tags Source
SHA-256 checksum
How to use checksums
e55b0e348d5bf1180965132d0e6f176e4b7e695e29108f82eecdfb438ed52da8
BLAKE2b-256 checksum
How to use checksums
bcccace37d83080322a1032398823d4ef7d713e415771760ed1152ad53b22837
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 Oct 10, 2026.

Transparency log

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

Download URL lumberjack_py-0.6.0-py3-none-any.whl
Size 157.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e0a4ff1996bf87a239fac4f2de93320e964b186eb1908dfb1f7e28f42823817c
BLAKE2b-256 checksum
How to use checksums
f45d0f8d30cf230e47b9942381851aac0e08b418f48b9c3b45fc3d93531d5f7a
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 Oct 10, 2026.

Transparency log

Release history Release notifications | RSS feed

0.7.0

2 release files

This release

0.6.0 This release

2 release files

0.5.0

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