Skip to main content

Tree-sitter Chunker

PyPI Python 3.11+ Test Suite codecov License

Split source code into functions, classes, and other syntax units for code search, embeddings, and AI context. Tree-sitter provides the syntax tree; Chunker returns source content, line and byte spans, and context metadata.

Install

Requires Python 3.11 or newer. The main package is a universal Python wheel.

pip install treesitter-chunker

The default parser stack uses Tree-sitter 0.26 and language-pack 1.20. Parser libraries download on first use and are cached by pack version and platform. The supported Linux wheel path requires glibc 2.34 or newer. For offline use, prefetch the languages you need while online:

python -c "import tree_sitter_language_pack as p; p.prefetch(['python', 'javascript', 'typescript'])"

See packaging and parser integrity for platform limits, offline custody, and release procedures. Debian, RPM, and Homebrew packages are currently suspended.

Optional extras include viz for visualization and advanced for additional query dependencies. Graphviz visualization also requires the system dot executable. The api extra installs REST API dependencies; the server under api/ runs from a source checkout and is not included in the main wheel.

Chunk a file or source text

from chunker import chunk_file, chunk_text

chunks = chunk_file("app.py", language="python")
for chunk in chunks:
    print(chunk.node_type, chunk.start_line, chunk.end_line)
    print(chunk.content)

source = "def greet(name):\n    return f'Hello, {name}'\n"
chunks = chunk_text(source, language="python", file_path="greet.py")

Pass a stable file_path when chunking text if you persist chunk identities. See the chunk identity contract and Boundary IR specification for identity, determinism, and relationship semantics.

The CLI can return JSON for use from other languages:

treesitter-chunker chunk app.py --lang python --json
printf 'def greet():\n    return "hello"\n' | treesitter-chunker chunk --stdin --lang python --json
treesitter-chunker boundary app.py --lang python --pretty
treesitter-chunker languages
treesitter-chunker --help

To check the installed version:

python -c "from importlib.metadata import version; print(version('treesitter-chunker'))"

Language support

The pinned language pack contains 371 parsers: 370 pass the bounded load gate, while COBOL is disabled after a native parser hang. Loading a parser does not establish useful chunk extraction. The committed coverage report records 28 extraction-verified languages and 12 languages with deterministic Boundary IR golden fixtures.

See the language coverage report for the per-language results and remaining extraction gaps.

BAML

Install the optional companion grammar for structural .baml chunking:

pip install 'treesitter-chunker[baml]'
treesitter-chunker chunk example.baml --json

The extra pins treesitter-chunker-baml-grammar==0.1.0. It uses BoundaryML's official grammar with a temporary overlay for BAML 0.20.1 backtick prompts. Native wheels cover Linux glibc x86_64/aarch64, macOS x86_64/arm64, and Windows x86_64, with tests on Python 3.11–3.13. Source installs require a C compiler.

Without the extra, main CLI BAML inputs give installation guidance and status 1; implicit ZeroConfigAPI file chunking falls back to text, and automatic symbol and Boundary repository scans skip BAML. Malformed BAML fails before returning structural chunks. See the companion grammar README.

Documentation

Development

git clone https://github.com/Consiliency/treesitter-chunker.git
cd treesitter-chunker
uv sync --locked --all-extras
uv run --locked --with toml --all-extras python scripts/run_ci_smoke.py

CONTRIBUTING.md describes local validation, platform checks, and Boundary IR changes. Coverage work remains in progress under treesitter-chunker#69; the Codecov badge reports the CI measurement and is not a claim that the full package meets a percentage target.

Report bugs through GitHub issues. Licensed under MIT.

Metadata

Release files for treesitter-chunker 6.0.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 treesitter-chunker 6.0.0
File Size Uploaded Provenance Actions
treesitter_chunker-6.0.0.tar.gz 1.3 MB With provenance Details for treesitter_chunker-6.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for treesitter-chunker 6.0.0
File Interpreter ABI Platform Actions
treesitter_chunker-6.0.0-py3-none-any.whl Python 3 none any Details for treesitter_chunker-6.0.0-py3-none-any.whl

Total release size: 2.1 MB

Release files / treesitter_chunker-6.0.0.tar.gz

Download URL treesitter_chunker-6.0.0.tar.gz
Size 1.3 MB
Tags Source
SHA-256 checksum
How to use checksums
4a26c80c5669a55737bc459484b9811e03f7c2b7a86724da3b373bbe3119715f
BLAKE2b-256 checksum
How to use checksums
eb5ba07c42ee3349b9e9c4421d48b7ff856f1a4019b24521887f62ae0b89593f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

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 21, 2026.

Transparency log

Release files / treesitter_chunker-6.0.0-py3-none-any.whl

Download URL treesitter_chunker-6.0.0-py3-none-any.whl
Size 852.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8e5927f387b05115e408496efbbf01343c4b7eba76b6c42ba209130e19153345
BLAKE2b-256 checksum
How to use checksums
3f8ce7eee7aa753f8ffeca2bc5ceceeb1257f8fcacd03c1adc01e2503965fa67
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

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 21, 2026.

Transparency log

Security for treesitter-chunker 6.0.0

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for treesitter_chunker-6.0.0.tar.gz

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 21, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

6.0.0 This release

2 release files Full provenance

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