--- id: gast version: "0.7.0" license: BSD 3-Clause license_treatment: permissive maintenance: active --- # gast — Python AST that abstracts the underlying Python version License: permissive · Maintenance: active · Downloads: 20.1M/mo ## What it is and what it does GAST is a compatibility layer that normalizes Python's Abstract Syntax Tree across different Python versions. It converts version-specific AST output from the standard ast module into a unified representation, then back again if needed. This solves the problem of AST structure differences between Python 2.7 and Python 3.x versions—for instance, how function arguments, exception handlers, and string literals are represented differently across versions. The package provides the same API as the standard ast module, with three key additions: gast.parse() produces a normalized tree directly, gast.dump() shows the unified representation, and gast.ast_to_gast() / gast.gast_to_ast() handle bidirectional conversion. It's tested across Python 2.7 through 3.11, making it suitable for tools that need to analyze or transform code written for multiple Python versions without rewriting logic for each version's AST quirks. Use it for: - Building code analysis or refactoring tools that must work with codebases targeting multiple Python versions - Writing AST-based linters or formatters that need a single code path for Python 2 and 3 syntax - Implementing code generation or transpilation that normalizes input AST before processing - Analyzing legacy Python 2 code alongside modern Python 3 code in a unified framework ## Worth the install? AI-flagged interpretation of the facts above — verify before relying. Provides a unified Abstract Syntax Tree representation that works across Python 2 and Python 3 versions, converting between the standard ast module's version-specific trees and a normalized GAST format. Yes. GAST is a low-friction, actively maintained utility with no dependencies, a permissive license, and zero known vulnerabilities. Install it if you're building tools that parse or analyze Python code across multiple versions and need to avoid version-specific AST branching logic. ## Install pip install gast uv add gast poetry add gast ## Installing gast Before you install: Installation is straightforward with no runtime dependencies. The package is actively maintained with a recent release and steady commit activity, making it reliable for production use. License in practice: Licensed under BSD 3-Clause, a permissive license that allows free use, modification, and distribution with minimal restrictions, suitable for both open-source and commercial projects. Quickstart: import ast import gast code = "x = 1 + 2" tree = ast.parse(code) gtree = gast.ast_to_gast(tree) # Process gtree with version-independent AST original_tree = gast.gast_to_ast(gtree) Verify before relying: - Whether the package is actively used by major tools or frameworks that depend on cross-version AST compatibility - Performance characteristics when converting large or deeply nested ASTs ## Package facts - License: BSD 3-Clause (permissive) - Python support: supports_current - Install friction: low - Maintenance: active - Downloads: 20.1M/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags python ast compatibility layer, cross-version abstract syntax tree, ast normalization python 2 3, unified ast representation, ast conversion between python versions, generic ast parser, python version-agnostic ast, ast-parsing, code-analysis, python-compatibility [View on SkillFed](https://skillfed.io/packages/gast) · [View on PyPI](https://pypi.org/project/gast/)