ripgrepy is a Python interface to ripgrep, a powerful, line-oriented search tool that recursively searches directories for regex patterns. It functions as a wrapper around the native `ripgrep` binary, allowing users to chain `ripgrep` command-line options directly in Python. The current version is 2.2.0, and the library maintains an active release cadence with updates typically occurring every few months.
pip install ripgrepyVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize `Ripgrepy` with a search pattern and a target directory (a temporary one in this example). It shows how to chain `ripgrep`'s command-line options like `with_filename()` and `line_number()`, execute the search with `run()`, and retrieve the output as a string. It also highlights the requirement for the underlying `ripgrep` binary to be installed on the system.
Review calls to `run()` and ensure arguments are correctly passed and escaped as per `subprocess.run`'s behavior. Explicitly cast arguments to strings if that was the intended behavior in earlier versions.
Ensure that all `ripgrep` option-chaining methods (e.g., `.with_filename()`, `.line_number()`, `.glob()`) are called *before* `.run()`.
Install the `ripgrep` binary (e.g., `brew install ripgrep` on macOS, `apt install ripgrep` on Debian/Ubuntu, or download from GitHub releases). Verify it's in your system's PATH by running `rg --version` in your terminal.
For complex or potentially incompatible `ripgrep` outputs, use `.as_string()` to get the raw output, and then parse it manually in your Python code as needed.
Install the `ripgrep` binary using your system's package manager (e.g., `sudo apt install ripgrep` on Debian/Ubuntu, `brew install ripgrep` on macOS, `choco install ripgrep` on Windows).
Install the package using pip: `pip install ripgrepy`
Import the `Ripgrepy` class and then create an instance to use its methods: `from ripgrepy import Ripgrepy` followed by `Ripgrepy().pattern('your_pattern').run()`.Access the specific attributes of the `RipgrepResult` objects (e.g., `filepath`, `linenumber`, `match`) to retrieve the desired information: `for r in results: print(f'File: {r.filepath}, Line: {r.linenumber}, Match: {r.match}')`.