Skip to main content

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 file
  • pattern_dir: Path to directory with pattern files
  • num_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

Support


PlumbrC — Protect your logs. Protect your secrets.

Project details


Download files

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

Source Distribution

plumbrc-1.0.1.tar.gz (40.5 kB view details)

Uploaded Source

File details

Details for the file plumbrc-1.0.1.tar.gz.

File metadata

  • Download URL: plumbrc-1.0.1.tar.gz
  • Upload date:
  • Size: 40.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for plumbrc-1.0.1.tar.gz
Algorithm Hash digest
SHA256 0344cc479127ea7789e4c9cd8ad98105a46e860fc93931f23ced440d402fe9c2
MD5 298b7f3a59a7d3400182abcc87071b52
BLAKE2b-256 7fddfde5a7453cd57b5366f762659e045c221dc1adf950da7c86b47f5c2146b0

See more details on using hashes here.

Provenance

The following attestation bundles were made for plumbrc-1.0.1.tar.gz:

Publisher: publish-pypi.yml on AmritRai1234/plumbrC

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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