Skip to content

Releases: Py-Swift/PySwiftAST

Release list

0.0.1

Choose a tag to compare

@psychowasp psychowasp released this 08 Sep 17:11

Full Changelog: 0.0.0...0.0.1

0.0.0

Choose a tag to compare

@psychowasp psychowasp released this 16 Feb 23:27

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

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.