🧩 chunklet-py
“One library to split them all: Sentence, Code, Docs”
Hey! Welcome. Let's make some text chunking magic happen.
Why Smart Chunking? (Or: Why Not Just Split on Character Count?)
You could split your text by character count or random line breaks. But that's like trying to cut a wedding cake with a chainsaw. 🎂
Dumb splitting causes problems:
- Mid-sentence surprises: Your thoughts get chopped mid-way, losing all meaning
- Language confusion: Non-English text and code structures get treated the same
- Lost context: Each chunk forgets what came before
Smart chunking solves this by:
- Smart limits: respects both natural boundaries (sentences, paragraphs, sections) AND configurable limits (tokens, lines, functions)
- Language-aware: detects language automatically and applies the right rules (60+ languages supported)
- Context preservation: overlap between chunks, rich metadata (source, span, document structure)
🤔 So What's Chunklet-py Anyway? (And Why Should You Care?)
Chunklet-py is a developer-friendly text splitting library for devs, researchers, and AI engineers. It goes way beyond basic character counting. I built this because I was tired of terrible chunking options. Chunklet-py intelligently chunks text, documents, and code into meaningful, context-aware pieces, perfect for RAG pipelines and LLM applications.
Key features:
- Composable constraints: mix and match limits (sentences, tokens, sections) to get exactly the chunks you need
- Pluggable architecture: swap in custom token counters or document processors
- Rich metadata: every chunk comes with source references, spans, and structural info
- Multi-format support: PDF, DOCX, EPUB, Markdown, HTML, LaTeX, ODT, CSV, Excel, and plain text
Available tools:
SentenceSplitter: lightweight sentence tokenizationDocumentChunker: natural language with semantic boundariesCodeChunker: language-aware code chunkingSelfTuningChunker: for mixed text/code corporaChunkVisualizer: interactive web-based exploration
Perfect for prepping data for LLMs, building RAG systems, or powering AI search - Chunklet-py gives you the precision and flexibility you need across tons of formats and languages.
| Feature | Why it's awesome |
|---|---|
| 🚀 Blazingly Fast | Parallel processing to chunk large volumes of content quickly. |
| 🪶 Featherlight Footprint | Lightweight and memory-efficient, no unnecessary overhead. |
| 🗂️ Rich Metadata for RAG | Chunks include context-aware metadata (source, span, document properties, code AST details) for RAG and LLM pipelines. |
| 🔧 Infinitely Customizable | Pluggable token counters, custom document processors and more. |
| 🌐 Multilingual Mastery | Supports 60+ languages for text and document chunking with automatic detection and language-specific algorithms. |
| 🧑💻 Code-Aware Intelligence | Language-agnostic code chunking that preserves the structural integrity of your source code. |
| 🎯 Precision Chunking | Configurable limits based on sentences, tokens, sections, lines, and functions. |
| 📄 Document Format Mastery | Handles .pdf, .docx, .epub, .eml, .pptx, .txt, .tex, .html, .hml, .md, .rst, .rtf, .odt, .csv, and .xlsx. |
| 💻 Triple Interface: CLI, Library & Web | Command-line tool, importable library, or interactive web visualizer for real-time chunk exploration and parameter tuning. |
And that's just the start - there's plenty more to explore!
📦 Installation
Ready to get Chunklet-py running? Awesome! Let's get you set up quickly and painlessly.
The Quick & Easy Way
The simplest way to get started is with pip:
# Install and check it's working
pip install chunklet-py -U
chunklet --version
That's it! You're all set to start chunking.
Extra Features (Optional)
Want to unlock more Chunklet-py superpowers? Add these optional dependencies based on what you need:
- Structured Documents: For handling
.pdf,.docx,.epub,.eml,.pptx, and other document formats:pip install "chunklet-py[struct-doc]"
- Code Chunking: For Language-agnostic code chunking features:
pip install "chunklet-py[code]"
- Self-Tuning Chunking: For self-tuning mixed text/code chunking (bundles
struct-doc,code):pip install "chunklet-py[self-tuning]"
- Auto Language Detection: For automatic language detection (
lang="auto"). Usespy3langidto detect the language of your text:pip install "chunklet-py[lang-detect]"
- Indic Languages: For splitting text in Indic languages (Assamese, Gujarati, Kannada, Nepali, Odia, Punjabi, Sanskrit, Tamil, Telugu). Note: Bengali, Malayalam, and Hindi are already covered by the default install:
pip install "chunklet-py[indic]"
- Visualization: For the interactive web-based chunk visualizer:
pip install "chunklet-py[viz]"
- All Extras: To install all optional dependencies:
pip install "chunklet-py[all]"
The From-Source Way
Prefer building from source? You can clone and install manually for full control:
git clone https://github.com/speedyk-005/chunklet-py.git
cd chunklet-py
pip install .[all]
(But honestly, the pip way is usually way easier!)
Want to Help Make Chunklet-py Even Better?
That's awesome! We'd love to have you contribute. Check out our Contributing Guide first, then set up your development environment:
git clone https://github.com/speedyk-005/chunklet-py.git
cd chunklet-py
# For basic development (testing, linting)
pip install -e ".[dev]"
# For documentation development
pip install -e ".[docs]"
# For comprehensive development (including all optional features like document and code chunking + docs dependencies)
pip install -e ".[dev-all]"
These install Chunklet-py in "editable" mode so your code changes take effect immediately. The different options give you just the dependencies you need.
Go forth and code! (And remember, good developers write tests. We appreciate excellent code examples!)
Quick Reference 🛠️
The Constraint-Based Logic
Chunklet-py is basically a "choose your own adventure" for data. It's constraint-based, meaning you can swap, combine, or ignore the limits below as you see fit.
The Golden Rule: You must provide at least one constraint, or the chunker has no idea when to stop.
Core Imports
Pick your weapon based on whatever data mess you're currently cleaning up.
from chunklet import DocumentChunker # For PDFs, DOCX, and general text chaos
from chunklet import CodeChunker # For source code (it actually respects brackets)
from chunklet import SelfTuningChunker # For mixed text + code, self-tuning chunking
from chunklet import SentenceSplitter # For when you just need to split sentences
from chunklet import visualizer # Web-based chunk visualizer
Configuration & Limits
These tools don't share arguments, so don't try to use max_functions on a PDF unless you want to see a very confused Python interpreter.
DocumentChunker (Text & Docs)
Perfect for natural language where you don't want to cut someone off mid-sentence.
# Constraints are set once, at construction -- then reused by every call
chunker = DocumentChunker(
lang="en", # Required. Pass "auto" to detect it (needs the [lang-detect] extra)
max_sentences=3, # Stop after X sentences
max_tokens=500, # Don't blow up the LLM context
max_section_breaks=2, # Respect the Markdown headers
token_counter=..., # Required whenever you set max_tokens
overlap_percent=20, # Give it some "memory" of the last chunk
)
chunks = chunker.chunk_text(text)
# They're plain attributes, so tweak them whenever you like
chunker.max_sentences = 5
CodeChunker (Source Code)
Logic-aware. It doesn't do "overlap" because duplicate code is a hallucination waiting to happen.
# Again, use whichever constraints make sense for your file
chunker = CodeChunker(
max_lines=50, # Height limit
max_tokens=512, # Width limit
max_functions=1, # One function per chunk (keeps things tidy)
token_counter=..., # Required whenever you set max_tokens
)
# `strict` stays per-call, since it depends on the source
chunks = chunker.chunk_text(
text,
strict=True, # True: Crash on big blocks; False: Slice 'em up anyway
)
SelfTuningChunker (Mixed Text & Code)
Detects each source as document or code, learns per-profile structural metrics (KAMA), and sizes chunks to match — no constraint tuning needed.
# token_counter is optional if you don't want max_tokens
chunker = SelfTuningChunker(lang="en", token_counter=...)
# Learning happens per call -- no queue, no separate processing step
chunks = chunker.chunk_file("docs/guide.md")
chunks += chunker.chunk_text("Some raw prose, chunked just like a file.")
# Each chunk.metadata carries "inferred_type": "document" or "code"
# Already know which? Skip the guesswork with file_type="code"
chunks = chunker.chunk_text(text, file_type="code")
The Output Object
The chunkers return a list (or generator) of Chunk objects. These are Box instances, so you can use dot notation like a civilized developer.
for chunk in chunks:
print(chunk.content) # The actual text/code
print(chunk.metadata) # Chunk metadata
print() # Because whitespace is free
Input Methods (Chunkers Only)
These helper methods are for the DocumentChunker, CodeChunker and SelfTuningChunker. The SentenceSplitter is a simple soul and only takes strings.
| Method | Input | Return Type |
|---|---|---|
chunk_text(text) |
str | List[Chunk] |
chunk_file(path) |
Path or str | List[Chunk] |
chunk_texts(list) |
List[str] | Generator[Chunk] |
chunk_files(list) |
List[Path] | Generator[Chunk] |
The batch methods also have show_progress, on_errors, n_jobs params.
Specialized Tools
SentenceSplitter
The "lite" version for when you just need sentences and no fancy metadata.
# Pass lang="auto" to detect it (needs the [lang-detect] extra)
# 'auto' usually guesses right, but you can specify 'en', 'es', etc.
splitter = SentenceSplitter(lang="auto")
sentences = splitter.split_text(text)
CLI (Command Line Interface)
If you prefer the terminal to an IDE, the CLI is packed with features. Just ask for help.
chunklet --help
chunklet split --help
chunklet chunk --help
chunklet visualize --help
chunklet [COMMAND] [OPTIONS*]
How Chunklet-py Compares
While there are other chunking libraries available, Chunklet-py offers versatility, performance, and ease of use in one lightweight package. Here's a quick look at how it compares to some of the alternatives:
| Library | Key Differentiator | Focus |
|---|---|---|
| chunklet-py | All-in-one, lightweight, multilingual, language-agnostic with specialized algorithms. | Text, Code, Docs |
| LangChain | Full LLM framework with basic splitters (e.g., RecursiveCharacterTextSplitter, Markdown, HTML, code splitters). Good for prototyping but basic for complex docs or multilingual needs. | Full Stack |
| Chonkie | All-in-one pipeline (chunking + embeddings + vector DB). Uses tree-sitter for code. Multilingual. |
Pipelines |
| Semchunk | Text-only, fast semantic splitting. Built-in tiktoken/HuggingFace support. 85% faster than alternatives. | Text |
| CintraAI Code Chunker | Code-specific, uses tree-sitter. Initially supports Python, JS, CSS only. |
Code |
Chunklet-py is a specialized, drop-in replacement for the chunking step in any RAG pipeline. It handles text, documents, and code without heavy dependencies, while keeping your project lightweight.
🙌 Contributors & Thanks
A huge thank you to the awesome people who helped shape Chunklet-py:
- @jmbernabotto: helped mostly on the CLI part, suggesting fixes, features, and design improvements.
- @arnoldfranz: reported the CLI Path Validation Bug (#6) that helped improve error handling.
- @AkshatSharma25: fixed EML metadata extraction to capture all header fields.
📜 License
Check out the LICENSE file for all the details.
MIT License. Use freely, modify boldly, and credit appropriately! (We're not that legendary... yet 😉)
Metadata
Release files for chunklet-py 3.0.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 | |
|---|---|---|---|
| chunklet_py-3.0.0.tar.gz | 120.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| chunklet_py-3.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 236.2 kB
Release files / chunklet_py-3.0.0.tar.gz
| Download URL | chunklet_py-3.0.0.tar.gz |
|---|---|
| Size | 120.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6c7795701c790da4b35e87f545c6b87da56d3dee4d918cf6da46e85d173edabd
|
|
BLAKE2b-256 checksum How to use checksums |
c601ea4fde81157df6467f7d790cc6ae6f023fb7c8e3f8156ade710542178b0c
|
| 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 1, 2026.
Transparency logRelease files / chunklet_py-3.0.0-py3-none-any.whl
| Download URL | chunklet_py-3.0.0-py3-none-any.whl |
|---|---|
| Size | 116.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1726233b25500dc8e43876b68f66084c35c347800e2f3ede7062fd601c6a7d73
|
|
BLAKE2b-256 checksum How to use checksums |
e0f2cace39739fbba4ab9b4c8db6abb30376c459181a5d183bdd1a257d5a418d
|
| 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 1, 2026.
Transparency log