Skip to content

Repository files navigation

πŸ” pii-radar

Scan any CSV, JSON, or Parquet file for Personally Identifiable Information β€” in seconds.

CI PyPI version Python Discussions License: MIT PRs Welcome


pii-radar Terminal Demo


Abstract

Data engineers and ML practitioners routinely work with datasets that silently contain Personally Identifiable Information (PII) β€” emails, phone numbers, SSNs, credit card numbers, and IP addresses β€” creating compliance risks under GDPR, CCPA, and HIPAA. pii-radar is a lightweight, zero-dependency-ML CLI tool that scans structured data files for PII using high-precision patterns, Luhn Mod-10 verification, and contextual heuristics, outputting results as rich terminal tables, JSON, or CSV reports. It integrates natively with pre-commit hooks and GitHub Actions to catch PII before it reaches production or version control.

☁️ Azure Cloud Integration

pii-radar provides streaming PII redaction components for Microsoft Azure Storage and Azure Event Hubs:

Flow 1: Stream and Redact Files in Azure Blob Storage

Azure Blob Storage PII Redaction Architecture

from pii_radar.integrations import AzureBlobStreamRedactor

# Scans CSV/JSON blobs in Azure Blob Storage and uploads redacted sanitized copies
redactor = AzureBlobStreamRedactor(
    connection_string="DefaultEndpointsProtocol=https;...",
    container_name="customer-data"
)
total_found, counts = redactor.redact_blob("raw_customers.csv", output_blob_name="sanitized_customers.csv")
print(f"Redacted {total_found} PII occurrences in Azure Blob Storage.")

Flow 2: Real-Time PII Redaction in Azure Event Hubs

Azure Event Hubs Real-Time PII Redaction Architecture

from pii_radar.integrations import AzureEventHubHandler

# Redacts sensitive PII in real-time telemetry streaming event batches
handler = AzureEventHubHandler(
    connection_string="Endpoint=sb://...",
    eventhub_name="telemetry-hub"
)
redacted_events = handler.process_event_batch(raw_event_messages)

πŸš€ Usage Guides

  • ⚑ Azure Blob Storage Stream Redactor β€” Real-time PII scanning & masking for CSV/JSON files in Azure Storage containers (AzureBlobStreamRedactor)
  • πŸ“‘ Azure Event Hubs Integration β€” Low-latency PII redaction pipeline for streaming telemetry in Azure Event Hubs (AzureEventHubHandler)
  • πŸ“ 3 file formats β€” CSV, JSON, Parquet (.parquet, .pq)
  • πŸ“‚ Folder scanning β€” Recursively scan entire directories
  • 🎨 Beautiful terminal output β€” Rich tables with confidence scores
  • πŸ€– CI/CD native β€” --fail-on-detect exits with code 1 for pipeline gates
  • ⚑ Row sampling β€” --sample 1000 limit for rapid audit sampling on massive files
  • πŸ”’ Auto-redaction β€” --redact creates a sanitized copy of your data
  • πŸ“Š CSV reports β€” Save all findings to a structured report file
  • ⚑ Fast β€” Pure regex + algorithmic validation, no heavy ML models

πŸ“¦ Installation

# Base installation (Lightweight)
pip install pii-radar

# With Azure Blob Storage & Azure Event Hubs support
pip install "pii-radar[azure]"

# With Parquet support
pip install "pii-radar[parquet]"

# Everything (Azure Blob/EventHubs + Parquet)
pip install "pii-radar[all]"

Or install from source:

git clone https://github.com/nithin42/pii-radar.git
cd pii-radar
pip install -e ".[dev]"

πŸš€ Quick Start

# Scan a CSV file
pii-radar scan data/customers.csv

# Fast sampling (scan only first 1,000 rows)
pii-radar scan data/large_file.csv --sample 1000

# Scan a JSON file
pii-radar scan logs/events.json

# Scan an entire directory
pii-radar scan data/

# Get JSON output (great for scripts)
pii-radar scan data.csv --output json

# Only show high-confidence detections
pii-radar scan data.csv --min-confidence 0.9

# Save a report to CSV
pii-radar scan data.csv --report pii_report.csv

# Create a redacted copy
pii-radar scan data.csv --redact data_clean.csv

# Use in CI/CD β€” fails build if PII found
pii-radar scan data.csv --fail-on-detect

πŸ—οΈ Architecture

