High-performance log redaction for Python - Python wrapper for PlumbrC
Project description
PlumbrC for Python
High-performance log redaction for Python. Python wrapper for the PlumbrC C library.
Features
- 🚀 Blazing Fast — 500K+ lines/sec powered by C engine
- 📦 702 Built-in Patterns — AWS, GCP, Stripe, GitHub, and more
- 🔒 Security-First — Detect and redact secrets, API keys, passwords, PII
- 💻 Simple API — Pythonic interface to high-performance C library
- 🔧 Zero Dependencies — Pure ctypes wrapper, no external Python packages
Installation
pip install plumbrc
Requirements
- Python 3.7+
- Linux or macOS
- libpcre2 (usually pre-installed)
Quick Start
from plumbrc import Plumbr
# Create redactor with default patterns
p = Plumbr()
# Redact secrets from text
text = "api_key=sk-proj-abc123 password=secret123"
safe = p.redact(text)
print(safe)
# Output: "api_key=[REDACTED:api_key] password=[REDACTED:password]"
# Check loaded patterns
print(f"Loaded {p.pattern_count} patterns")
# Get statistics
print(p.stats)
Usage
Basic Redaction
from plumbrc import Plumbr
p = Plumbr()
# Single line
safe = p.redact("AWS key: AKIAIOSFODNN7EXAMPLE")
# "AWS key: [REDACTED:aws_access_key]"
# Multiple lines
lines = [
"User login with token: ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"Database: postgres://user:pass@localhost:5432/db",
"Normal log line"
]
redacted = p.redact_lines(lines)
Context Manager
with Plumbr() as p:
safe = p.redact("secret data")
print(safe)
# Resources automatically cleaned up
Custom Patterns
# Load custom pattern file
p = Plumbr(pattern_file="my_patterns.txt")
# Load patterns from directory
p = Plumbr(pattern_dir="patterns/")
Statistics
p = Plumbr()
p.redact("api_key=secret123")
stats = p.stats
print(stats)
# {
# 'lines_processed': 1,
# 'lines_modified': 1,
# 'patterns_matched': 1,
# 'bytes_processed': 17,
# 'elapsed_seconds': 0.000123
# }
API Reference
Plumbr
Main redaction class.
Constructor
Plumbr(
pattern_file: Optional[str] = None,
pattern_dir: Optional[str] = None,
num_threads: int = 0,
quiet: bool = True
)
Parameters:
pattern_file: Path to custom pattern filepattern_dir: Path to directory with pattern filesnum_threads: Number of worker threads (0 = auto)quiet: Suppress statistics output
Methods
redact(text: str) -> str
Redact secrets from text.
safe = p.redact("password=secret123")
redact_lines(lines: List[str]) -> List[str]
Redact multiple lines.
safe_lines = p.redact_lines(["line1", "line2"])
Properties
pattern_count: int
Number of loaded patterns.
count = p.pattern_count
stats: Dict[str, int]
Processing statistics.
stats = p.stats
version() -> str (static)
Get PlumbrC library version.
ver = Plumbr.version()
Pattern Categories
PlumbrC includes 702 patterns across 12 categories:
| Category | Patterns | Examples |
|---|---|---|
| Cloud | 109 | AWS, GCP, Azure, DigitalOcean |
| Communication | 127 | Slack, Discord, Telegram, Twilio |
| Payment | 79 | Stripe, Square, PayPal, Braintree |
| VCS | 63 | GitHub, GitLab, Bitbucket |
| Infrastructure | 72 | Docker, NPM, PyPI, CI/CD |
| Crypto | 54 | SSH, SSL/TLS, PGP, JWT |
| Secrets | 52 | Generic API keys, passwords |
| Social | 50 | Facebook, Twitter, LinkedIn |
| Database | 42 | PostgreSQL, MongoDB, MySQL |
| Analytics | 30 | Google Analytics, Mixpanel |
| PII | 14 | Email, SSN, phone, IP |
| Auth | 10 | JWT, OAuth, Bearer tokens |
Performance
PlumbrC is built for speed:
- 500K+ lines/sec on modern hardware
- Sub-microsecond per-line latency
- Zero-allocation hot path in C engine
- Parallel processing support
import time
from plumbrc import Plumbr
p = Plumbr()
# Benchmark
lines = ["test line"] * 100000
start = time.time()
p.redact_lines(lines)
elapsed = time.time() - start
print(f"Processed {len(lines)} lines in {elapsed:.2f}s")
print(f"Throughput: {len(lines)/elapsed:.0f} lines/sec")
Examples
Log File Processing
from plumbrc import Plumbr
with Plumbr() as p:
with open("app.log") as f:
for line in f:
safe = p.redact(line)
print(safe, end="")
Flask Integration
from flask import Flask, request, jsonify
from plumbrc import Plumbr
app = Flask(__name__)
redactor = Plumbr()
@app.route("/api/redact", methods=["POST"])
def redact():
text = request.json.get("text", "")
safe = redactor.redact(text)
return jsonify({"redacted": safe, "stats": redactor.stats})
Batch Processing
from plumbrc import Plumbr
import glob
p = Plumbr()
for log_file in glob.glob("logs/*.log"):
with open(log_file) as f:
lines = f.readlines()
redacted = p.redact_lines(lines)
with open(f"redacted/{log_file}", "w") as f:
f.writelines(redacted)
Development
Building from Source
# Clone repository
git clone https://github.com/AmritRai1234/plumbrC.git
cd plumbrC/python
# Install in development mode
pip install -e ".[dev]"
# Run tests
pytest tests/ -v
Running Tests
# Install test dependencies
pip install pytest pytest-cov
# Run tests
pytest tests/
# With coverage
pytest tests/ --cov=plumbrc --cov-report=html
License
Source Available License — Free for non-commercial use. See LICENSE for details.
Links
- Homepage: https://plumbr.ca
- GitHub: https://github.com/AmritRai1234/plumbrC
- PyPI: https://pypi.org/project/plumbrc/
- Documentation: https://plumbr.ca
Support
- Issues: GitHub Issues
- Commercial Licensing: See LICENSE file
PlumbrC — Protect your logs. Protect your secrets.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file plumbrc-1.0.2.tar.gz.
File metadata
- Download URL: plumbrc-1.0.2.tar.gz
- Upload date:
- Size: 39.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fe2e348393e2e13efe72d323d66c87c80bb590aa18641bf85a436ab3fc25ebfb
|
|
| MD5 |
dca2951b686a489e8ee27f13197f1941
|
|
| BLAKE2b-256 |
24d7421bf740fb2b0e0b2c95672051acb9e52cb07f9b375596cefff2e0505b93
|
Provenance
The following attestation bundles were made for plumbrc-1.0.2.tar.gz:
Publisher:
publish-pypi.yml on AmritRai1234/plumbrC
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
plumbrc-1.0.2.tar.gz -
Subject digest:
fe2e348393e2e13efe72d323d66c87c80bb590aa18641bf85a436ab3fc25ebfb - Sigstore transparency entry: 952375777
- Sigstore integration time:
-
Permalink:
AmritRai1234/plumbrC@38e4bab5a991f071587d53c860d612bf9e67a362 -
Branch / Tag:
refs/tags/v1.0.2 - Owner: https://github.com/AmritRai1234
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@38e4bab5a991f071587d53c860d612bf9e67a362 -
Trigger Event:
release
-
Statement type: