Metadata-Version: 2.5
Name: treechunk
Version: 0.1.0
Summary: A Python library for tree-aware chunking.
License: MIT License
        
        Copyright (c) 2026 Vishwa Aloka
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: chunking,text-processing,tree
Classifier: Development Status :: 3 - Alpha
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Typing :: Typed
Requires-Python: >=3.10
Provides-Extra: dev
Requires-Dist: pytest-cov>=5.0; extra == 'dev'
Requires-Dist: pytest>=8.0; extra == 'dev'
Requires-Dist: ruff>=0.6; extra == 'dev'
Description-Content-Type: text/markdown

# TreeChunk

TreeChunk is a Python library for tree-aware chunking.

## Installation

```bash
pip install TreeChunk
```

## Development setup

Create and activate a virtual environment, then install the package with its
development tools:

```bash
python -m venv .venv
python -m pip install --upgrade pip
python -m pip install -e ".[dev]"
```

Run the checks:

```bash
pytest
ruff check .
ruff format --check .
```

## Project layout

```text
src/treechunk/       Library source code
  chunkers/          Chunking strategies
  core/              Core models and interfaces
  utils/             Shared internal utilities
tests/               Automated tests
docs/                Project documentation
```

## Usage

```python
from treechunk import RecursiveChunker

chunks = RecursiveChunker(max_chars=500).chunk("Your text goes here.")

print(chunks[0].text)
print(chunks[0].metadata)
```

Section chunks can be limited by characters or words:

```python
from treechunk import SectionChunker

character_chunks = SectionChunker(max_chars=500).chunk(document)
word_chunks = SectionChunker(max_words=100).chunk(document)
```

Only one size limit can be used at a time.

## Dialogue chunking

DialogueChunker identifies `Speaker: message` and timestamped transcript lines,
preserves multiline turns, and can overlap turns between chunks:

```python
from treechunk import DialogueChunker

chunks = DialogueChunker(max_turns=4, overlap_turns=1).chunk(transcript)
```

Structured chat messages can be passed without text parsing:

```python
chunks = DialogueChunker().chunk_messages(
    [{"role": "user", "content": "Hello"}]
)
```

## Mail and letter chunking

CorrespondenceChunker provides one combined implementation for email and letter
content. MailChunker and LetterChunker remain available as focused names and
share the same implementation.

```python
from treechunk import CorrespondenceChunker, LetterChunker, MailChunker

all_correspondence = CorrespondenceChunker(max_words=150).chunk(text)
email_chunks = MailChunker(max_words=150).chunk(email_thread)
letter_chunks = LetterChunker(max_chars=1_000).chunk(letter)
```