CLI Interface (cli.py)
   β”‚
   β”œβ”€β–Ί scan_file / scan_directory (scanner.py)
   β”‚     β”‚
   β”‚     β”œβ”€β–Ί File Readers (readers.py) β€” CSV / JSON / Parquet Cell Stream
   β”‚     β”‚
   β”‚     └─► Heuristic Engine (detectors.py)
   β”‚           β”œβ”€ Email (RFC-compliant regex)
   β”‚           β”œβ”€ SSN (Format + Range Rejection)
   β”‚           β”œβ”€ Credit Card (Luhn Mod-10 Checksum)
   β”‚           β”œβ”€ Phone (Word-bounded pattern)
   β”‚           β”œβ”€ IP Address (IPv4 0-255 Octet Validation)
   β”‚           └─ Date of Birth (Column-Name Heuristic + Format)
   β”‚
   └─► Reporting Layer (reporter.py)
         β”œβ”€ Rich Terminal Panel & Table
         β”œβ”€ JSON Pipeline Stream
         └─ CSV Compliance Report

πŸ“Š Detection Capabilities & Validation

PII Type Verification Strategy Accuracy / False Positive Defense
EMAIL RFC-compliant regex 99% β€” Word boundary enforced
SSN Format + Area exclusion 98% β€” Rejects invalid 000, 666, 900+ ranges
CREDIT_CARD Luhn Mod-10 Algorithm 99% β€” Eliminates random 16-digit number false positives
IP_ADDRESS IPv4 + Octet range check 95% β€” Rejects 999.x.x.x and version strings
PHONE US/International regex 92% β€” Enforces strict \b word boundaries
DATE_OF_BIRTH Format + Column Heuristics 95% β€” Contextual matching (dob, birth, bday)

πŸ§ͺ Performance Benchmark

Run the reproducible benchmark script locally:

python examples/benchmark.py
  • Dataset: 10,000 rows x 7 columns (70,000 cells)
  • Throughput: ~45,000–60,000 cells/second
  • Memory Overhead: Minimal (generator-based cell streaming)

πŸ”§ CI/CD Integration

GitHub Actions

- name: Scan for PII before merge
  run: |
    pip install pii-radar
    pii-radar scan data/ --fail-on-detect --min-confidence 0.85

Pre-commit Hook

Add to .pre-commit-config.yaml:

- repo: local
  hooks:
    - id: pii-radar
      name: PII Scanner
      entry: pii-radar scan
      args: [--fail-on-detect, --min-confidence, "0.9"]
      language: python
      types: [csv, json]

πŸ“ Project Structure

pii-radar/
β”œβ”€β”€ src/pii_radar/
β”‚   β”œβ”€β”€ cli.py          ← Click CLI entry point (--sample, --fail-on-detect)
β”‚   β”œβ”€β”€ scanner.py      ← Core scan orchestration with row limits
β”‚   β”œβ”€β”€ detectors.py    ← Luhn + IPv4 range + DOB heuristics engine
β”‚   β”œβ”€β”€ readers.py      ← CSV / JSON / Parquet readers
β”‚   └── reporter.py     ← Rich terminal + JSON + CSV output
β”œβ”€β”€ tests/
β”‚   β”œβ”€β”€ conftest.py     ← Shared fixtures
β”‚   β”œβ”€β”€ test_detectors.py
β”‚   β”œβ”€β”€ test_negative_cases.py  ← False positive & Luhn unit tests
β”‚   β”œβ”€β”€ test_scanner.py
β”‚   └── test_cli.py
β”œβ”€β”€ examples/
β”‚   β”œβ”€β”€ sample.csv
β”‚   β”œβ”€β”€ sample.json
β”‚   └── benchmark.py    ← Performance benchmarking tool
β”œβ”€β”€ .github/workflows/  ← CI/CD matrix (Ubuntu + Windows)
β”œβ”€β”€ pyproject.toml
β”œβ”€β”€ Makefile
└── README.md

πŸ“„ License

MIT β€” see LICENSE.


πŸ‘€ Author

Nithin Β· github.com/nithin42 Β· kumbam.nithingoud@gmail.com

Part of an elite Data Science & Secure Computing portfolio. Focused on data privacy, reproducible ML, and secure systems engineering.

About

CLI tool to scan CSV, JSON and Parquet files for PII -> emails, phones, SSNs, credit cards and more

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

43 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages