--- id: grep-ast version: "0.9.0" license: unclear license_treatment: permissive maintenance: aging --- # grep-ast — A tool to grep through the AST of a source file License: permissive · Maintenance: aging · Downloads: 1.8M/mo ## 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 above — 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 pip install grep-ast uv add grep-ast 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: unspecified - Install friction: low - Maintenance: aging - Downloads: 1.8M/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags grep source code ast context, search code with syntax tree, find code patterns with context, grep-like tool for ast, code search with structure, search functions and classes, pattern matching in code, code-search, ast-parsing, cli-tool [View on SkillFed](https://skillfed.io/packages/grep-ast) · [View on PyPI](https://pypi.org/project/grep-ast/)