skillfed

tree-sitter-swift

Swift grammar for tree-sitter

tree-sitter-swift v0.7.3 1.9M downloads/30d#3,415 on PyPI217
Permissive license MIT Active released

What it is and what it does

tree-sitter-swift is a language grammar binding that plugs into the tree-sitter incremental parsing framework to parse Swift source code. It generates a syntax tree representation of Swift programs, which can be used for code analysis, transformation, linting, or IDE features. The package provides precompiled wheels for multiple platforms, eliminating the need to build the grammar locally in most cases.

The grammar is maintained actively and designed to work with tree-sitter's core parser engine. It can be used from Python, Rust, JavaScript/Node.js, or WebAssembly environments depending on which tree-sitter binding you pair it with. The package itself contains only the language definition; you supply the tree-sitter parser library separately to actually parse code.

Use it for:

  • Build a Swift linter or code quality checker that traverses the syntax tree to detect style violations.
  • Implement IDE features like syntax highlighting, code completion, or go-to-definition by querying the parse tree.
  • Analyze Swift codebases to extract metrics, find unused code, or refactor patterns across multiple files.
  • Create a Swift-to-other-language transpiler or code generator that walks the syntax tree and emits different output.
  • Develop a documentation generator that parses Swift source to extract and format API signatures and comments.

Worth the install?

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

Provides a tree-sitter grammar for parsing Swift source code, enabling incremental syntax analysis and abstract syntax tree generation.

Yes, if you need to parse Swift code programmatically. The package is actively maintained, has no known vulnerabilities, uses a permissive MIT license, and provides prebuilt wheels for common platforms. The main caveat is that tree-sitter itself must be available in your environment; verify that dependency is clear before installing.

Install

tree-sitter-swift on PyPI

pip

pip install tree-sitter-swift

uv

uv add tree-sitter-swift

poetry

poetry add tree-sitter-swift

Installing tree-sitter-swift

Before you install

Medium install friction due to compiled wheels; prebuilt binaries available for common platforms (macOS x86_64/arm64, Linux x86_64/aarch64, Windows x86_64/arm64, musl). Package is actively maintained with recent releases and no known vulnerabilities.

License in practice

MIT license permits commercial and private use with minimal restrictions; you may use, modify, and distribute the package provided you include the license notice.

Quickstart

pip install tree-sitter-swift

import tree_sitter_swift

language = tree_sitter_swift.language()

Python 3.8 or later required; tree-sitter parser library must be available separately in your environment.

Verify before relying

  • Whether tree-sitter is automatically installed as a transitive dependency or must be installed separately.
  • Performance characteristics when parsing large Swift codebases or in incremental update scenarios.
  • Completeness of Swift language coverage across recent Swift versions and all language constructs.

Package facts

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

Evidence: tree_sitter_swift-0.7.3-cp38-abi3-macosx_10_9_x86_64.whl; tree_sitter_swift-0.7.3-cp38-abi3-macosx_11_0_arm64.whl; tree_sitter_swift-0.7.3-cp38-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl; tree_sitter_swift-0.7.3-cp38-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl; tree_sitter_swift-0.7.3-cp38-abi3-musllinux_1_2_aarch64.whl; tree_sitter_swift-0.7.3-cp38-abi3-musllinux_1_2_x86_64.whl; tree_sitter_swift-0.7.3-cp38-abi3-win_amd64.whl; tree_sitter_swift-0.7.3-cp38-abi3-win_arm64.whl

Keywords: incremental, parsing, tree-sitter, swift

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

Tags

swift parser tree-sitterswift syntax tree parsingincremental swift code analysisswift grammar parsertree-sitter swift languageswift ast generationswift code parsing library
parsingswiftsyntax-analysis

More Linguistic packages

Further reading