skillfed

tree-sitter-cmake

CMake grammar for tree-sitter

tree-sitter-cmake v0.7.2.post1 74.4K downloads/30d#14,847 on PyPI59
Permissive license MIT Active released

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-cmake

uv

uv add tree-sitter-cmake

poetry

poetry add tree-sitter-cmake

Installing 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

Intended Audience :: DevelopersTopic :: Software Development :: CompilersTopic :: Text Processing :: LinguisticTyping :: Typed

Tags

cmake parser pythontree-sitter cmake grammarcmake syntax treeincremental cmake parsingcmake ast extractioncmake code analysis
parsingcmakebuild-tools

More Linguistic packages