Python API for ripgrep-style file walking and searching
Project description
rgapi
rgapi is a Python API for ripgrep-style walking and search. It is meant for Python code that wants fd-style file discovery or rg-style searching without shelling out.
It uses the same ignore, grep-regex, and grep-searcher crates that ripgrep uses for walking, regex matching, and file scanning. Walking and searching run in parallel by default. Most expensive work stays in Rust.
Overview
For common file discovery and search:
from rgapi import fd, rg, rg_iter
fd(".", ext="py", exclude="test_*.py")
for row in rg_iter("TODO", ".", include="*.py", context=2): print(row.asdict())
rg("TODO", ".", ext="py", skip_dir=".venv", paths=True)
For cell-aware search of Jupyter notebooks (see Notebooks):
from rgapi import nbrg
nbrg("read_csv", ".", cell_context=1)
For direct access to the regex, search, and walk pieces:
from rgapi import compile, search_path, search_text, walk
matcher = compile("TODO")
matcher.is_match("TODO")
matcher.finditer("TODO TODO")
walk(".")
search_text(matcher, "alpha\nTODO\nomega\n", path="memory.txt", context=1)
search_path(matcher, "src/lib.rs", display_path="src/lib.rs")
Install
pip install rgapi
Semantics
fd and walk return slash-separated paths relative to root. They use the ignore crate, so .gitignore, .ignore, and the usual ripgrep filters apply by default. .rgignore files are also honored and take precedence over .gitignore. Hidden files are skipped unless hidden=True. Pass ignore=False to disable all ignore filtering (including .rgignore). Symlinks are not followed unless follow_links=True; same_file_system=True avoids crossing filesystem boundaries. Traversal is parallel, and result order is not guaranteed; use sorted(...) if order matters.
root arguments accept str or pathlib.Path and expand ~; search_path also accepts path-like file paths. Display labels such as display_path are stringified without expansion.
fd adds fd-like filtering on top of walk: pattern is a substring match on the relative path, and include/exclude use glob syntax. glob= is accepted as an alias for include=. A basename glob such as *.py also matches recursively, so it finds src/app.py. Use ext="py" or ext=["py", "rs"] for extension filters, min_depth=/max_depth= to bound recursion, and max_filesize= to skip files above a byte limit.
path_re and skip_path_re are regex filters on slash-separated relative paths. They filter returned paths or searched files, but do not control traversal. skip_dir uses glob syntax to prune matching directory subtrees, and skip_dir_re does the same with regex.
rg and rg_iter return structured rows rather than raw CLI text. They accept the same include, exclude, glob, ext, path_re, skip_path_re, skip_dir, skip_dir_re, min_depth, max_depth, max_filesize, follow_links, and same_file_system filters as fd. Each row is a SearchLine with:
kind 'match', 'before', 'after', or 'context'
path path relative to root
line_number 1-based line number
line line text without the trailing newline
matches list of (start, end) byte offsets for match rows
rg, search_text, and search_path return SearchResults by default, a list subclass whose str() and notebook pretty display are rg-style multiline text. rg_iter yields rows lazily.
SearchLine has a structured repr, an rg-style str, and SearchLine.asdict() returns row fields as a plain Python dict. rg(..., paths=True) returns unique matched paths, and rg(..., count=True) returns the total number of match spans. paths and count cannot both be set.
before_context, after_context, and context are like rg -B, rg -A, and rg -C. Files containing NUL bytes or invalid UTF-8 are skipped.
Search is case-sensitive by default, matching rg. Use smart_case=True for rg --smart-case behavior, or case_sensitive=False to force case-insensitive matching.
Notebooks
nbrg searches Jupyter .ipynb files cell-by-cell, so results are cells rather than raw JSON lines. Searching a notebook with plain rg matches the escaped JSON text (including outputs and metadata) and reports JSON line numbers; nbrg instead searches each cell's reconstructed source and returns the cells that matched.
from rgapi import nbrg
nbrg("read_csv", ".") # cells whose source matches, across all notebooks under "."
nbrg("read_csv", ".", cell_context=1) # also include neighbouring cells as context
It finds notebooks with the fast parallel Rust walker (fd), then matches each cell's source through the same Rust engine as rg (via search_text), so regex behaviour and the case_sensitive/smart_case flags match rg. Only cell source is searched, not outputs or metadata. nbrg accepts the same discovery filters as fd/rg (include, exclude, glob, hidden, max_depth, skip_dir, …).
nbrg returns NbResults, a list of NbCell. Each NbCell has:
path notebook path relative to root
cell_index 0-based position of the cell in the notebook
cell_id nbformat cell id (falls back to the cell index for notebooks without ids)
cell_type 'code', 'markdown', or 'raw'
kind 'match' or 'context'
source full cell source
matches list of SearchLine rows for the matched lines within the cell
NbCell.asdict() returns those fields as a plain dict (with matches as SearchLine dicts). str()/pretty display is one truncated, newline-escaped line per cell: path:cell_id:source for matches and path:cell_id-source for context cells. A cell with several matches appears once, with every hit collected in matches.
cell_context=N includes the N cells before and after each matching cell as kind="context" rows (deduplicated per notebook). prefilter=True first narrows candidate notebooks with rg before the per-cell search; it is faster on notebook-heavy trees but can miss matches whose pattern is affected by JSON escaping (quotes, backslashes, regex metacharacters straddling escapes), so it is off by default.
Benchmarks
tools/bench.py compares the rg CLI with in-process rgapi. Run it against a release build. One run on this machine, using best time from seven repeats:
| fixture | rg | rgapi |
|---|---|---|
| 6 x 2 MB files, 2 matches | 6.54 ms | 1.44 ms |
| 800 x 1.5 KB files, 2 matches | 13.90 ms | 10.94 ms |
| tiny dir, repeated 30x | 5.92 ms | 2.14 ms |
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rgapi-0.1.9.tar.gz.
File metadata
- Download URL: rgapi-0.1.9.tar.gz
- Upload date:
- Size: 24.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3ef5717db4069a9deac1e1aa535ebea8ca5454f3c2c0066b3ae5b04b6984a4e3
|
|
| MD5 |
5e711b141aff84ccb4a11e4acfa27177
|
|
| BLAKE2b-256 |
fed7cc55787dfc343b7a2ab2d700b389814574ba3bec175943a731cc8f577e9d
|
Provenance
The following attestation bundles were made for rgapi-0.1.9.tar.gz:
Publisher:
ci.yml on AnswerDotAI/rgapi
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rgapi-0.1.9.tar.gz -
Subject digest:
3ef5717db4069a9deac1e1aa535ebea8ca5454f3c2c0066b3ae5b04b6984a4e3 - Sigstore transparency entry: 1947912483
- Sigstore integration time:
-
Permalink:
AnswerDotAI/rgapi@6a655fea9ab7a94d8aa8b3e075778b18742e3b09 -
Branch / Tag:
refs/tags/v0.1.9 - Owner: https://github.com/AnswerDotAI
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@6a655fea9ab7a94d8aa8b3e075778b18742e3b09 -
Trigger Event:
push
-
Statement type:
File details
Details for the file rgapi-0.1.9-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: rgapi-0.1.9-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 1.6 MB
- Tags: CPython 3.13, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4161bce320a72cf6d50bdd1c001d12dc629ec17e6e32d911f71e9bc649f8c19d
|
|
| MD5 |
52251656f4f8b3d4f64e7a90400a304c
|
|
| BLAKE2b-256 |
d2a0dc071bd91869c7b7fa23e5f718d2512e8b53d7d13ea0962995a9da86ffd0
|
Provenance
The following attestation bundles were made for rgapi-0.1.9-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
ci.yml on AnswerDotAI/rgapi
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rgapi-0.1.9-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
4161bce320a72cf6d50bdd1c001d12dc629ec17e6e32d911f71e9bc649f8c19d - Sigstore transparency entry: 1947912866
- Sigstore integration time:
-
Permalink:
AnswerDotAI/rgapi@6a655fea9ab7a94d8aa8b3e075778b18742e3b09 -
Branch / Tag:
refs/tags/v0.1.9 - Owner: https://github.com/AnswerDotAI
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@6a655fea9ab7a94d8aa8b3e075778b18742e3b09 -
Trigger Event:
push
-
Statement type:
File details
Details for the file rgapi-0.1.9-cp313-cp313-macosx_11_0_arm64.whl.
File metadata
- Download URL: rgapi-0.1.9-cp313-cp313-macosx_11_0_arm64.whl
- Upload date:
- Size: 1.4 MB
- Tags: CPython 3.13, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
33fff934c4570d6963b6f7e9f3d6966431d6a4623ee5230178f8f14ceb0c8436
|
|
| MD5 |
32050c81d74bcb27d52dacba1cfaeec4
|
|
| BLAKE2b-256 |
9f5ce9f32e31da1c0e7210ae5327ddf1abe3b779a32560c6e1b2dbc6ce6dc207
|
Provenance
The following attestation bundles were made for rgapi-0.1.9-cp313-cp313-macosx_11_0_arm64.whl:
Publisher:
ci.yml on AnswerDotAI/rgapi
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rgapi-0.1.9-cp313-cp313-macosx_11_0_arm64.whl -
Subject digest:
33fff934c4570d6963b6f7e9f3d6966431d6a4623ee5230178f8f14ceb0c8436 - Sigstore transparency entry: 1947913515
- Sigstore integration time:
-
Permalink:
AnswerDotAI/rgapi@6a655fea9ab7a94d8aa8b3e075778b18742e3b09 -
Branch / Tag:
refs/tags/v0.1.9 - Owner: https://github.com/AnswerDotAI
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@6a655fea9ab7a94d8aa8b3e075778b18742e3b09 -
Trigger Event:
push
-
Statement type:
File details
Details for the file rgapi-0.1.9-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: rgapi-0.1.9-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 1.6 MB
- Tags: CPython 3.12, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
97e81419b631f76f0eb9fd2ee516ededf9cd58da2168ef20047290f87b5c2b21
|
|
| MD5 |
0844de06646331865d6f6392ab402a97
|
|
| BLAKE2b-256 |
20c6d342236e0759b14da4bdfbded234706d8cb758a955e25ee4b40021e5c8c7
|
Provenance
The following attestation bundles were made for rgapi-0.1.9-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
ci.yml on AnswerDotAI/rgapi
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rgapi-0.1.9-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
97e81419b631f76f0eb9fd2ee516ededf9cd58da2168ef20047290f87b5c2b21 - Sigstore transparency entry: 1947913072
- Sigstore integration time:
-
Permalink:
AnswerDotAI/rgapi@6a655fea9ab7a94d8aa8b3e075778b18742e3b09 -
Branch / Tag:
refs/tags/v0.1.9 - Owner: https://github.com/AnswerDotAI
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@6a655fea9ab7a94d8aa8b3e075778b18742e3b09 -
Trigger Event:
push
-
Statement type:
File details
Details for the file rgapi-0.1.9-cp312-cp312-macosx_11_0_arm64.whl.
File metadata
- Download URL: rgapi-0.1.9-cp312-cp312-macosx_11_0_arm64.whl
- Upload date:
- Size: 1.4 MB
- Tags: CPython 3.12, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
44f32842b40e31fb2e17e6ee9665009e70d94e9a0d3312fba8d581ec7f74b025
|
|
| MD5 |
241da89238ae56ce1d761551cf658bfd
|
|
| BLAKE2b-256 |
d3313a28f24591b553c90b9dfc6932bd359b45a79b86bfef6a557755fd60ce1e
|
Provenance
The following attestation bundles were made for rgapi-0.1.9-cp312-cp312-macosx_11_0_arm64.whl:
Publisher:
ci.yml on AnswerDotAI/rgapi
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rgapi-0.1.9-cp312-cp312-macosx_11_0_arm64.whl -
Subject digest:
44f32842b40e31fb2e17e6ee9665009e70d94e9a0d3312fba8d581ec7f74b025 - Sigstore transparency entry: 1947912735
- Sigstore integration time:
-
Permalink:
AnswerDotAI/rgapi@6a655fea9ab7a94d8aa8b3e075778b18742e3b09 -
Branch / Tag:
refs/tags/v0.1.9 - Owner: https://github.com/AnswerDotAI
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@6a655fea9ab7a94d8aa8b3e075778b18742e3b09 -
Trigger Event:
push
-
Statement type:
File details
Details for the file rgapi-0.1.9-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: rgapi-0.1.9-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 1.6 MB
- Tags: CPython 3.11, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9ed495aa9652bb0396636e0b0df2f193af753565778fb59f4f9ade397bf0f7c5
|
|
| MD5 |
c485a199b799e2d398299e06778d9262
|
|
| BLAKE2b-256 |
eefe82619ad875f8cece589e743d61d055d159435d284c1eaf2b77272a3deae8
|
Provenance
The following attestation bundles were made for rgapi-0.1.9-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
ci.yml on AnswerDotAI/rgapi
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rgapi-0.1.9-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
9ed495aa9652bb0396636e0b0df2f193af753565778fb59f4f9ade397bf0f7c5 - Sigstore transparency entry: 1947913205
- Sigstore integration time:
-
Permalink:
AnswerDotAI/rgapi@6a655fea9ab7a94d8aa8b3e075778b18742e3b09 -
Branch / Tag:
refs/tags/v0.1.9 - Owner: https://github.com/AnswerDotAI
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@6a655fea9ab7a94d8aa8b3e075778b18742e3b09 -
Trigger Event:
push
-
Statement type:
File details
Details for the file rgapi-0.1.9-cp311-cp311-macosx_11_0_arm64.whl.
File metadata
- Download URL: rgapi-0.1.9-cp311-cp311-macosx_11_0_arm64.whl
- Upload date:
- Size: 1.4 MB
- Tags: CPython 3.11, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
deb124beeef7b39afdb98169660acb21f0d15d09b5816d77bef9cf6917bd7d06
|
|
| MD5 |
5805a2a93db002be8546118b1a683180
|
|
| BLAKE2b-256 |
006a08f0e7f38ce0719b065ac327f36d917bc7032c5d51adea75e2556f60b6a6
|
Provenance
The following attestation bundles were made for rgapi-0.1.9-cp311-cp311-macosx_11_0_arm64.whl:
Publisher:
ci.yml on AnswerDotAI/rgapi
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rgapi-0.1.9-cp311-cp311-macosx_11_0_arm64.whl -
Subject digest:
deb124beeef7b39afdb98169660acb21f0d15d09b5816d77bef9cf6917bd7d06 - Sigstore transparency entry: 1947913296
- Sigstore integration time:
-
Permalink:
AnswerDotAI/rgapi@6a655fea9ab7a94d8aa8b3e075778b18742e3b09 -
Branch / Tag:
refs/tags/v0.1.9 - Owner: https://github.com/AnswerDotAI
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@6a655fea9ab7a94d8aa8b3e075778b18742e3b09 -
Trigger Event:
push
-
Statement type:
File details
Details for the file rgapi-0.1.9-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: rgapi-0.1.9-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 1.6 MB
- Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c042e6fdfe32bc0494ac1f7bca8be3b0d48a8fea49d15401d0852905c489fc7d
|
|
| MD5 |
0397ca9bad6eb1cd9717596915777831
|
|
| BLAKE2b-256 |
0f9a316b6b2ee8bc65584a8e69fa43d6443e808633501da25573f8131df065e6
|
Provenance
The following attestation bundles were made for rgapi-0.1.9-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
ci.yml on AnswerDotAI/rgapi
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rgapi-0.1.9-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
c042e6fdfe32bc0494ac1f7bca8be3b0d48a8fea49d15401d0852905c489fc7d - Sigstore transparency entry: 1947912632
- Sigstore integration time:
-
Permalink:
AnswerDotAI/rgapi@6a655fea9ab7a94d8aa8b3e075778b18742e3b09 -
Branch / Tag:
refs/tags/v0.1.9 - Owner: https://github.com/AnswerDotAI
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@6a655fea9ab7a94d8aa8b3e075778b18742e3b09 -
Trigger Event:
push
-
Statement type:
File details
Details for the file rgapi-0.1.9-cp310-cp310-macosx_11_0_arm64.whl.
File metadata
- Download URL: rgapi-0.1.9-cp310-cp310-macosx_11_0_arm64.whl
- Upload date:
- Size: 1.4 MB
- Tags: CPython 3.10, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3dbf5332a38183609c9be77998ec833aaae8654fbf28153b013fd0346897f897
|
|
| MD5 |
648c9fbe11b36a2a8c67cbf473911958
|
|
| BLAKE2b-256 |
03106d8fc7dc02ecaaae35c3a0333c6cac22656081d7b175560a3ff40c89e036
|
Provenance
The following attestation bundles were made for rgapi-0.1.9-cp310-cp310-macosx_11_0_arm64.whl:
Publisher:
ci.yml on AnswerDotAI/rgapi
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rgapi-0.1.9-cp310-cp310-macosx_11_0_arm64.whl -
Subject digest:
3dbf5332a38183609c9be77998ec833aaae8654fbf28153b013fd0346897f897 - Sigstore transparency entry: 1947913409
- Sigstore integration time:
-
Permalink:
AnswerDotAI/rgapi@6a655fea9ab7a94d8aa8b3e075778b18742e3b09 -
Branch / Tag:
refs/tags/v0.1.9 - Owner: https://github.com/AnswerDotAI
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@6a655fea9ab7a94d8aa8b3e075778b18742e3b09 -
Trigger Event:
push
-
Statement type: