skillfed

grep-ast

A tool to grep through the AST of a source file

grep-ast v0.9.0 1.8M downloads/30d#3,574 on PyPI362
Permissive license AGING released

What it is and what it does

grep-ast is a command-line search tool that finds patterns in source code and displays matching lines along with their syntactic context—the enclosing functions, classes, loops, and other code blocks they belong to. It uses tree-sitter to parse code into an abstract syntax tree, then shows you not just the match but how it fits into the broader structure of the file. This is useful when you need to understand not just where a pattern appears, but what code context surrounds it.

The tool respects .gitignore by default and recurses through directories, so you can run it from a repository root without specifying files. It supports many popular programming languages via tree-sitter-language-pack and can be invoked as either `grep-ast` or `gast`. It offers basic options like case-insensitive matching, color control, and encoding specification.

Use it for:

  • Find all uses of a function name and see which functions or classes call it and in what context
  • Search for a variable name and understand the scope and surrounding logic where it appears
  • Locate a specific pattern across a codebase and see the class or method definitions that contain each match
  • Explore a large unfamiliar codebase by searching for key terms and seeing their structural context
  • Refactor code by finding all occurrences of a pattern and understanding their relationships to surrounding code

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Search source code files by pattern and display matching lines with their surrounding context in the abstract syntax tree, showing how matches fit into functions, classes, loops, and other code structures.

Yes, if you work with source code search and want to understand context. Low install friction and permissive license make it a low-risk addition. Aging maintenance (463 days since last release) is a minor concern but the repository is active and has reasonable adoption. No known vulnerabilities. Install if you need AST-aware code search; skip if you only need simple text grep.

Install

grep-ast on PyPI

pip

pip install grep-ast

uv

uv add grep-ast

poetry

poetry add grep-ast

Installing grep-ast

Before you install

Low install friction; pure Python wheel. Maintenance status is aging—last release was 463 days ago—but the repository is active and not archived, with 362 stars.

License in practice

Licensed under Apache Software License (permissive), so you can use, modify, and distribute the package freely with minimal restrictions.

Quickstart

pip install grep-ast

grep-ast 'pattern' /path/to/code
# or with options:
grep-ast -i --color 'pattern' src/

Verify before relying

  • Whether Python version support is truly unspecified or if there is a practical minimum version requirement
  • How well the tool handles very large codebases or deeply nested syntax trees
  • Whether the .gitignore-respecting behavior works correctly across all supported operating systems

Package facts

License not declared (permissive)
Python support not specified
Install friction low — pure-Python wheel
Runtime dependencies 2 — tree-sitter-language-pack, pathspec
Maintenance aging — 463 days since the last release
Last repo commit
First released
Downloads 1,768,321/month — #3,574 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: grep_ast-0.9.0-py3-none-any.whl

License :: OSI Approved :: Apache Software License

Tags

grep source code ast contextsearch code with syntax treefind code patterns with contextgrep-like tool for astcode search with structuresearch functions and classespattern matching in code
code-searchast-parsingcli-tool

More Software Development packages