Skip to main content

grep-ast

Grep source code files and see matching lines with useful context that show how they fit into the code. See the loops, functions, methods, classes, etc that contain all the matching lines. Get a sense of what's inside a matched class or function definition. You see relevant code from every layer of the abstract syntax tree, above and below the matches.

By default, grep-AST recurses the current directory to search all source code files. It respects .gitignore, so it will usually "do the right thing" in most repos if you just do grep-ast <regex> without specifying any filenames.

You can also invoke grep-ast as gast for convenience.

Grep-AST is built with tree-sitter and tree-sitter-languages. So it supports a lot of popular code languages.

Install

python -m pip install git+https://github.com/paul-gauthier/grep-ast.git

Usage

Basic usage:

grep-ast [pattern] [filenames...]

Full options list:

usage: grep_ast.py [-h] [-i] [--color] [--no-color] [--encoding ENCODING] [--languages] [--verbose]
                   [pat] [filenames ...]

positional arguments:
  pat                  the pattern to search for
  filenames            the files to display

options:
  -h, --help           show this help message and exit
  -i, --ignore-case    ignore case distinctions
  --color              force color printing
  --no-color           disable color printing
  --encoding ENCODING  file encoding
  --languages          print the parsers table
  --verbose            enable verbose output

Examples

Here we search for "encoding" in the source to this tool. These results mainly highlight how grep-ast shows you how the matches fit into the code base.

aider screencast

Here we search for "TreeContext" in the source to this tool. These results mainly highlight how grep-ast helps you understand the contents of a matching named code block (class, function, method, etc).

aider screencast

Release files for grep-ast 0.9.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for grep-ast 0.9.0
File Size Uploaded
grep_ast-0.9.0.tar.gz 14.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for grep-ast 0.9.0
File Interpreter ABI Platform
grep_ast-0.9.0-py3-none-any.whl Python 3 none any Details

Total release size: 28.0 kB

Release files / grep_ast-0.9.0.tar.gz

Download URL grep_ast-0.9.0.tar.gz
Size 14.1 kB
Tags Source
SHA-256 checksum
How to use checksums
620a242a4493e6721338d1c9a6c234ae651f8774f4924a6dcf90f6865d4b2ee3
BLAKE2b-256 checksum
How to use checksums
6782a87079945a7c15d242cb586ae22e17952132439eaa9c878ec5fbdc61c54d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.6

Release files / grep_ast-0.9.0-py3-none-any.whl

Download URL grep_ast-0.9.0-py3-none-any.whl
Size 13.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a3973dca99f1abc026a01bbbc70e00a63860c8ff94a56182ff18b089836826d7
BLAKE2b-256 checksum
How to use checksums
407929f1373b2ce1eec37c03aefbc17194c2470d8b61ede288e5043231825999
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.6

Release history Release notifications | RSS feed

This release

0.9.0 This release

2 release files

0.8.1

2 release files

0.8.0

1 release file

0.7.2

2 release files

0.7.1

2 release files

0.7.0

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page