Registry / data / tree-sitter-go

tree-sitter-go

JSON →
library0.25.0pypypi✓ verified 25d ago

tree-sitter-go provides Python bindings for the Go programming language grammar, enabling the tree-sitter parsing library to generate incremental syntax trees for Go code. This allows for robust code analysis, highlighting, and manipulation. The library is actively maintained, with releases generally coinciding with updates to the core tree-sitter project.

pip install tree-sitter-go tree-sitter
INSTALL
IMPORT
SIG · TREE-SITTER-GO
T
tree-sitter-go
datapythonv0.25.0
Install
1.6s avg
Import
48ms
Disk
18MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
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
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.050s · 19.6MB
glibc
py 3.103.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.
fix
Review 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.
fix
Instead 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.
fix
Ensure 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.
Agent activity
27 hits · last 30 days
node
24
OpenAI (training)
1
Resources
tree-sitter-go — pip install tree-sitter-go · libregistry