skillfed

tree-sitter-cpp

C++ grammar for tree-sitter

tree-sitter-cpp v0.23.4 4.8M downloads/30d#2,231 on PyPI445
Permissive license MIT Active released

What it is and what it does

tree-sitter-cpp is a C++ language grammar for the tree-sitter incremental parsing framework. It translates C++ source code into syntax trees that can be traversed and analyzed programmatically. The package ships as prebuilt binary wheels for major platforms, avoiding compilation on installation.

The grammar enables use cases like code analysis, refactoring tools, linters, and IDE features that need to understand C++ structure. It integrates with tree-sitter's ecosystem and follows the C++ BNF specification, supporting incremental updates when code changes rather than reparsing from scratch.

Use it for:

  • Build code analysis and linting tools that need to parse and inspect C++ syntax trees.
  • Implement IDE features like syntax highlighting, code navigation, and refactoring for C++ editors.
  • Analyze C++ codebases to extract metrics, dependencies, or patterns without invoking a full compiler.
  • Create documentation generators or code transformation tools that operate on C++ ASTs.
  • Develop static analysis or security scanning tools that examine C++ code structure.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Provides a C++ language grammar for tree-sitter, enabling incremental parsing and syntax tree generation for C++ code.

Yes, if you need C++ parsing within a Python application and are already using or planning to use tree-sitter. The permissive MIT license, active maintenance, and prebuilt wheels for common platforms make it a low-friction choice. No known security vulnerabilities. Verify that your use case aligns with tree-sitter's incremental parsing model and that you have or will install the core tree-sitter Python bindings separately.

Install

tree-sitter-cpp on PyPI

pip

pip install tree-sitter-cpp

uv

uv add tree-sitter-cpp

poetry

poetry add tree-sitter-cpp

Installing tree-sitter-cpp

Before you install

Medium install friction due to binary wheels for multiple platforms (macOS, Linux, Windows, ARM); prebuilt binaries available for Python 3.9+ reduce compilation overhead. Repository is actively maintained with recent commits.

License in practice

MIT license permits unrestricted use, modification, and distribution in both open-source and commercial projects with minimal restrictions.

Quickstart

pip install tree-sitter-cpp

from tree_sitter_cpp import language

parser = language.parser()
tree = parser.parse(b'int main() { return 0; }')

Requires Python 3.9 or later; prebuilt wheels available for common platforms but may require compilation on unsupported architectures.

Verify before relying

  • Whether the package provides direct parsing APIs or requires a separate tree-sitter Python binding to be installed alongside it.
  • Performance characteristics and memory overhead for parsing large C++ files or codebases.
  • Completeness of C++ standard coverage (C++11, C++17, C++20, etc.) in the grammar.

Package facts

License MIT (permissive)
Python support supports the current Python release (>=3.9)
Install friction medium — platform-specific wheel
Runtime dependencies none
Maintenance actively maintained — 641 days since the last release
Last repo commit
First released
Downloads 4,786,023/month — #2,231 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: tree_sitter_cpp-0.23.4-cp39-abi3-macosx_10_9_x86_64.whl; tree_sitter_cpp-0.23.4-cp39-abi3-macosx_11_0_arm64.whl; tree_sitter_cpp-0.23.4-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl; tree_sitter_cpp-0.23.4-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl; tree_sitter_cpp-0.23.4-cp39-abi3-musllinux_1_2_x86_64.whl; tree_sitter_cpp-0.23.4-cp39-abi3-win_amd64.whl; tree_sitter_cpp-0.23.4-cp39-abi3-win_arm64.whl

Keywords: incremental, parsing, tree-sitter, cpp

Intended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseTopic :: Software Development :: CompilersTopic :: Text Processing :: LinguisticTyping :: Typed

Tags

c++ parsing grammartree-sitter c++ languageincremental c++ parsersyntax tree c++c++ code analysistree-sitter language bindingc++ ast generation
parsingc++-grammarsyntax-analysis

More Linguistic packages

Further reading