File discovery and search

Synchronous and asynchronous ripgrep-style file walking and regex text search.

rgapi 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.

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 walks recursively respecting .gitignore and returns absolute Path objects in a PathResults list. ls lists one level with ignore rules disabled and directories included. Use fd_iter to stream paths lazily and stop early.

fd

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

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: 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

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 searches files in parallel using fancy-regex patterns (supporting lookaround and backreferences) and returns SearchResults of SearchLine rows, or BlockResults when summary=True. Pass lnhashs=True for exhash-compatible line addresses, or use rgstr to search an in-memory string.

rg

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, 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 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

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 rows; lnhashs=True shows exhash-style addresses.

compile

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

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

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 on a string: no path label, no separate compile.

search_path

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.

fda, fda_iter, rga, and 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

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: find paths on Rust threads without blocking the event loop.

fda_iter

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: yield absolute Paths; early exit stops the walk.

rga

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: search on Rust threads without blocking the event loop.

rga_iter

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: yield SearchLine rows as they are found; early exit cancels the search.

Result types and iterators

PathResults

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

def SearchResults(
    *args, **kwargs
):

List of SearchLine rows with rg-style text display.

SearchLine

class SearchLine:

One matched or context source line returned by rg, rg_iter, rgstr, search_text, or search_path.

SearchLine.asdict

def asdict()

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

SearchLine.lnhash

@property
def lnhash(self):

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

SearchLine.line_number

@property
def line_number(self):

1-based line number in the file.

SearchLine.kind

@property
def kind(self):

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

SearchLine.line

@property
def line(self):

Line text without a trailing newline.

SearchLine.path

@property
def path(self):

Relative path label for the file (empty for rgstr).

SearchLine.matches

@property
def matches(self):

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

RgIter

class RgIter:

Lazy iterator of SearchLine rows returned by rg_iter.

RgIter.cancel

def cancel()

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

Regex

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

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

Regex.is_match

def is_match(
    text
):

Return True if any line in text matches this pattern.

Regex.finditer

def finditer(
    text
):

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

Regex.pattern

@property
def pattern(self):

Original pattern string.

Regex.smart_case

@property
def smart_case(self):

True when smart-case matching is enabled.

Regex.case_sensitive

@property
def case_sensitive(self):

Explicit case sensitivity override (None delegates to smart_case).

Re-exported from rgapi.nb for convenience (nbrg, nbrg_iter, nbrga, nbrga_iter).

nbrg

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

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 rows as they are found.

nbrga

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: search notebooks on Rust threads without blocking the event loop.

nbrga_iter

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: yield NbCell rows as they are found; early exit cancels the search.