Install & Compatibility
Where this runs
tested against v0.25.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.050s · 19.6MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 1.6s · import 0.046s · 21MB
18MB installed
● package 18MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
language
✓ import tree_sitter_go as tsgo
from tree_sitter import Language, Parser
GO_LANGUAGE = Language(tsgo.language())
The `tree_sitter_go` package exports a `language()` function that returns the compiled Go grammar, which is then loaded by the core `tree_sitter.Language` class.
Parser
✓ from tree_sitter import Parser
✗ from tree_sitter_go import Parser
The `Parser` class is part of the core `tree-sitter` Python bindings, not the language-specific grammar package.
This quickstart demonstrates how to load the Go grammar, create a parser, and parse a simple Go code snippet. It then prints the root node's type and the types of its immediate children, showcasing the basic structure of the generated Abstract Syntax Tree (AST).
import tree_sitter_go as tsgo
from tree_sitter import Language, Parser
# Load the Go language grammar
GO_LANGUAGE = Language(tsgo.language())
# Create a parser and set its language
parser = Parser()
parser.set_language(GO_LANGUAGE)
# Example Go code (must be bytes for tree-sitter)
go_code = b"""
package main
import (
"fmt"
"os"
)
func main() {
// A simple 'Hello World' in Go
name := os.Getenv("USER_NAME")
if name == "" {
name = "Tree-sitter User"
}
fm.Println("Hello,", name + "!")
}
"""
# Parse the code
tree = parser.parse(go_code)
# Get the root node of the syntax tree
root_node = tree.root_node
# Print basic information about the root node
print(f"Root Node Type: {root_node.type}")
print(f"Root Node Text (first 50 chars): {root_node.text.decode('utf8')[:50]}...")
# Traverse and print types of top-level children
print("\nTop-level children types:")
for child in root_node.children:
print(f"- {child.type}")
Debug
Known issues
breakingThe `tree-sitter` core library (a dependency) introduced significant breaking changes in version `0.25.0`, including an ABI bump to 15, removal of `ts_node_child_containing_descendant`, and changes to parsing/query cancellation APIs. Users upgrading the core `tree-sitter` package should consult its changelog for compatibility.fixReview the core `tree-sitter` library's `0.25.0` release notes and adjust code for API changes. Ensure your `tree-sitter-go` version is compatible with your `tree-sitter` core version.
affects: tree-sitter>=0.25.0
deprecatedThe `Language.build_library` static method was removed from the `tree-sitter` Python bindings around version `0.21.x`. Attempting to build grammars dynamically from source within Python code will now fail.fixInstead of `Language.build_library`, directly install pre-compiled grammar packages like `tree-sitter-go` via `pip`. The `tree-sitter-go.language()` function already provides the pre-compiled grammar.
affects: tree-sitter>=0.21.0
gotchaUsers on Windows may encounter challenges when installing `tree-sitter` or language grammars due to underlying C/C++ compilation requirements. Error messages related to missing compilers (e.g., `cl.exe`) are common.fixEnsure you have a compatible C/C++ compiler toolchain installed (e.g., Build Tools for Visual Studio, MinGW, or clang). For many users, installing and using `tree-sitter` within Windows Subsystem for Linux (WSL) can provide a smoother experience.
affects: *
Upgrade
Version history
0.25.0latest on PyPI · released Aug 29, 2025
Audit
Dependencies
pythonrequiredRequired Python version.
tree-sitterrequiredCore tree-sitter parsing library bindings required to use the grammar.