Install & Compatibility
Where this runs
tested against v1.1.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.910 runs
installs and imports cleanly · install 0.0s · import 0.052s · 21.2MB
glibcpy 3.10–3.910 runs
installs and imports cleanly · install 1.5s · import 0.045s · 22MB
19MB installed
● package 19MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
Language
✓ from tree_sitter_kotlin import language
✗ import tree_sitter_kotlin as tskt
from tree_sitter import Language
KOTLIN_LANGUAGE = Language(tskt.language())
Demonstrates how to load the `tree-sitter-kotlin` grammar and use `tree_sitter.Parser` to parse a basic Kotlin code snippet, then access the root node of the generated Abstract Syntax Tree.
import tree_sitter_kotlin as tskt
from tree_sitter import Language, Parser
# Load the Kotlin grammar
KOTLIN_LANGUAGE = Language(tskt.language())
# Create a parser and set the language
parser = Parser()
parser.set_language(KOTLIN_LANGUAGE)
# Sample Kotlin code to parse
kotlin_code = b'''
fun main() {
val greeting = "Hello, Tree-sitter!"
println(greeting)
}
'''
# Parse the code
tree = parser.parse(kotlin_code)
# Get the root node of the AST
root_node = tree.root_node
print(f"Root node type: {root_node.type}")
print(f"Root node children count: {len(root_node.children)}")
# Example: Find a function declaration
function_node = root_node.children[0] # Assuming 'fun main()' is the first child
if function_node.type == 'function_declaration':
print(f"Found function: {function_node.text.decode('utf8').split('(')[0]}")
Debug
Known issues
breakingThe `Language.build_library()` static method for compiling grammars was removed from the `tree_sitter` Python binding around versions 0.21.x/0.22. Direct compilation of local grammar sources is no longer supported via this API.fixInstead of `Language.build_library()`, install pre-compiled language packages (e.g., `pip install tree-sitter-kotlin`). For custom grammars, external compilation tools or older `tree_sitter` versions (pre-0.22.0) are required.
affects: tree_sitter >= 0.22.0
gotchaTree-sitter can fail to parse large files (e.g., >32KB) with a generic 'Invalid argument' error if the internal buffer size is not adequately configured.fixWhen creating a `Parser`, consider setting a larger `bufferSize` in the `parse()` method's options if dealing with very large source files, or splitting files into smaller chunks before parsing. Consult `tree_sitter` documentation for `parse()` method options.
affects: All versions
gotchaGrammar objects are loaded via a function call, not directly as attributes. For `tree-sitter-kotlin`, you must call `tskt.language()` to get the underlying C grammar object.fixEnsure you call `tree_sitter_kotlin.language()` (e.g., `Language(tskt.language())`) and do not treat `language` as a direct attribute or constant without the `()`.
affects: All versions
Upgrade
Version history
1.1.0latest on PyPI · released Jan 9, 2025
Audit
Dependencies
tree_sitterrequiredRequired for the Python bindings to interact with Tree-sitter grammars.