Lumberjack
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
tiktokenand 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. |
| 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
- Core concepts — document parsing, chunking, rendering, and source metadata.
- Configuration guide — block policies and budget controls.
- Custom components — parsers, tokenizers, splitters, and post-processing.
- Contributing · Security · License
Metadata
Release files for lumberjack-py 0.7.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| lumberjack_py-0.7.0.tar.gz | 928.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| lumberjack_py-0.7.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 1.1 MB
Release files / lumberjack_py-0.7.0.tar.gz
| Download URL | lumberjack_py-0.7.0.tar.gz |
|---|---|
| Size | 928.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
21351ad9774e4ee3941a2654bf5c0284604f398882fd2b4b547e5a4ff0c354aa
|
|
BLAKE2b-256 checksum How to use checksums |
d7c61e9e74c1e94ac3467f9233d3471fcaa0cc8c3900c1e2ee7b60b039ebef10
|
| 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 13, 2026.
Transparency logRelease files / lumberjack_py-0.7.0-py3-none-any.whl
| Download URL | lumberjack_py-0.7.0-py3-none-any.whl |
|---|---|
| Size | 157.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8e026c83992baf29f2917cc41fb7d6a773437f78fcacce252630121ecb97fedc
|
|
BLAKE2b-256 checksum How to use checksums |
072af5905b3516de8e18efd1752c8e05cf93ffb9b63a487cb8ab17def82abe3e
|
| 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 13, 2026.
Transparency log