Quick Start
This guide walks you from install to parsing, code intelligence, and LLM chunking.
1. Install
Section titled “1. Install”pip install tree-sitter-language-packnpm install @xberg-io/tree-sitter-language-packcargo add tree-sitter-language-packbrew tap xberg-io/homebrew-tapbrew install xberg-io/homebrew-tap/ts-pack2. Download Parsers
Section titled “2. Download Parsers”Parsers download automatically on first use. For production, CI, Docker, or offline environments, pre-download them.
Specific languages
Section titled “Specific languages”# Download specific languagests-pack download python javascript rust go
# Download all available languagests-pack download --all
# Download a language group (the manifest currently defines only "all")ts-pack download --groups all
# Fresh download (clear cache first)ts-pack download --fresh python
# Check what's cachedts-pack list --downloadedDownload a single language parser and verify count
from tree_sitter_language_pack import download
def main() -> None: names = ["python"] result = download(names) print(result)
main()Download a single language parser and verify count
import { download } from "@xberg-io/tree-sitter-language-pack";function main() { const result = download(["python"]); console.log(result);}
void main();Download a single language parser and verify count
require "tree_sitter_language_pack"result = TreeSitterLanguagePack.download(['python'])puts result.inspectDownload a single language parser and verify count
<?php
declare(strict_types=1);
require_once __DIR__ . '/vendor/autoload.php';
use Tree\Sitter\Language\Pack\TreeSitterLanguagePack;$result = TreeSitterLanguagePack::download(["python"]);var_dump($result);Download a single language parser and verify count
package main
import ( "encoding/json" "fmt" tspack "github.com/xberg-io/tree-sitter-language-pack/packages/go")
func main() { var names []string if err := json.Unmarshal([]byte(`["python"]`), &names); err != nil { panic(fmt.Sprintf("config parse failed: %v", err)) } result, err := tspack.Download(names) if err != nil { panic(err) } fmt.Printf("%+v\n", result)}Download a single language parser and verify count
import io.xberg.treesitterlanguagepack.*;
public final class Example { public static void main(String[] args) throws Exception { var result = TreeSitterLanguagePack.download(java.util.List.of("python")); System.out.println(result); }}Download a single language parser and verify count
using System;using System.Text.Json;using TreeSitterLanguagePack;
var ConfigOptions = new JsonSerializerOptions { PropertyNameCaseInsensitive = true };var result = TreeSitterLanguagePackConverter.Download(new List<String>() { JsonSerializer.Deserialize<String>("\"python\"", ConfigOptions)! });Console.WriteLine(result);Download a single language parser and verify count
result = TreeSitterLanguagePack.download(["python"])IO.inspect(result)Download a single language parser and verify count
import 'dart:io';import 'package:tree_sitter_language_pack/tree_sitter_language_pack.dart';import 'package:tree_sitter_language_pack/src/tree_sitter_language_pack_bridge_generated/frb_generated.dart' show RustLib;Future<void> main() async { await RustLib.init(); try { final result = await TreeSitterLanguagePackBridge.download(<String>['python']); stdout.writeln(result); } finally { RustLib.dispose(); }}Download a single language parser and verify count
import TreeSitterLanguagePack
let result = try TreeSitterLanguagePack.download(names: ["python"])print(result)Download a single language parser and verify count
const std = @import("std");const tree_sitter_language_pack = @import("tree_sitter_language_pack");
pub fn main() !void { const result = try tree_sitter_language_pack.download("[\"python\"]"); std.debug.print("{any}\n", .{result});
}prefetch([‘python’]) downloads and loads parser
import io.xberg.tslp.android.*
fun main() { TreeSitterLanguagePack.prefetch(listOf("python"))}prefetch([‘python’]) downloads and loads parser
import { prefetch } from "@xberg-io/tree-sitter-language-pack-wasm";function main() { const result = prefetch(["python"]);}
void main();Download a single language parser and verify count
use tree_sitter_language_pack::download;
fn main() { let names_json: serde_json::Value = serde_json::from_str(r#"["python"]"#).unwrap(); let names = serde_json::from_value::<Vec<String>>(names_json).unwrap(); let names_refs: Vec<&str> = names.iter().map(String::as_str).collect(); let result = download(&names_refs); println!("{:?}", result);}All 371 languages
Section titled “All 371 languages”ts-pack download --allfrom tree_sitter_language_pack import download_all
download_all()import { downloadAll } from "@xberg-io/tree-sitter-language-pack";
downloadAll();use tree_sitter_language_pack::download_all;
download_all()?;By language group
Section titled “By language group”Group names are manifest data, not a compile-time constant. The published manifest currently
defines exactly one group, "all" — there is no web, data, or systems group, and passing
one fails. Enumerate the real names with manifest_groups() before calling download_group().
from tree_sitter_language_pack import download_group, manifest_groups
for group in manifest_groups(): print(group) # currently prints just: all
download_group("all")use tree_sitter_language_pack::{download_group, manifest_groups};
let group = manifest_groups()? .into_iter() .next() .expect("manifest defines no groups");let count = download_group(&group)?;println!("{count} languages available");Docker and CI
Section titled “Docker and CI”Pre-download parsers during your build to avoid runtime network calls:
FROM python:3.12-slimRUN pip install tree-sitter-language-pack# Pre-download at build time — no network needed at runtimeRUN python -c "from tree_sitter_language_pack import download_all; download_all()"- name: Install and pre-download parsers run: | pip install tree-sitter-language-pack python -c "from tree_sitter_language_pack import download; download(['python', 'javascript', 'rust'])"Configuration file
Section titled “Configuration file”Declare which languages your project needs in a language-pack.toml:
languages = ["python", "javascript", "rust", "go"]# groups = ["all"] # only names returned by manifest_groups() are accepted# cache_dir = "/tmp/parsers"Then download everything declared in the config:
# Reads language-pack.toml automaticallyts-pack downloadfrom tree_sitter_language_pack import init
# Reads language-pack.toml from current directoryinit()3. Parse Code
Section titled “3. Parse Code”Run the parser over a source string. process() parses the source and returns the result;
if the language is not cached yet it is downloaded on this first call.
# Download parsersts-pack download python javascript rust
# Parse a filets-pack parse main.py --format json
# Run code intelligencets-pack process src/app.py --all
# List available languagests-pack list --manifestParse a Python function definition and assert node type
from tree_sitter_language_pack import process
def main() -> None: source = "def hello(): pass" config = {"language": "python"} result = process(source, config) print(result)
main()Parse a Python function definition and assert node type
import { process } from "@xberg-io/tree-sitter-language-pack";function main() { const result = process("def hello(): pass", { language: "python" }); console.log(result);}
void main();Parse a Python function definition and assert node type
require "tree_sitter_language_pack"result = TreeSitterLanguagePack.process('def hello(): pass', { 'language' => 'python' })puts result.inspectParse a Python function definition and assert node type
<?php
declare(strict_types=1);
require_once __DIR__ . '/vendor/autoload.php';
use Tree\Sitter\Language\Pack\TreeSitterLanguagePack;use Tree\Sitter\Language\Pack\Language;use Tree\Sitter\Language\Pack\ProcessConfig;use Tree\Sitter\Language\Pack\Tree;$config = \Tree\Sitter\Language\Pack\ProcessConfig::from_json(json_encode(["language" => "python"]));$result = TreeSitterLanguagePack::process("def hello(): pass", $config);var_dump($result);Parse a Python function definition and assert node type
package main
import ( "fmt" tspack "github.com/xberg-io/tree-sitter-language-pack/packages/go")
func main() { config := tspack.ProcessConfig{ Language: `python`, } result, err := tspack.Process(`def hello(): pass`, config) if err != nil { panic(err) } fmt.Printf("%+v\n", result)}Parse a Python function definition and assert node type
import io.xberg.treesitterlanguagepack.*;
public final class Example { public static void main(String[] args) throws Exception { var configJson = "{\"language\":\"python\"}"; var config = JsonUtil.fromJson(configJson, ProcessConfig.class); var result = TreeSitterLanguagePack.process("def hello(): pass", config); System.out.println(result); }}Parse a Python function definition and assert node type
using System;using TreeSitterLanguagePack;
var result = TreeSitterLanguagePackConverter.Process("def hello(): pass", new ProcessConfig { Language = "python" });Console.WriteLine(result);Parse a Python function definition and assert node type
config_value = %TreeSitterLanguagePack.ProcessConfig{language: "python"}result = TreeSitterLanguagePack.process("def hello(): pass", config_value)IO.inspect(result)Parse a Python function definition and assert node type
import 'dart:io';import 'package:tree_sitter_language_pack/tree_sitter_language_pack.dart';import 'package:tree_sitter_language_pack/src/tree_sitter_language_pack_bridge_generated/frb_generated.dart' show RustLib;Future<void> main() async { await RustLib.init(); try { final config = await createProcessConfigFromJson(json: '{"language":"python"}'); final result = await TreeSitterLanguagePackBridge.process('def hello(): pass', config: config); stdout.writeln(result); } finally { RustLib.dispose(); }}Parse a Python function definition and assert node type
import TreeSitterLanguagePack
let configObj = try TreeSitterLanguagePack.processConfigFromJson("{\"language\":\"python\"}")let result = try TreeSitterLanguagePack.process(source: "def hello(): pass", config: configObj)print(result)Parse a Python function definition and assert node type
const std = @import("std");const tree_sitter_language_pack = @import("tree_sitter_language_pack");
pub fn main() !void { const _result_json = try tree_sitter_language_pack.process("def hello(): pass", "{\"language\":\"python\"}"); defer std.heap.c_allocator.free(_result_json); std.debug.print("{s}\n", .{_result_json});
}Parse a Python function definition and assert node type
import io.xberg.tslp.android.*import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
fun main() { val mapper = jacksonObjectMapper() val config = mapper.readValue("{\"language\":\"python\"}", ProcessConfig::class.java) val result = TreeSitterLanguagePack.process("def hello(): pass", config) println(result)}Parse a Python function definition and assert node type
import { process } from "@xberg-io/tree-sitter-language-pack-wasm";function main() { const result = process("def hello(): pass", { language: "python" }); console.log(result);}
void main();Parse a Python function definition and assert node type
use tree_sitter_language_pack::process;
fn main() { let source = r#"def hello(): pass"#; let config_json: serde_json::Value = serde_json::from_str(r#"{"language":"python"}"#).unwrap(); let config = serde_json::from_value(config_json).unwrap(); let result = process(source, &config); println!("{:?}", result);}4. Extract Code Intelligence
Section titled “4. Extract Code Intelligence”Go beyond the raw syntax tree. Extract functions, classes, imports, docstrings, and more with process.
# Parse and show S-expressionts-pack parse main.py --language python
# Parse as JSONecho "fn main() {}" | ts-pack parse - --language rust --format json
# Full code intelligencets-pack process src/app.py --language python --all
# Structure + imports onlyts-pack process src/app.py --structure --importsIntel: process with all features enabled
from tree_sitter_language_pack import process
def main() -> None: source = "# A comment\ndef greet(name):\n \"\"\"Say hello.\"\"\"\n return f'Hi {name}'\n\nimport os\n" config = {"language": "python"} result = process(source, config) print(result)
main()Intel: process with all features enabled
import { process } from "@xberg-io/tree-sitter-language-pack";function main() { const result = process("# A comment\ndef greet(name):\n \"\"\"Say hello.\"\"\"\n return f'Hi {name}'\n\nimport os\n", { language: "python" }); console.log(result);}
void main();Intel: process with all features enabled
require "tree_sitter_language_pack"result = TreeSitterLanguagePack.process("\# A comment\ndef greet(name):\n \"\"\"Say hello.\"\"\"\n return f'Hi {name}'\n\nimport os\n", { 'language' => 'python' })puts result.inspectIntel: process with all features enabled
<?php
declare(strict_types=1);
require_once __DIR__ . '/vendor/autoload.php';
use Tree\Sitter\Language\Pack\TreeSitterLanguagePack;use Tree\Sitter\Language\Pack\Language;use Tree\Sitter\Language\Pack\ProcessConfig;use Tree\Sitter\Language\Pack\Tree;$config = \Tree\Sitter\Language\Pack\ProcessConfig::from_json(json_encode(["language" => "python"]));$result = TreeSitterLanguagePack::process("# A comment\ndef greet(name):\n \"\"\"Say hello.\"\"\"\n return f'Hi {name}'\n\nimport os\n", $config);var_dump($result);Intel: process with all features enabled
package main
import ( "fmt" tspack "github.com/xberg-io/tree-sitter-language-pack/packages/go")
func main() { config := tspack.ProcessConfig{ Language: `python`, } result, err := tspack.Process(`# A commentdef greet(name): """Say hello.""" return f'Hi {name}'
import os`, config) if err != nil { panic(err) } fmt.Printf("%+v\n", result)}Intel: process with all features enabled
import io.xberg.treesitterlanguagepack.*;
public final class Example { public static void main(String[] args) throws Exception { var configJson = "{\"language\":\"python\"}"; var config = JsonUtil.fromJson(configJson, ProcessConfig.class); var result = TreeSitterLanguagePack.process("# A comment\ndef greet(name):\n \"\"\"Say hello.\"\"\"\n return f'Hi {name}'\n\nimport os\n", config); System.out.println(result); }}Intel: process with all features enabled
using System;using TreeSitterLanguagePack;
var result = TreeSitterLanguagePackConverter.Process("# A comment\ndef greet(name):\n \"\"\"Say hello.\"\"\"\n return f'Hi {name}'\n\nimport os\n", new ProcessConfig { Language = "python" });Console.WriteLine(result);Intel: process with all features enabled
config_value = %TreeSitterLanguagePack.ProcessConfig{language: "python"}result = TreeSitterLanguagePack.process("\# A comment\ndef greet(name):\n \"\"\"Say hello.\"\"\"\n return f'Hi {name}'\n\nimport os\n", config_value)IO.inspect(result)Intel: process with all features enabled
import 'dart:io';import 'package:tree_sitter_language_pack/tree_sitter_language_pack.dart';import 'package:tree_sitter_language_pack/src/tree_sitter_language_pack_bridge_generated/frb_generated.dart' show RustLib;Future<void> main() async { await RustLib.init(); try { final config = await createProcessConfigFromJson(json: '{"language":"python"}'); final result = await TreeSitterLanguagePackBridge.process('# A comment\ndef greet(name):\n """Say hello."""\n return f\'Hi {name}\'\n\nimport os\n', config: config); stdout.writeln(result); } finally { RustLib.dispose(); }}Intel: process with all features enabled
import TreeSitterLanguagePack
let configObj = try TreeSitterLanguagePack.processConfigFromJson("{\"language\":\"python\"}")let result = try TreeSitterLanguagePack.process(source: "# A comment\ndef greet(name):\n \"\"\"Say hello.\"\"\"\n return f'Hi {name}'\n\nimport os\n", config: configObj)print(result)Intel: process with all features enabled
const std = @import("std");const tree_sitter_language_pack = @import("tree_sitter_language_pack");
pub fn main() !void { const _result_json = try tree_sitter_language_pack.process("# A comment\ndef greet(name):\n \"\"\"Say hello.\"\"\"\n return f'Hi {name}'\n\nimport os\n", "{\"language\":\"python\"}"); defer std.heap.c_allocator.free(_result_json); std.debug.print("{s}\n", .{_result_json});
}Intel: process with all features enabled
import io.xberg.tslp.android.*import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
fun main() { val mapper = jacksonObjectMapper() val config = mapper.readValue("{\"language\":\"python\"}", ProcessConfig::class.java) val result = TreeSitterLanguagePack.process("# A comment\ndef greet(name):\n \"\"\"Say hello.\"\"\"\n return f'Hi {name}'\n\nimport os\n", config) println(result)}Intel: process with all features enabled
import { process } from "@xberg-io/tree-sitter-language-pack-wasm";function main() { const result = process("# A comment\ndef greet(name):\n \"\"\"Say hello.\"\"\"\n return f'Hi {name}'\n\nimport os\n", { language: "python" }); console.log(result);}
void main();Intel: process with all features enabled
use tree_sitter_language_pack::process;
fn main() { let source = r#"# A commentdef greet(name): """Say hello.""" return f'Hi {name}'
import os"#; let config_json: serde_json::Value = serde_json::from_str(r#"{"language":"python"}"#).unwrap(); let config = serde_json::from_value(config_json).unwrap(); let result = process(source, &config); println!("{:?}", result);}5. Inspect Query Sources
Section titled “5. Inspect Query Sources”process() covers the built-in intelligence fields. There is no public extract() helper for arbitrary query execution. For custom analysis, fetch bundled query source with helpers such as get_tags_query(), then run tree-sitter query APIs yourself or walk the AST manually.
from tree_sitter_language_pack import get_tags_query
tags_query = get_tags_query("python")if tags_query is not None: print(tags_query.splitlines()[0])use tree_sitter_language_pack::{get_parser, get_tags_query};
let query_source = get_tags_query("rust");let mut parser = get_parser("rust")?;let tree = parser.parse("fn main() {}").ok_or("failed to parse")?;println!("{}", tree.root_node().kind());6. Chunk for LLMs
Section titled “6. Chunk for LLMs”Split code at natural boundaries so language models receive coherent, complete units which is ideal for embedding pipelines and context windows.
from tree_sitter_language_pack import process, ProcessConfig
with open("large_module.py") as f: source = f.read()
config = ProcessConfig( language="python", chunk_max_size=1500, # max bytes per chunk structure=True,)result = process(source, config)
for i, chunk in enumerate(result.chunks): print(f"Chunk {i}: lines {chunk.start_line}-{chunk.end_line} " f"({chunk.end_byte - chunk.start_byte} bytes)")import { process } from "@xberg-io/tree-sitter-language-pack";import { readFileSync } from "fs";
const source = readFileSync("large_module.ts", "utf8");
const result = process(source, { language: "typescript", chunkMaxSize: 1500, structure: true,});
result.chunks.forEach((chunk, i) => { console.log(`Chunk ${i}: lines ${chunk.startLine}-${chunk.endLine} (${chunk.endByte - chunk.startByte} bytes)`);});# Chunk a file for LLM ingestionts-pack process large_module.py --chunk-size 1500 \ | jq '.chunks[] | {start: .start_line, end: .end_line, bytes: (.end_byte - .start_byte)}'You now have the full workflow. You can now install, download, parse, extract intelligence, inspect query sources, and chunk for LLMs. Go further with the following guides:
- Parsing guide — syntax trees, error handling, and incremental parsing
- Configuration —
language-pack.tomland advanced options - API Reference — full API docs for every binding