0.0.0
PySwiftAST v0.0.0 — Initial Release
A Python 3.13 AST parser and code generator written in pure Swift. Parse Python code without requiring a Python runtime.
Highlights
- Complete Python 3.13 syntax coverage — all statements, expressions, operators, literals, pattern matching (3.10+), type parameters (3.12+), and async/await
- Pure Swift — no Python interpreter required; works anywhere Swift runs (macOS, Linux, iOS)
- Thread-safe — all AST types conform to
Sendable
Libraries Included
| Library | Description |
|---|---|
| PySwiftAST | Tokenizer, recursive-descent parser, and full AST node definitions (28 modular files) |
| PySwiftCodeGen | Generate Python source code from an AST with round-trip support |
| PyFormatters | Code formatting utilities (Black-style, YAPF-style) |
| PyChecking | Type checking and static analysis |
| PyAstVisitors | AST visitor / walker infrastructure |
Parser Features
- Tokenizer — 130+ token types, indentation-aware (INDENT/DEDENT), all string literal kinds (raw, f-strings, triple-quoted, bytes), all number formats
- Parser — 3,200+ line recursive-descent parser with operator-precedence climbing, error recovery, and full comprehension / pattern-matching support
- Code Generator — AST to Python source with proper indentation; enables parse, generate, re-parse round-trips
Performance
- 5.4x faster tokenization than CPython
- 1.17x faster parsing than CPython
- 2.93x faster round-trip (parse, codegen, reparse)
Requirements
- Swift 6.1+ (swift-tools-version 6.1)
- Dependency: swift-algorithms >= 1.2.0
Installation
Add to your Package.swift:
dependencies: [
.package(url: "https://github.com/Py-Swift/PySwiftAST.git", from: "0.0.0"),
]Quick Example
import PySwiftAST
let source = """
def greet(name: str) -> str:
return f"Hello {name}"
"""
let ast = try parsePython(source)This is the initial public release (v0.0.0). APIs may evolve in future versions.