Registry / serialization / tree-sitter-swift

tree-sitter-swift

JSON →
library0.7.2pypypi✓ verified 89d ago

Swift grammar for tree-sitter, providing incremental parsing, syntax highlighting, and code analysis for the Swift programming language. Current version: 0.7.2. Released irregularly, with updates following Swift language evolution and tree-sitter releases.

pip install tree-sitter-swift
INSTALL
IMPORT
SIG · TREE-SITTER-SWIFT
T
tree-sitter-swift
serializationpythonv0.7.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

Language
✓ from tree_sitter_swift import language
✗ from tree_sitter_swift import Language
The correct export is a function `language()`, not a class `Language`.

Create a parser with the Swift language and parse a simple Swift snippet.

import tree_sitter as ts from tree_sitter_swift import language parser = ts.Parser(language()) tree = parser.parse(b"let x = 42") print(tree.root_node.type)
Debug
Known issues
breakingIn version 0.7.0, the grammar was updated to tree-sitter 0.23, introducing breaking changes in the tree-sitter API. Ensure you are using tree-sitter >= 0.23.0.
fix
Update tree-sitter to >=0.23.0: pip install 'tree-sitter>=0.23'
affects: >=0.7.0, <0.8.0
deprecatedThe import path from tree_sitter_swift import Language is deprecated. Use from tree_sitter_swift import language instead.
fix
Replace `from tree_sitter_swift import Language` with `from tree_sitter_swift import language` and call `language()`.
affects: >=0.5.0, <0.8.0
gotchaGrammar functions may be pickled incorrectly if you try to serialize the parser object with the grammar loaded.
fix
Re-create the parser and load the grammar after deserialization instead of pickling the parser directly.
affects: all
Errors
Common errors & fixes
AttributeError: module 'tree_sitter_swift' has no attribute 'Language'
Importing a non-existent attribute `Language`; the correct import is the function `language` without capital L.
fix
Change import to: from tree_sitter_swift import language
TypeError: Parser() takes no arguments
Passing the language object directly to `Parser()` in older tree-sitter versions (<0.23) or using the wrong API pattern.
fix
Use the newer API: parser = ts.Parser(language())
tree_sitter_swift does not provide bindings for version x.y.z
Attempting to install a version of `tree-sitter-swift` that does not have a prebuilt wheel for the current platform or Python version.
fix
Ensure you have Rust installed to compile from source, or use a version that supports your platform: pip install 'tree-sitter-swift>=0.7'
Upgrade
Version history
0.7.2latest on PyPI · released May 4, 2026
Audit
Dependencies
tree-sitterrequiredRequired to load and use the grammar; tree-sitter-swift provides only the grammar definition.
Agent activity
15 hits · last 30 days
node
14
OpenAI (training)
1
Resources
tree-sitter-swift — pip install tree-sitter-swift · libregistry