Skip to main content

Rust-powered blazing-fast regex search for Python

Project description

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}")

⚙️ 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)
iinvert_match bool Return lines that do not match the pattern (optional)

🛠 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)

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


📜 License

MIT License


👤 Author

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


Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rgpy-0.2.1-cp312-cp312-macosx_11_0_arm64.whl (949.5 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

File details

Details for the file rgpy-0.2.1-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for rgpy-0.2.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e9f4acf6da720a12cc960228b864a67d72840e3d42ba9f9f56ffad415b95de86
MD5 2a9403b99be6122947c59baf7d2f82a9
BLAKE2b-256 116f4e3f471bf65b909ef980ce839d49d8fb720e635b3ee3ce8e0e55f5ef9283

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page