ast-grep-py
Structural Search and Rewrite code at large scale using precise AST pattern.
Decision gist · record as of 2026-08-14
Yes, if you need structural code search or rewriting beyond regex. The package is actively maintained, has no security vulnerabilities, uses a permissive MIT license, and is well-distributed across platforms. Medium install friction is acceptable for a compiled tool. Start with the official API guide to confirm the pattern syntax and API surface fit your use case.AI-flagged interpretation of the facts on this page — verify before relying
Before you install
- Requires Python 3.8 or later; prebuilt wheels are available for common platforms, but installation may require a Rust toolchain if building from source.
- Medium install friction due to compiled wheels, but well-supported across multiple Python versions on Linux, macOS, and Windows.
- Active maintenance with a release 7 days old and 15516 repository stars.
License · maintenance · safety
MIT (permissive) — MIT license is permissive; you may use, modify, and distribute this package freely in commercial or private projects with minimal restrictions.
last release 2026-08-07 (7 days) · last repo commit 2026-08-14 · 15,516 stars
0 known vulnerabilities (OSV.dev, 2026-08-14) · 1,163,264 downloads/mo, #4,281 on PyPI
Alternatives
Verify before relying
pip install ast-grep-py
# See https://ast-grep.github.io/guide/api-usage.html for pattern and search examples- Whether the package provides a high-level convenience API or requires deep familiarity with AST and pattern syntax to be productive.
- Performance characteristics when searching or rewriting large codebases.
- Availability of pattern libraries or templates for common refactoring tasks.
- Concrete example of how to invoke the binding's main entry points after import.
What it is and what it does
ast-grep-py exposes ast-grep's code search and rewriting engine to Python programs. It lets you define patterns that match code structure—not just text—and then find, analyze, or transform matching code at scale. The package is a native Rust binding compiled to wheels, so it has no Python runtime dependencies and runs efficiently on modern Python versions.
You would use this when you need to perform structural code analysis or refactoring that text regex cannot handle: finding all calls to a deprecated function across a codebase, rewriting patterns to use a new API, or enforcing code style rules based on syntax tree shape. The API is programmatic, so you integrate it into scripts, linters, or CI pipelines rather than using a command-line tool.
Use it for
- Search for and refactor all uses of a deprecated API across a large codebase in one pass.
- Enforce custom code style rules by matching specific AST patterns and flagging violations.
- Automate codemod tasks—e.g., migrate from one library to another—by pattern-matching and rewriting code structure.
- Build custom linters that detect anti-patterns or security issues based on syntax tree shape.
- Analyze code structure programmatically to gather metrics or generate reports on code patterns.
Worth the install?
AI-flagged interpretation of the facts on this page. Verify before relying on it.
Yes, if you need structural code search or rewriting beyond regex.
The package is actively maintained, has no security vulnerabilities, uses a permissive MIT license, and is well-distributed across platforms. Medium install friction is acceptable for a compiled tool. Start with the official API guide to confirm the pattern syntax and API surface fit your use case.
Install
ast-grep-py on PyPI
Before you install
Medium install friction due to compiled wheels, but well-supported across multiple Python versions on Linux, macOS, and Windows. Active maintenance with a release 7 days old and 15516 repository stars.
Requires Python 3.8 or later; prebuilt wheels are available for common platforms, but installation may require a Rust toolchain if building from source.
License in practice
MIT license is permissive; you may use, modify, and distribute this package freely in commercial or private projects with minimal restrictions.
Quickstart
pip install ast-grep-py
# See https://ast-grep.github.io/guide/api-usage.html for pattern and search examples
Verify before relying
- Whether the package provides a high-level convenience API or requires deep familiarity with AST and pattern syntax to be productive.
- Performance characteristics when searching or rewriting large codebases.
- Availability of pattern libraries or templates for common refactoring tasks.
- Concrete example of how to invoke the binding's main entry points after import.
Package facts
| License | MIT permissive |
| Python support | Supports the current Python release >=3.8 |
| Install friction | Medium. Platform-specific wheel |
| Runtime dependencies | None |
| Maintenance | Actively maintained 7 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 1,163,264 / month, #4,281 on PyPI 30-day window, as of 2026-08-14 |
| Known vulnerabilities | None known OSV.dev, checked 2026-08-14 |
| Classifiers | Development Status :: 3 - AlphaEnvironment :: ConsoleIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: RustTopic :: SecurityTopic :: Software DevelopmentTopic :: Software Development :: Quality AssuranceTopic :: Text Processing |
Evidence: ast_grep_py-0.45.1-cp310-cp310-manylinux_2_28_aarch64.whl; ast_grep_py-0.45.1-cp310-cp310-manylinux_2_28_x86_64.whl; ast_grep_py-0.45.1-cp310-cp310-win32.whl; ast_grep_py-0.45.1-cp310-cp310-win_amd64.whl; ast_grep_py-0.45.1-cp311-cp311-macosx_10_12_x86_64.whl; ast_grep_py-0.45.1-cp311-cp311-macosx_11_0_arm64.whl; ast_grep_py-0.45.1-cp311-cp311-manylinux_2_28_aarch64.whl; ast_grep_py-0.45.1-cp311-cp311-manylinux_2_28_x86_64.whl; ast_grep_py-0.45.1-cp311-cp311-win32.whl; ast_grep_py-0.45.1-cp311-cp311-win_amd64.whl; ast_grep_py-0.45.1-cp312-cp312-macosx_10_12_x86_64.whl; ast_grep_py-0.45.1-cp312-cp312-macosx_11_0_arm64.whl; ast_grep_py-0.45.1-cp312-cp312-manylinux_2_28_aarch64.whl; ast_grep_py-0.45.1-cp312-cp312-manylinux_2_28_x86_64.whl; ast_grep_py-0.45.1-cp312-cp312-win32.whl; ast_grep_py-0.45.1-cp312-cp312-win_amd64.whl; ast_grep_py-0.45.1-cp313-cp313-macosx_10_12_x86_64.whl; ast_grep_py-0.45.1-cp313-cp313-macosx_11_0_arm64.whl; ast_grep_py-0.45.1-cp313-cp313-manylinux_2_28_aarch64.whl; ast_grep_py-0.45.1-cp313-cp313-manylinux_2_28_x86_64.whl
Tags
Let your AI agent find packages like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 14,416 PyPI packages by what they can do, searchable in plain language.
wish › “syntax tree pattern matching”
- ast-grep-pyast-grep-py is a Python binding for ast-grep, a tool that searches,…
- ast-grep-cliast-grep-cli is a command-line tool for searching, linting, and…
- grep-astSearch source code files by pattern and display matching lines with…
Give your agent the search over MCP, or paste the wish link into any chat.
More Software Development packages
Provides backported and experimental type hints for Python 3.9+, allowing use of newer typing features on older Python versions and enabling early experimentation with type system PEPs before they enter the standard library.
NumPy provides an N-dimensional array object and a comprehensive suite of mathematical, linear algebra, Fourier transform, and random number functions for scientific computing in Python.
FastAPI is a Python web framework for building REST APIs using type hints, with automatic request validation, serialization, and interactive API documentation.
Provides a way to document function parameters, class attributes, return types, and variables inline using Python's `Annotated` type hint syntax instead of traditional docstrings.
Typer builds command-line applications from Python functions using type hints, automatically generating help text, argument parsing, and shell completion.
Install it if you are building CLIs in Python.
Distlib provides low-level packaging utilities for building, distributing, and managing Python software—including metadata handling, version specifiers, wheel support, script installation, and dependency resolution.
See also ast-grep-cli · gritql · tensor-grep · ast-serialize · grep-ast · libcst · ignore-python · ast-decompiler · astor · rtest