Registry / serialization / tree-sitter-languages

tree-sitter-languages

JSON →
library1.10.2pypypi✓ verified 27d ago

The `tree-sitter-languages` library provides pre-compiled binary Python wheels for various Tree-sitter language parsers. It simplifies the setup for `py-tree-sitter` users by bundling common language grammars, eliminating the need for manual compilation. As of its last updates, the library is largely unmaintained, with official recommendations to consider `tree-sitter-language-pack` for active development and broader compatibility.

pip install tree-sitter-languages
INSTALL
IMPORT
SIG · TREE-SITTER-LANGUA
T
tree-sitter-languages
serializationpythonv1.10.2
Install
2.1s avg
Import
26ms
Disk
101MB
Pass rate
8/ 10
Env Coverage8 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v1.10.2 · 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
glibc
py 3.10
✓ —
✓ 2.1s
py 3.11
✓ —
✓ 2.1s
py 3.12
✓ —
✓ 1.9s
py 3.13
✕ build_error
✕ build_error
py 3.9
✓ —
✓ 2.5s
101MB installed
● package 101MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

get_language
✓ from tree_sitter_languages import get_language
get_parser
✓ from tree_sitter_languages import get_parser

Demonstrates how to load a language and obtain a parser, then use it to parse a simple Python code snippet. It highlights the crucial dependency on `tree-sitter` and the potential need for version pinning.

from tree_sitter_languages import get_language, get_parser import tree_sitter # The underlying tree-sitter library # IMPORTANT: This library has known compatibility issues with newer versions of `tree-sitter`. # For versions of `tree-sitter-languages` up to 1.10.2, you might need to pin `tree-sitter` # to an earlier version for functionality, e.g., `pip install tree-sitter==0.21.3`. try: # Get a language object for Python python_language = get_language('python') print(f"Loaded language: {python_language}") # Get a parser instance for Python python_parser = get_parser('python') print(f"Created parser: {python_parser}") # Example usage: parse some Python code code_bytes = b""" def hello_world(): print('Hello, Tree-sitter!') """ tree = python_parser.parse(code_bytes) print("\nParsed code:") print(code_bytes.decode()) print("\nRoot node of the syntax tree (S-expression form):") print(tree.root_node.sexp()) except ImportError as e: print(f"Error: {e}. Ensure 'tree-sitter-languages' and 'tree-sitter' are installed.") except Exception as e: print(f"An error occurred during parsing: {e}. Check tree-sitter version compatibility.")
Debug
Known issues
breakingVersions of `tree-sitter` equal to or greater than `0.22` (especially `0.25.1` and higher) introduce breaking changes that are incompatible with `tree-sitter-languages`. Attempting to use newer `tree-sitter` versions will result in runtime errors.
fix
Pin `tree-sitter` to an earlier, compatible version, such as `0.21.3`, when installing: `pip install tree-sitter-languages tree-sitter==0.21.3`.
affects: tree-sitter-languages all versions (when used with tree-sitter >= 0.22)
deprecatedThe `tree-sitter-languages` library is largely unmaintained. The original maintainers recommend migrating to `tree-sitter-language-pack` for continued support, new features, and broader compatibility with modern `tree-sitter` versions.
fix
Evaluate migrating your projects to `tree-sitter-language-pack` or another actively maintained Tree-sitter binding. Consult their documentation for equivalent usage patterns.
affects: All versions
gotchaSource installs of `tree-sitter-languages` are not supported. The library is distributed exclusively as pre-compiled binary wheels. Attempts to install from source will fail.
fix
Ensure your Python environment can correctly utilize pre-compiled binary wheels (e.g., compatible OS/architecture). Do not attempt to install directly from source.
affects: All versions
gotchaThe API provided by `tree-sitter-languages` is extremely minimal, offering only `get_language` and `get_parser`. For any advanced operations, such as traversing the syntax tree, querying nodes, or modifying parsers, you must directly interact with the underlying `py-tree-sitter` library's API.
fix
After obtaining a `language` or `parser` object, refer to the `py-tree-sitter` documentation for its API to perform detailed parsing, analysis, and manipulation tasks.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'tree_sitter_languages'
The `tree-sitter-languages` package is not installed or is not accessible in the current Python environment.
fix
Ensure the package is installed using `pip install tree-sitter-languages`.
ERROR: Could not find a version that satisfies the requirement tree-sitter-languages
`pip` failed to find compatible pre-compiled binary wheels for your specific operating system and Python version, often due to the library being unmaintained for newer environments.
fix
Try specifying an older version, e.g., `pip install tree-sitter-languages==1.8.0`, or consider `pip install tree-sitter-language-pack` as it is the actively maintained successor.
AttributeError: 'NoneType' object has no attribute 'parse'
The `get_language()` or `get_parser()` function returned `None` because the requested language was not found or supported, and subsequent code attempted to use this `None` object as a valid parser or language object.
fix
Always check if the result of `get_language()` or `get_parser()` is not `None` before using it, and ensure the language string is correct and supported by your installed version of `tree-sitter-languages`. For broader and updated language support, consider `tree-sitter-language-pack`.
Upgrade
Version history
1.10.2latest on PyPI · released Feb 4, 2024
Audit
Dependencies
tree-sitterrequiredProvides the core Tree-sitter Python bindings; specific versions are required for compatibility.
Agent activity
33 hits · last 30 days
node
30
OpenAI (training)
1
Resources
tree-sitter-languages — pip install tree-sitter-languages · libregistry