Registry / serialization / tree-sitter-kotlin

tree-sitter-kotlin

JSON →
library1.1.0pypypi✓ verified 86d ago

tree-sitter-kotlin provides a Kotlin grammar for the Tree-sitter parsing library. Tree-sitter is an incremental parsing system designed for text editors, enabling fast and robust syntax tree generation and updates. This Python package provides pre-compiled binaries of the Kotlin grammar, allowing developers to parse Kotlin code and build Abstract Syntax Trees (ASTs) in Python applications. The library maintains an active development status, with recent releases indicating a cadence of a few updates per year.

pip install tree-sitter-kotlin
INSTALL
IMPORT
SIG · TREE-SITTER-KOTLIN
T
tree-sitter-kotlin
serializationpythonv1.1.0
Install
1.5s avg
Import
49ms
Disk
19MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
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
musl
py 3.10–3.910 runs
installs and imports cleanly · install 0.0s · import 0.052s · 21.2MB
glibc
py 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.
fix
Instead 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.
fix
When 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.
fix
Ensure 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.
Agent activity
10 hits · last 30 days
node
8
OpenAI (training)
2
Resources
tree-sitter-kotlin — pip install tree-sitter-kotlin · libregistry