gast
Python AST that abstracts the underlying Python version
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 on this page — 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
gast on PyPI
pip
pip install gastuv
uv add gastpoetry
poetry add gastInstalling 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 the current Python release (!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,>=2.7) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | actively maintained — 258 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 20,135,601/month — #1,044 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: gast-0.7.0-py3-none-any.whl
Tags
More Software Development packages
Provides backported and experimental type hints…
permissive · top 100 on PyPI
numpyNumPy provides an N-dimensional array object…
permissive · top 100 on PyPI
fastapiFastAPI is a Python web framework for building…
permissive · top 100 on PyPI
annotated-docProvides a way to document function parameters,…
permissive · top 100 on PyPI
typerTyper builds command-line applications from…
permissive · top 1,000 on PyPI
distlibDistlib provides low-level packaging utilities…
permissive · top 1,000 on PyPI
astprettyPretty-print Python abstract syntax trees (AST)…
permissive · top 15,000 on PyPI
benigetBeniget performs compile-time analysis on…
permissive · top 15,000 on PyPI
parsoParso is a Python parser that recovers from…
permissive · top 1,000 on PyPI
asttokensAnnotates Python abstract syntax trees with the…
permissive · top 1,000 on PyPI
ast-commentsExtends Python's built-in `ast` module to…
permissive · top 15,000 on PyPI
astunparseConverts Python abstract syntax trees (ASTs)…
permissive · top 5,000 on PyPI
ast-decompilerConverts Python abstract syntax trees (ASTs)…
permissive · top 15,000 on PyPI
astorastor converts Python abstract syntax trees…
permissive · top 5,000 on PyPI
luaparserParses Lua source code into an abstract syntax…
permissive · top 15,000 on PyPI
PyMeta3PyMeta3 compiles pattern-matching grammars…
permissive · top 15,000 on PyPI