Skip to main content

rgpy

rgpy is a blazing-fast, Rust-powered regular expression search tool for Python.
It brings the speed of ripgrep and regex into your Python environment, ideal for scanning large log files and datasets.


🚀 Features

  • Super-fast regex matching (powered by Rust)
  • Supports both regex and pcre2
  • Multithreaded line scanning (via Rayon)
  • Easy-to-use Python API
  • Supports:
    • Count-only mode (count=True)
    • Invert match (invert_match=True)
    • Recursive directory search (search_dir())

📦 Installation

Install via pip using maturin:

pip install maturin
maturin develop  # for local development

You can also install from PyPI once published:

pip install rgpy

🧪 Example Usage

from rgpy import search_file

results = search_file(
    pattern="error",
    path="./logs/sample.log",
    engine="regex",         # or "pcre2"
    ignore_case=True
)

for line in results:
    print(f"{line.path}:{line.line_number}: {line.text}")

🔢 Count-only mode

from rgpy import search_file

count = search_file("error", "./logs/sample.log", count=True)
print("Total matches:", count)

🚫 Invert match (return lines that do NOT match)

from rgpy import search_file

non_matches = search_file("error", "./logs/sample.log", invert_match=True)
for line in non_matches:
    print(f"{line.line_number}: {line.text}")

📂 Recursive search in a directory

from rgpy import search_dir

results = search_dir("timeout", "./logs", ignore_case=True)
for line in results:
    print(f"{line.path}:{line.line_number}: {line.text}")

multiprocessing support

from multiprocessing import Pool, cpu_count
from rgpy import search_file

LOG_FILE = "./logs/sample.log"

with open(LOG_FILE, "r", encoding="utf-8", errors="ignore") as f:
        lines = f.readlines()

chunk_size = len(lines) // cpu_count()
chunks = [lines[i:i + chunk_size] for i in range(0, len(lines), chunk_size)]

with Pool() as pool:
    counts = pool.map(search_file("error", LOG_FILE, invert_match=True), chunks)

🛠 Engine Options

  • "regex": Rust’s built-in, fast and safe regex engine (no backreferences or lookbehind)
  • "pcre2": Perl-compatible regex with full support for lookaround, backreference, etc. (slightly slower)

⚙️ Arguments

Parameter Type Description
pattern str Regex pattern to search
path/dir str File path (search_file) or directory (search_dir)
engine str "regex" (default) or "pcre2"
ignore_case bool Case-insensitive matching (optional)
count bool Return number of matches only (optional)
invert_match bool Return lines that do not match the pattern (optional)

⚡ Performance

rgpy uses Rust + Rayon for multithreaded file processing.
This makes it significantly faster than Python’s built-in re module, especially for large files. Without multiprocessing, rgpy is about 24% faster than re.

== Time Comparison (in seconds) ==
rgpy: 3.462s rgpy.compile: 3.419s rgpy.compile + mp: 2.293s re: 4.443s re.compile: 4.208s re.compile + mp: 2.173s


📜 License

MIT License


👤 Author

Developed by [cpprhtn/Junwon Lee]
Inspired by ripgrep and pyo3


Metadata

Release files for rgpy 0.2.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for rgpy 0.2.4
File Interpreter ABI Platform
rgpy-0.2.4-cp312-cp312-macosx_11_0_arm64.whl CPython 3.12 CPython 3.12 macOS 11.0+ ARM64 Details

Release files / rgpy-0.2.4-cp312-cp312-macosx_11_0_arm64.whl

Download URL rgpy-0.2.4-cp312-cp312-macosx_11_0_arm64.whl
Size 1.0 MB
Tags CPython 3.12 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
3bfef2d9afe6b8a8437c3b9215364aabbf943d69964c9b9ddd38ecf083f64f56
BLAKE2b-256 checksum
How to use checksums
005f4428c2209d1f3b1d5370bcfca637132e3131917bbee364c6cdc420e21cfd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release history Release notifications | RSS feed

This release

0.2.4 This release

1 release file

0.2.3

1 release file

0.2.2

1 release file

0.2.1

1 release file

0.2.0

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page