tree-sitter-cmake
CMake grammar for tree-sitter
What it is and what it does
tree-sitter-cmake is a Python binding for a tree-sitter grammar that parses CMake code into a syntax tree. It wraps the grammar from the uyha/tree-sitter-cmake repository and exposes it through a simple Python API. You supply CMake source code as bytes, initialize a tree-sitter Parser with the CMake language, and receive back a traversable syntax tree representing commands, arguments, variables, and comments.
The package is designed for developers who need to analyze, transform, or validate CMake files programmatically. It supports general commands, flow control (if, while, foreach), functions, macros, quoted and bracket arguments, variable references, and both line and bracket comments.
Use it for:
- Build system analysis: extract and inspect CMake project structure, dependencies, and compiler flags
- CMake linting or validation: traverse the syntax tree to enforce coding standards or detect errors
- Code generation: programmatically modify or generate CMake files by manipulating the parsed tree
- Documentation extraction: parse CMake files to auto-generate build documentation or dependency graphs
- IDE integration: provide syntax highlighting, code completion, or error reporting for CMake editors
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Provides a tree-sitter grammar for parsing CMake code, enabling incremental syntax analysis of CMake files in Python applications.
Yes, if you need to parse or analyze CMake code programmatically in Python. The package is actively maintained, permissively licensed, and has no known vulnerabilities. Medium install friction is typical for tree-sitter bindings. Requires Python >= 3.10 and tree-sitter ~= 0.24.
Install
tree-sitter-cmake on PyPI
pip
pip install tree-sitter-cmakeuv
uv add tree-sitter-cmakepoetry
poetry add tree-sitter-cmakeInstalling tree-sitter-cmake
Before you install
Medium install friction due to platform-specific wheels; actively maintained with last commit on 2026-07-08.
License in practice
MIT license permits unrestricted use, modification, and distribution with minimal obligations—suitable for both open and closed-source projects.
Quickstart
pip install tree-sitter-cmake
import tree_sitter_cmake
import tree_sitter
cmake_language = tree_sitter.Language(tree_sitter_cmake.language())
parser = tree_sitter.Parser(cmake_language)
tree = parser.parse(b"cmake_minimum_required(VERSION 3.10)")
print(tree.root_node)
Requires Python >= 3.10 and tree-sitter ~= 0.24
Verify before relying
- Whether tree-sitter ~= 0.24 is automatically installed or must be manually added
- Performance characteristics when parsing large or deeply nested CMake files
- Completeness of grammar coverage for CMake syntax beyond documented constructs
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.10) |
| Install friction | medium — platform-specific wheel |
| Runtime dependencies | none |
| Maintenance | actively maintained — 263 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 74,361/month — #14,847 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: tree_sitter_cmake-0.7.2.post1-cp310-abi3-win_amd64.whl
Keywords: incremental, parsing, tree-sitter, cmake
Tags
More Linguistic packages
Detects and normalizes text encoding from…
permissive · top 100 on PyPI
tiktokentiktoken is a fast BPE tokenizer that converts…
permissive · top 1,000 on PyPI
chardetDetects character encoding and language in byte…
permissive · top 1,000 on PyPI
text-unidecodeConverts Unicode text to ASCII by…
copyleft · top 1,000 on PyPI
larkLark is a parsing library that builds abstract…
permissive · top 1,000 on PyPI
tree-sitterPython bindings to the tree-sitter parsing…
permissive · top 1,000 on PyPI
tree-sitter-javaProvides a Java language grammar for…
permissive · top 5,000 on PyPI
tree-sitter-pythonProvides a Python grammar for tree-sitter,…
permissive · top 5,000 on PyPI
tree-sitter-goProvides a Go language grammar for tree-sitter,…
permissive · top 5,000 on PyPI
tree-sitter-language-packProvides pre-compiled tree-sitter parsers for…
permissive · top 5,000 on PyPI
tree-sitter-rubyProvides a Ruby language grammar for…
permissive · top 5,000 on PyPI
tree-sitter-elixirProvides an Elixir language grammar for…
permissive · top 5,000 on PyPI
tree-sitter-cProvides a C language grammar for tree-sitter,…
permissive · top 5,000 on PyPI
tree-sitter-powershellProvides a tree-sitter grammar for parsing…
permissive · top 5,000 on PyPI
tree-sitter-phpProvides a PHP language grammar for…
permissive · top 5,000 on PyPI