---
title: File discovery and search
description: Synchronous and asynchronous ripgrep-style file walking and regex text
  search.
order: 1
---
[`rgapi`](rgapi.md) runs ripgrep's directory walker and fancy-regex engine in process on Rust threads. All walk and search functions accept the shared filter parameters (`glob`, `include`, `exclude`, `ext`, `hidden`, `ignore`, `max_depth`, `min_depth`, `max_filesize`, `follow_links`, `same_file_system`, `path_re`, `skip_path_re`, `skip_dir`, `skip_dir_re`). Invalid patterns or backtracking-limit failures raise `ValueError`, and unreadable paths emit a `RuntimeWarning` and are skipped.

```python
hits = rgstr(r"error:\s+(\w+)", "ok\nerror: timeout\ndone\n", context=1)
assert len(hits) == 3 and hits[1].kind == "match"
```

## Discovering files

[`fd`](rgapi.md#fd) walks recursively respecting `.gitignore` and returns absolute `Path` objects in a [`PathResults`](rgapi.md#pathresults) list. [`ls`](rgapi.md#ls) lists one level with ignore rules disabled and directories included. Use [`fd_iter`](rgapi.md#fd_iter) to stream paths lazily and stop early.

### fd

```python
def fd(
    pattern:str | None=None, # Smart-case regex matched against each basename
    root:str | Path | list='.', # Directory or file to walk, or a list of them (expands `~`)
    files:bool=True, # Include files in results
    dirs:bool=False, # Include directories in results
    show_target:bool=False, # Append `-> target` to symlink rows in the display
    timeout_ms:int | None=None, # Cancel the walk after this long and return partial results
    *, glob:str | list | None=None, # Include glob or globs; alias for `include`
    include:str | list | None=None, # Include glob or globs, e.g. `*.py`
    exclude:str | list | None=None, # Exclude glob or globs, e.g. `test_*.py`
    ext:str | list | None=None, # Extension or extensions to require, without needing `*.`; ANDs with `include`/`glob`
    hidden:bool=False, # Include hidden files and directories
    ignore:bool=True, # Respect `.gitignore` and other ignore files
    max_depth:int | None=None, # Maximum directory depth to descend
    min_depth:int | None=None, # Minimum depth for returned/searched paths
    max_filesize:int | None=None, # Skip files larger than this many bytes
    follow_links:bool=False, # Follow symbolic links while walking
    same_file_system:bool=False, # Do not cross filesystem boundaries
    path_re:str | None=None, # Regex that relative paths must match
    skip_path_re:str | None=None, # Regex for relative paths to skip
    skip_dir:str | list | None=None, # Directory glob or globs to prune
    skip_dir_re:str | None=None, # Directory regex used to prune traversal
)->PathResults:
```

*Find absolute Paths with fd-style filters and gitignore support.*

Filename/path regexes support backreferences and lookaround, matching the full name/path. Regex errors raise `ValueError`.

### ls

```python
def ls(
    root:str | Path | list='.', # Directory or file to list, or a list of them (expands `~`)
    pattern:str | None=None, # Smart-case regex matched against each basename
    hidden:bool=False, # Include hidden files and directories, like `ls -a`
    dirs:bool=True, # Include directories in results
    max_depth:int | None=1, # Directory depth to list; 1 lists just `root`
    ignore:bool=False, # Respect `.gitignore` and other ignore files
    *, files:bool=True, # Include files in results
    show_target:bool=False, # Append `-> target` to symlink rows in the display
    timeout_ms:int | None=None, # Cancel the walk after this long and return partial results
    glob:str | list | None=None, # Include glob or globs; alias for `include`
    include:str | list | None=None, # Include glob or globs, e.g. `*.py`
    exclude:str | list | None=None, # Exclude glob or globs, e.g. `test_*.py`
    ext:str | list | None=None, # Extension or extensions to require, without needing `*.`; ANDs with `include`/`glob`
    min_depth:int | None=None, # Minimum depth for returned/searched paths
    max_filesize:int | None=None, # Skip files larger than this many bytes
    follow_links:bool=False, # Follow symbolic links while walking
    same_file_system:bool=False, # Do not cross filesystem boundaries
    path_re:str | None=None, # Regex that relative paths must match
    skip_path_re:str | None=None, # Regex for relative paths to skip
    skip_dir:str | list | None=None, # Directory glob or globs to prune
    skip_dir_re:str | None=None, # Directory regex used to prune traversal
)->PathResults:
```

*List a directory like [`ls`](rgapi.md#ls): one level, directories included, ignore rules off, sorted by name. A root link to a directory lists that directory, with paths under the link.*

### fd\_iter

```python
def fd_iter(
    pattern:str | None=None, # Smart-case regex matched against each basename
    root:str | Path | list='.', # Directory or file to walk, or a list of them (expands `~`)
    files:bool=True, # Include files in results
    dirs:bool=False, # Include directories in results
    *, glob:str | list | None=None, # Include glob or globs; alias for `include`
    include:str | list | None=None, # Include glob or globs, e.g. `*.py`
    exclude:str | list | None=None, # Exclude glob or globs, e.g. `test_*.py`
    ext:str | list | None=None, # Extension or extensions to require, without needing `*.`; ANDs with `include`/`glob`
    hidden:bool=False, # Include hidden files and directories
    ignore:bool=True, # Respect `.gitignore` and other ignore files
    max_depth:int | None=None, # Maximum directory depth to descend
    min_depth:int | None=None, # Minimum depth for returned/searched paths
    max_filesize:int | None=None, # Skip files larger than this many bytes
    follow_links:bool=False, # Follow symbolic links while walking
    same_file_system:bool=False, # Do not cross filesystem boundaries
    path_re:str | None=None, # Regex that relative paths must match
    skip_path_re:str | None=None, # Regex for relative paths to skip
    skip_dir:str | list | None=None, # Directory glob or globs to prune
    skip_dir_re:str | None=None, # Directory regex used to prune traversal
):
```

*Walk lazily, yielding absolute Paths; early exit stops the walk.*

## Searching text

[`rg`](rgapi.md#rg) searches files in parallel using fancy-regex patterns (supporting lookaround and backreferences) and returns [`SearchResults`](rgapi.md#searchresults) of [`SearchLine`](rgapi.md#searchline) rows, or [`BlockResults`](block.md#blockresults) when `summary=True`. Pass `lnhashs=True` for `exhash`-compatible line addresses, or use [`rgstr`](rgapi.md#rgstr) to search an in-memory string.

### rg

```python
def rg(
    pattern:str, # Regex pattern to search for
    root:str | Path | list='.', # Directory or file to search, or a list of them (expands `~`)
    case_sensitive:bool | None=None, # True/False forces case; None allows `smart_case`
    smart_case:bool=False, # Match `rg --smart-case` behavior
    before_context:int=0, # Lines of context before each match, like `rg -B`
    after_context:int=0, # Lines of context after each match, like `rg -A`
    context:int=0, # Sets both before and after context, like `rg -C`
    paths:bool=False, # Return unique matched paths instead of rows
    count:bool | str=False, # Return the total match span count, or with `"file"` a dict of each file's count, instead of rows
    max_results:int | None=None, # Stop after this many matching rows; context rows of kept matches are included
    lnhashs:bool=False, # Show `lineno|hash|` addresses instead of line numbers in row display
    timeout_ms:int | None=None, # Cancel the search after this long and return partial results
    summary:bool=False, # Return one pilcrow-joined line per blank-line-delimited block?
    maxlen:int=180, # Maximum source characters per displayed block
    *, glob:str | list | None=None, # Include glob or globs; alias for `include`
    include:str | list | None=None, # Include glob or globs, e.g. `*.py`
    exclude:str | list | None=None, # Exclude glob or globs, e.g. `test_*.py`
    ext:str | list | None=None, # Extension or extensions to require, without needing `*.`; ANDs with `include`/`glob`
    hidden:bool=False, # Include hidden files and directories
    ignore:bool=True, # Respect `.gitignore` and other ignore files
    max_depth:int | None=None, # Maximum directory depth to descend
    min_depth:int | None=None, # Minimum depth for returned/searched paths
    max_filesize:int | None=None, # Skip files larger than this many bytes
    follow_links:bool=False, # Follow symbolic links while walking
    same_file_system:bool=False, # Do not cross filesystem boundaries
    path_re:str | None=None, # Regex that relative paths must match
    skip_path_re:str | None=None, # Regex for relative paths to skip
    skip_dir:str | list | None=None, # Directory glob or globs to prune
    skip_dir_re:str | None=None, # Directory regex used to prune traversal
):
```

*Search files and return [`SearchResults`](rgapi.md#searchresults), matched paths, or match counts; `lnhashs=True` shows exhash-style addresses.*

Patterns support backreferences and lookaround, confined to individual lines. Compilation or backtracking-limit failures raise `ValueError`. Timeouts request cancellation but do not interrupt a regex evaluation already in progress.

`summary=True` returns one [`SearchBlock`](block.md#searchblock) per block of lines separated by blank or whitespace-only lines, however many matches it holds, and `context` then counts blocks. Summary mode can't combine with `paths` or `count`, and with `lnhashs=True` shows each block's boundary addresses. `^` and `$` anchor each line, and a line ends at LF or CRLF. Patterns containing a newline or carriage return are rejected. Row `path` fields are labels relative to the root, or to the common ancestor of several roots. Each row has `asdict()`. A symlink named as `root` is followed.

### rg\_iter

```python
def rg_iter(
    pattern:str, # Regex pattern to search for
    root:str | Path | list='.', # Directory or file to search, or a list of them (expands `~`)
    case_sensitive:bool | None=None, # True/False forces case; None allows `smart_case`
    smart_case:bool=False, # Match `rg --smart-case` behavior
    before_context:int=0, # Lines of context before each match, like `rg -B`
    after_context:int=0, # Lines of context after each match, like `rg -A`
    context:int=0, # Sets both before and after context, like `rg -C`
    lnhashs:bool=False, # Show `lineno|hash|` addresses instead of line numbers in row display
    *, glob:str | list | None=None, # Include glob or globs; alias for `include`
    include:str | list | None=None, # Include glob or globs, e.g. `*.py`
    exclude:str | list | None=None, # Exclude glob or globs, e.g. `test_*.py`
    ext:str | list | None=None, # Extension or extensions to require, without needing `*.`; ANDs with `include`/`glob`
    hidden:bool=False, # Include hidden files and directories
    ignore:bool=True, # Respect `.gitignore` and other ignore files
    max_depth:int | None=None, # Maximum directory depth to descend
    min_depth:int | None=None, # Minimum depth for returned/searched paths
    max_filesize:int | None=None, # Skip files larger than this many bytes
    follow_links:bool=False, # Follow symbolic links while walking
    same_file_system:bool=False, # Do not cross filesystem boundaries
    path_re:str | None=None, # Regex that relative paths must match
    skip_path_re:str | None=None, # Regex for relative paths to skip
    skip_dir:str | list | None=None, # Directory glob or globs to prune
    skip_dir_re:str | None=None, # Directory regex used to prune traversal
)->RgIter:
```

*Search files lazily, yielding [`SearchLine`](rgapi.md#searchline) rows; `lnhashs=True` shows exhash-style addresses.*

### compile

```python
def compile(
    pattern:str, # Regex pattern to compile
    case_sensitive:bool | None=None, # True/False forces case; None allows `smart_case`
    smart_case:bool=False, # Match `rg --smart-case` behavior
)->Regex:
```

*Compile a line-oriented fancy-regex matcher, supporting backreferences and lookaround.*

`is_match` and `finditer` search each line independently; match offsets are UTF-8 bytes. Compilation or backtracking-limit failures raise `ValueError`.

### search\_text

```python
def search_text(
    matcher:Regex, # Compiled `Regex` from `compile()`
    text:str, # Text to search
    path:str | Path='<text>', # Path label stored in results
    before_context:int=0, # Lines of context before each match
    after_context:int=0, # Lines of context after each match
    context:int=0, # Sets both before and after context, like `rg -C`
)->SearchResults:
```

*Search an in-memory string with a compiled matcher.*

### rgstr

```python
def rgstr(
    pattern:str, # Regex pattern to search for
    text:str, # Text to search
    case_sensitive:bool | None=None, # True/False forces case; None allows `smart_case`
    smart_case:bool=False, # Match `rg --smart-case` behavior
    *, before_context:int=0, # Lines of context before each match
    after_context:int=0, # Lines of context after each match
    context:int=0, # Sets both before and after context, like `rg -C`
)->SearchResults:
```

*Search text already in hand, like [`rg`](rgapi.md#rg) on a string: no path label, no separate [`compile`](rgapi.md#compile).*

### search\_path

```python
def search_path(
    matcher:Regex, # Compiled `Regex` from `compile()`
    path:str | Path, # File path to search (expands `~`)
    display_path:str | Path | None=None, # Path stored in results; defaults to `path`
    before_context:int=0, # Lines of context before each match
    after_context:int=0, # Lines of context after each match
    context:int=0, # Sets both before and after context, like `rg -C`
)->SearchResults:
```

*Search one file with a compiled matcher.*

## Async discovery and search

[`fda`](rgapi.md#fda), [`fda_iter`](rgapi.md#fda_iter), [`rga`](rgapi.md#rga), and [`rga_iter`](rgapi.md#rga_iter) offload directory walking and searching to Rust worker threads so an asyncio event loop stays responsive. Breaking out of an async iterator cancels the Rust worker.

### fda

```python
async def fda(
    pattern:str | None=None, # Smart-case regex matched against each basename
    root:str | Path | list='.', # Directory or file to walk, or a list of them (expands `~`)
    files:bool=True, # Include files in results
    dirs:bool=False, # Include directories in results
    show_target:bool=False, # Append `-> target` to symlink rows in the display
    timeout_ms:int | None=None, # Cancel the walk after this long and return partial results
    *, glob:str | list | None=None, # Include glob or globs; alias for `include`
    include:str | list | None=None, # Include glob or globs, e.g. `*.py`
    exclude:str | list | None=None, # Exclude glob or globs, e.g. `test_*.py`
    ext:str | list | None=None, # Extension or extensions to require, without needing `*.`; ANDs with `include`/`glob`
    hidden:bool=False, # Include hidden files and directories
    ignore:bool=True, # Respect `.gitignore` and other ignore files
    max_depth:int | None=None, # Maximum directory depth to descend
    min_depth:int | None=None, # Minimum depth for returned/searched paths
    max_filesize:int | None=None, # Skip files larger than this many bytes
    follow_links:bool=False, # Follow symbolic links while walking
    same_file_system:bool=False, # Do not cross filesystem boundaries
    path_re:str | None=None, # Regex that relative paths must match
    skip_path_re:str | None=None, # Regex for relative paths to skip
    skip_dir:str | list | None=None, # Directory glob or globs to prune
    skip_dir_re:str | None=None, # Directory regex used to prune traversal
)->PathResults:
```

*Async [`fd`](rgapi.md#fd): find paths on Rust threads without blocking the event loop.*

### fda\_iter

```python
def fda_iter(
    pattern:str | None=None, # Smart-case regex matched against each basename
    root:str | Path | list='.', # Directory or file to walk, or a list of them (expands `~`)
    files:bool=True, # Include files in results
    dirs:bool=False, # Include directories in results
    batch_max:int=512, # Largest batch of paths delivered to the event loop at once
    *, glob:str | list | None=None, # Include glob or globs; alias for `include`
    include:str | list | None=None, # Include glob or globs, e.g. `*.py`
    exclude:str | list | None=None, # Exclude glob or globs, e.g. `test_*.py`
    ext:str | list | None=None, # Extension or extensions to require, without needing `*.`; ANDs with `include`/`glob`
    hidden:bool=False, # Include hidden files and directories
    ignore:bool=True, # Respect `.gitignore` and other ignore files
    max_depth:int | None=None, # Maximum directory depth to descend
    min_depth:int | None=None, # Minimum depth for returned/searched paths
    max_filesize:int | None=None, # Skip files larger than this many bytes
    follow_links:bool=False, # Follow symbolic links while walking
    same_file_system:bool=False, # Do not cross filesystem boundaries
    path_re:str | None=None, # Regex that relative paths must match
    skip_path_re:str | None=None, # Regex for relative paths to skip
    skip_dir:str | list | None=None, # Directory glob or globs to prune
    skip_dir_re:str | None=None, # Directory regex used to prune traversal
):
```

*Async [`fd_iter`](rgapi.md#fd_iter): yield absolute Paths; early exit stops the walk.*

### rga

```python
async def rga(
    pattern:str, # Regex pattern to search for
    root:str | Path | list='.', # Directory or file to search, or a list of them (expands `~`)
    case_sensitive:bool | None=None, # True/False forces case; None allows `smart_case`
    smart_case:bool=False, # Match `rg --smart-case` behavior
    before_context:int=0, # Lines of context before each match, like `rg -B`
    after_context:int=0, # Lines of context after each match, like `rg -A`
    context:int=0, # Sets both before and after context, like `rg -C`
    paths:bool=False, # Return unique matched paths instead of rows
    count:bool | str=False, # Return the total match span count, or with `"file"` a dict of each file's count, instead of rows
    max_results:int | None=None, # Stop after this many matching rows; context rows of kept matches are included
    lnhashs:bool=False, # Show `lineno|hash|` addresses instead of line numbers in row display
    timeout_ms:int | None=None, # Cancel the search after this long and return partial results
    summary:bool=False, # Return one pilcrow-joined line per blank-line-delimited block?
    maxlen:int=180, # Maximum source characters per displayed block
    *, glob:str | list | None=None, # Include glob or globs; alias for `include`
    include:str | list | None=None, # Include glob or globs, e.g. `*.py`
    exclude:str | list | None=None, # Exclude glob or globs, e.g. `test_*.py`
    ext:str | list | None=None, # Extension or extensions to require, without needing `*.`; ANDs with `include`/`glob`
    hidden:bool=False, # Include hidden files and directories
    ignore:bool=True, # Respect `.gitignore` and other ignore files
    max_depth:int | None=None, # Maximum directory depth to descend
    min_depth:int | None=None, # Minimum depth for returned/searched paths
    max_filesize:int | None=None, # Skip files larger than this many bytes
    follow_links:bool=False, # Follow symbolic links while walking
    same_file_system:bool=False, # Do not cross filesystem boundaries
    path_re:str | None=None, # Regex that relative paths must match
    skip_path_re:str | None=None, # Regex for relative paths to skip
    skip_dir:str | list | None=None, # Directory glob or globs to prune
    skip_dir_re:str | None=None, # Directory regex used to prune traversal
):
```

*Async [`rg`](rgapi.md#rg): search on Rust threads without blocking the event loop.*

### rga\_iter

```python
def rga_iter(
    pattern:str, # Regex pattern to search for
    root:str | Path | list='.', # Directory or file to search, or a list of them (expands `~`)
    case_sensitive:bool | None=None, # True/False forces case; None allows `smart_case`
    smart_case:bool=False, # Match `rg --smart-case` behavior
    before_context:int=0, # Lines of context before each match, like `rg -B`
    after_context:int=0, # Lines of context after each match, like `rg -A`
    context:int=0, # Sets both before and after context, like `rg -C`
    lnhashs:bool=False, # Show `lineno|hash|` addresses instead of line numbers in row display
    batch_max:int=512, # Largest batch of rows delivered to the event loop at once
    *, glob:str | list | None=None, # Include glob or globs; alias for `include`
    include:str | list | None=None, # Include glob or globs, e.g. `*.py`
    exclude:str | list | None=None, # Exclude glob or globs, e.g. `test_*.py`
    ext:str | list | None=None, # Extension or extensions to require, without needing `*.`; ANDs with `include`/`glob`
    hidden:bool=False, # Include hidden files and directories
    ignore:bool=True, # Respect `.gitignore` and other ignore files
    max_depth:int | None=None, # Maximum directory depth to descend
    min_depth:int | None=None, # Minimum depth for returned/searched paths
    max_filesize:int | None=None, # Skip files larger than this many bytes
    follow_links:bool=False, # Follow symbolic links while walking
    same_file_system:bool=False, # Do not cross filesystem boundaries
    path_re:str | None=None, # Regex that relative paths must match
    skip_path_re:str | None=None, # Regex for relative paths to skip
    skip_dir:str | list | None=None, # Directory glob or globs to prune
    skip_dir_re:str | None=None, # Directory regex used to prune traversal
):
```

*Async [`rg_iter`](rgapi.md#rg_iter): yield [`SearchLine`](rgapi.md#searchline) rows as they are found; early exit cancels the search.*

## Result types and iterators

### PathResults

```python
def PathResults(
    paths:tuple=(), root:str='.', show_target:bool=False
):
```

*Absolute `Path` objects with root-relative plain and `ls -l`-style displays.*

The display is an ls-style table capped at `MAX_REPR` names. `str(res)` gives one root-relative name per line, and `list(res)` the absolute Paths. Slices keep the display root and completion status.

### SearchResults

```python
def SearchResults(
    *args, **kwargs
):
```

*List of [`SearchLine`](rgapi.md#searchline) rows with rg-style text display.*

### SearchLine

```python
class SearchLine:
```

*One matched or context source line returned by [`rg`](rgapi.md#rg), [`rg_iter`](rgapi.md#rg_iter), [`rgstr`](rgapi.md#rgstr), [`search_text`](rgapi.md#search_text), or [`search_path`](rgapi.md#search_path).*

#### SearchLine.asdict

```python
def asdict()
```

*Return this row's fields (`kind`, `path`, `line_number`, `lnhash`, `line`, `matches`) as a plain `dict`.*

#### SearchLine.lnhash

```python
@property
def lnhash(self):
```

*Hash-verified `lineno|hash|` address compatible with `exhash`.*

#### SearchLine.line\_number

```python
@property
def line_number(self):
```

*1-based line number in the file.*

#### SearchLine.kind

```python
@property
def kind(self):
```

*Row role: `'match'`, `'before'`, `'after'`, or `'context'`.*

#### SearchLine.line

```python
@property
def line(self):
```

*Line text without a trailing newline.*

#### SearchLine.path

```python
@property
def path(self):
```

*Relative path label for the file (empty for [`rgstr`](rgapi.md#rgstr)).*

#### SearchLine.matches

```python
@property
def matches(self):
```

*UTF-8 byte `(start, end)` match spans on `'match'` rows (empty on context rows).*

### RgIter

```python
class RgIter:
```

*Lazy iterator of [`SearchLine`](rgapi.md#searchline) rows returned by [`rg_iter`](rgapi.md#rg_iter).*

#### RgIter.cancel

```python
def cancel()
```

*Stop the background Rust search worker early without exhausting the iterator.*

### Regex

```python
def Regex(
    pattern, case_sensitive=None, smart_case:bool=False
):
```

*Compiled line-oriented fancy-regex matcher supporting backreferences and lookaround.*

#### Regex.is\_match

```python
def is_match(
    text
):
```

*Return `True` if any line in `text` matches this pattern.*

#### Regex.finditer

```python
def finditer(
    text
):
```

*Return UTF-8 byte `(start, end)` match spans across `text`.*

#### Regex.pattern

```python
@property
def pattern(self):
```

*Original pattern string.*

#### Regex.smart\_case

```python
@property
def smart_case(self):
```

*`True` when smart-case matching is enabled.*

#### Regex.case\_sensitive

```python
@property
def case_sensitive(self):
```

*Explicit case sensitivity override (`None` delegates to `smart_case`).*

## Notebook search

Re-exported from [`rgapi.nb`](nb.md) for convenience ([`nbrg`](rgapi.md#nbrg), [`nbrg_iter`](rgapi.md#nbrg_iter), [`nbrga`](rgapi.md#nbrga), [`nbrga_iter`](rgapi.md#nbrga_iter)).

### nbrg

```python
def nbrg(
    pattern:str, # Regex pattern to search for
    root:str | Path | list='.', # Directory or file to search, or a list of them (expands `~`)
    cell_context:int=0, # Cells of context to include before/after each matching cell
    case_sensitive:bool | None=None, # True/False forces case; None allows `smart_case`
    smart_case:bool=False, # Match `rg --smart-case` behavior
    paths:bool=False, # Return unique matched paths instead of rows
    multiline:bool=False, # Let the pattern match across lines within a cell
    max_results:int | None=None, # Return at most this many cells
    count:bool=False, # Return the number of matching cells instead of results
    timeout_ms:int | None=None, # Cancel the search after this long and return partial results
    maxlen:int=180, # Maximum source characters per displayed cell
    *, glob:str | list | None=None, # Include glob or globs; alias for `include`
    include:str | list | None=None, # Include glob or globs, e.g. `*.py`
    exclude:str | list | None=None, # Exclude glob or globs, e.g. `test_*.py`
    hidden:bool=False, # Include hidden files and directories
    ignore:bool=True, # Respect `.gitignore` and other ignore files
    max_depth:int | None=None, # Maximum directory depth to descend
    min_depth:int | None=None, # Minimum depth for returned/searched paths
    max_filesize:int | None=None, # Skip files larger than this many bytes
    follow_links:bool=False, # Follow symbolic links while walking
    same_file_system:bool=False, # Do not cross filesystem boundaries
    path_re:str | None=None, # Regex that relative paths must match
    skip_path_re:str | None=None, # Regex for relative paths to skip
    skip_dir:str | list | None=None, # Directory glob or globs to prune
    skip_dir_re:str | None=None, # Directory regex used to prune traversal
):
```

*Search `.ipynb` cell sources under `root` in parallel, returning matched cells, paths, or a count.*

Only cell sources are searched, never metadata or outputs. Backreferences and lookaround are line-local by default. `multiline=True` allows matching across lines within a cell, never across cells; `^` and `$` still anchor individual lines. Compilation or backtracking-limit failures raise `ValueError`; timeouts cannot interrupt an in-progress regex evaluation. Metadata `nbdev` directives display as a bracket tag after the cell id (e.g. `nb.ipynb:c1[export]:…`). A match preview starts at the first matched line and marks omitted earlier lines as `…[Ln]` (1-based), keeping any leading `#|` directive line as in `#| export…[L4]needle here`.

### nbrg\_iter

```python
def nbrg_iter(
    pattern:str, # Regex pattern to search for
    root:str | Path | list='.', # Directory or file to search, or a list of them (expands `~`)
    cell_context:int=0, # Cells of context to include before/after each matching cell
    case_sensitive:bool | None=None, # True/False forces case; None allows `smart_case`
    smart_case:bool=False, # Match `rg --smart-case` behavior
    multiline:bool=False, # Let the pattern match across lines within a cell
    maxlen:int=180, # Maximum source characters per displayed cell
    *, glob:str | list | None=None, # Include glob or globs; alias for `include`
    include:str | list | None=None, # Include glob or globs, e.g. `*.py`
    exclude:str | list | None=None, # Exclude glob or globs, e.g. `test_*.py`
    hidden:bool=False, # Include hidden files and directories
    ignore:bool=True, # Respect `.gitignore` and other ignore files
    max_depth:int | None=None, # Maximum directory depth to descend
    min_depth:int | None=None, # Minimum depth for returned/searched paths
    max_filesize:int | None=None, # Skip files larger than this many bytes
    follow_links:bool=False, # Follow symbolic links while walking
    same_file_system:bool=False, # Do not cross filesystem boundaries
    path_re:str | None=None, # Regex that relative paths must match
    skip_path_re:str | None=None, # Regex for relative paths to skip
    skip_dir:str | list | None=None, # Directory glob or globs to prune
    skip_dir_re:str | None=None, # Directory regex used to prune traversal
):
```

*Search `.ipynb` cell sources lazily, yielding [`NbCell`](nb.md#nbcell) rows as they are found.*

### nbrga

```python
async def nbrga(
    pattern:str, # Regex pattern to search for
    root:str | Path | list='.', # Directory or file to search, or a list of them (expands `~`)
    cell_context:int=0, # Cells of context to include before/after each matching cell
    case_sensitive:bool | None=None, # True/False forces case; None allows `smart_case`
    smart_case:bool=False, # Match `rg --smart-case` behavior
    paths:bool=False, # Return unique matched paths instead of rows
    multiline:bool=False, # Let the pattern match across lines within a cell
    max_results:int | None=None, # Return at most this many cells
    count:bool=False, # Return the number of matching cells instead of results
    timeout_ms:int | None=None, # Cancel the search after this long and return partial results
    maxlen:int=180, # Maximum source characters per displayed cell
    *, glob:str | list | None=None, # Include glob or globs; alias for `include`
    include:str | list | None=None, # Include glob or globs, e.g. `*.py`
    exclude:str | list | None=None, # Exclude glob or globs, e.g. `test_*.py`
    hidden:bool=False, # Include hidden files and directories
    ignore:bool=True, # Respect `.gitignore` and other ignore files
    max_depth:int | None=None, # Maximum directory depth to descend
    min_depth:int | None=None, # Minimum depth for returned/searched paths
    max_filesize:int | None=None, # Skip files larger than this many bytes
    follow_links:bool=False, # Follow symbolic links while walking
    same_file_system:bool=False, # Do not cross filesystem boundaries
    path_re:str | None=None, # Regex that relative paths must match
    skip_path_re:str | None=None, # Regex for relative paths to skip
    skip_dir:str | list | None=None, # Directory glob or globs to prune
    skip_dir_re:str | None=None, # Directory regex used to prune traversal
):
```

*Async [`nbrg`](rgapi.md#nbrg): search notebooks on Rust threads without blocking the event loop.*

### nbrga\_iter

```python
def nbrga_iter(
    pattern:str, # Regex pattern to search for
    root:str | Path | list='.', # Directory or file to search, or a list of them (expands `~`)
    cell_context:int=0, # Cells of context to include before/after each matching cell
    case_sensitive:bool | None=None, # True/False forces case; None allows `smart_case`
    smart_case:bool=False, # Match `rg --smart-case` behavior
    multiline:bool=False, # Let the pattern match across lines within a cell
    batch_max:int=512, # Largest batch of cells delivered to the event loop at once
    maxlen:int=180, # Maximum source characters per displayed cell
    *, glob:str | list | None=None, # Include glob or globs; alias for `include`
    include:str | list | None=None, # Include glob or globs, e.g. `*.py`
    exclude:str | list | None=None, # Exclude glob or globs, e.g. `test_*.py`
    hidden:bool=False, # Include hidden files and directories
    ignore:bool=True, # Respect `.gitignore` and other ignore files
    max_depth:int | None=None, # Maximum directory depth to descend
    min_depth:int | None=None, # Minimum depth for returned/searched paths
    max_filesize:int | None=None, # Skip files larger than this many bytes
    follow_links:bool=False, # Follow symbolic links while walking
    same_file_system:bool=False, # Do not cross filesystem boundaries
    path_re:str | None=None, # Regex that relative paths must match
    skip_path_re:str | None=None, # Regex for relative paths to skip
    skip_dir:str | list | None=None, # Directory glob or globs to prune
    skip_dir_re:str | None=None, # Directory regex used to prune traversal
):
```

*Async [`nbrg_iter`](rgapi.md#nbrg_iter): yield [`NbCell`](nb.md#nbcell) rows as they are found; early exit cancels the search.*
