Registry / devops / ripgrepy

ripgrepy

JSON →
library2.2.0pypypi✓ verified 87d ago

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 ripgrepy
INSTALL
IMPORT
SIG · RIPGREPY
R
ripgrepy
devopspythonv2.2.0
Install
2.4s avg
Import
54ms
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.2.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.058s · 19.3MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 2.4s · import 0.049s · 20MB
17MB installed
● package 17MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Ripgrepy
from ripgrepy import Ripgrepy

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.

import tempfile import os from ripgrepy import Ripgrepy # Create a temporary directory and file for demonstration with tempfile.TemporaryDirectory() as tmpdir: test_file_path = os.path.join(tmpdir, 'test_document.txt') with open(test_file_path, 'w') as f: f.write('Hello, world!\n') f.write('This is a test line.\n') f.write('Another line saying hello.\n') print(f"Searching in: {tmpdir}") print(f"Content of {os.path.basename(test_file_path)}:\n---\n{open(test_file_path).read()}---\n") # Initialize Ripgrepy with a regex pattern and the directory to search # Note: The 'ripgrep' binary must be installed on your system (e.g., `brew install ripgrep` or `apt install ripgrep`) rg = Ripgrepy('hello', tmpdir) # Chain ripgrep options (e.g., --with-filename, --line-number) # .run() executes the command, followed by an output method results = rg.with_filename().line_number().run().as_string() print("Search results (as string):\n---") print(results) print("---") # You can also get results as a dictionary or JSON # results_dict = rg.run().as_dict() # print("Search results (as dict):\n---") # print(results_dict) # print("---")
Debug
Known issues
breakingVersion 2.0.0 changed the internal execution of `run()` to use `subprocess.run` for shell escaping. This might alter how arguments are processed and escaped compared to previous versions, potentially affecting commands with complex or unquoted arguments. It also fixed a bug where numeric arguments were incorrectly cast to strings, which could change behavior if older code relied on that implicit conversion.
fix
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.
affects: >=2.0.0
gotchaThe `.run()` method must always be the last method called before an output method (e.g., `.as_string()`, `.as_dict()`, `.as_json()`). Any `ripgrep` options chained *after* `.run()` will be ignored and will not be included in the executed command.
fix
Ensure that all `ripgrep` option-chaining methods (e.g., `.with_filename()`, `.line_number()`, `.glob()`) are called *before* `.run()`.
affects: All
gotchaThe `ripgrepy` library is a wrapper around the `ripgrep` command-line tool. It *requires* the `ripgrep` binary to be installed on the system where the Python code is executed. It will not work if the `ripgrep` binary is not found in the system's PATH or explicitly specified during `Ripgrepy` instantiation.
fix
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.
affects: All
gotchaNot all output formats from the underlying `ripgrep` binary are compatible with `ripgrepy`'s structured output methods, specifically `.as_dict()` and `.as_json()`. If the `ripgrep` command produces highly verbose or non-standard output, these methods might fail to parse it correctly.
fix
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.
affects: All
Errors
Common errors & fixes
FileNotFoundError: [Errno 2] No such file or directory: 'rg'
The `ripgrepy` Python library is a wrapper for the `ripgrep` executable, which must be installed separately and be accessible in your system's PATH.
fix
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).
ModuleNotFoundError: No module named 'ripgrepy'
The `ripgrepy` Python package has not been installed in your current Python environment.
fix
Install the package using pip: `pip install ripgrepy`
TypeError: 'module' object is not callable
You are attempting to call the `ripgrepy` *module* directly, instead of importing and instantiating the `Ripgrepy` class from it.
fix
Import the `Ripgrepy` class and then create an instance to use its methods: `from ripgrepy import Ripgrepy` followed by `Ripgrepy().pattern('your_pattern').run()`.
AttributeError: 'RipgrepResult' object has no attribute 'split'
`ripgrepy` returns a list of `RipgrepResult` objects, which encapsulate the search findings with specific attributes, rather than raw strings that can be directly split or manipulated as text.
fix
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}')`.
Upgrade
Version history
2.2.0latest on PyPI · released Jul 11, 2025
Audit
Dependencies
ripgrep (binary)requiredripgrepy is a Python wrapper that requires the `ripgrep` command-line tool to be installed on the system and accessible in the system's PATH, or its path explicitly provided during Ripgrepy instantiation.
Agent activity
12 hits · last 30 days
node
10
OpenAI (training)
1
Resources
ripgrepy — pip install ripgrepy · libregistry