vexy-glob¶
vexy-glob finds files and searches their contents from Python. The work
happens in a Rust extension module built on the ignore crate (the directory
walker behind fd) and the grep-searcher crate (the search engine behind
ripgrep). Python receives the matching paths as they are found, through an
iterator, so the first results arrive before the walk finishes.
The import name is vexy_glob. The PyPI package name is vexy-glob. The
command-line tool is vg.
What it does¶
You give it a glob pattern, a starting directory and optional filters. It walks
the directory tree on several threads, skips what .gitignore and hidden-file
rules exclude, applies your filters, and yields each path that passes.
With a project that contains src/a.py and src/sub/b.py, this prints:
The order can differ from run to run, because several threads walk the tree at
once. Pass sort="path" when you need a stable order.
Add a regular expression with content= (or call search()) and the tool reads
each matching file and yields one dictionary per matching line:
for hit in vexy_glob.search("TODO", "*.py", root="src"):
print(f"{hit['path']}:{hit['line_number']}:{hit['line_text'].rstrip()}")
Main features¶
- Streaming results.
find()returns an iterator by default. Passas_list=Trueto get a list. - Ignore rules.
.gitignore,.ignore,.git/info/excludeand a root.fdignorefile are honoured unless you passignore_git=True. - Filters. File type, extension, exclude patterns, size, modification time, access time, creation time and depth.
- Smart case. A pattern without uppercase letters matches case-insensitively. A pattern with an uppercase letter matches case-sensitively.
- Content search. Regular expressions in Rust
regexsyntax, run only on files that pass the path filters. globreplacements.vexy_glob.glob()andvexy_glob.iglob()accept the common arguments ofglob.glob()andglob.iglob().- CLI.
vg findandvg searchexpose the same engine in the terminal.
Where to go next¶
| Page | What it covers |
|---|---|
| Installation | Installing from PyPI and from source |
| Quickstart | A first session, step by step |
| Patterns and case | How glob patterns are matched against paths |
| Filters | Type, extension, exclude, size, time, depth, ignore files |
| Content search | Regex search inside files and the result format |
| Command line | The vg find and vg search commands |
| Python API | Every function, parameter and exception |
| Architecture | How the Rust core and the Python layer fit together |
| Troubleshooting | Empty results, errors and surprises |
| Contributing | Building, testing and releasing |