Privacy-first, hybrid PII detection and redaction engine using local rules and Hugging Face Transformers.
Project description
🛡️ PII Warden (Python Package)
Privacy-first, hybrid PII (Personally Identifiable Information) detection and redaction engine for Python applications.
It combines local regex & checksum patterns with Hugging Face Transformers to offer context-aware token classification locally on your machine.
Features
- Hybrid Two-Tier Engine:
- Tier 1 (Instant & Offline): Identifies structured data (Credit Cards, Emails, Phone Numbers, IP Addresses, IBANs) using fast regexes and mathematical checksum validation.
- Tier 2 (Context-Aware ML): Uses a fine-tuned token classification model (DistilBERT) from Hugging Face to detect names, organizations, and locations.
- Deduplication & Collision Resolution: Automatically merges overlapping matches and resolves boundary clashes between local rules and machine learning predictions.
- Privacy First: Zero API servers or external API hops are required for inference. The model runs locally on your device.
Installation
Install the package via pip:
pip install pii-warden
Make sure you have PyTorch installed for your system. If not, pip will attempt to fetch it as a dependency.
Quick Start
1. Tier 1: Rules & Checksums Only (Offline, Zero-Dependency)
No model is loaded; it runs instantly using local rules.
from pii_warden import PIIWarden
# Initialize the warden
warden = PIIWarden()
# Analyze text
result = warden.analyze("My credit card is 4111-1111-1111-1111 and email is sam@example.com")
print(result["redacted_text"])
# Output: "My credit card is [ID_1] and email is [EMAIL_1]"
print(result["entities"])
# Output: Detailed list of matched entities (type, start, end, score, source)
2. Tier 2: Hybrid Mode (Local Rules + Transformer Model)
Loads a PyTorch Transformer model from the Hugging Face hub for high-accuracy NER.
from pii_warden import PIIWarden
warden = PIIWarden()
# Load the local model (downloads on first call)
warden.load_model()
# Analyze using hybrid rules + model classification
result = warden.analyze("My name is Samuel Olubukun and my phone number is +1-555-0199")
print(result["redacted_text"])
# Output: "My name is [ID_2] [ID_1] and my phone number is [PHONE_1]"
Model Details & Provenance
The ML component of the engine is optimized in two forms:
- Base PyTorch Model: The core classifier is powered by
samuelolubukun/pii-ner-finetuned-distilbert. This model is a fine-tune of DistilBERT trained on top of AI4Privacy's high-quality multilingual PII dataset, optimized for Token Classification (NER). - Edge ONNX Model: If you need to run in web environments or browsers, check out our companion NPM library
pii-wardenwhich runs the ONNX optimized versionsamuelolubukun/pii-ner-edge-optimized.
License
MIT
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pii_warden-1.0.0.tar.gz.
File metadata
- Download URL: pii_warden-1.0.0.tar.gz
- Upload date:
- Size: 6.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0ed7f5d4ecba469f65bea71ebb6bc5411e0a23b091af4c80abc39fa99557ea8e
|
|
| MD5 |
53a4db2cef43eeb354c687815b4b2f00
|
|
| BLAKE2b-256 |
a92f565169779d4f63f4a38d2ec49bb42ab1f0a73c8ca07fc57e3e52b67b20e1
|
File details
Details for the file pii_warden-1.0.0-py3-none-any.whl.
File metadata
- Download URL: pii_warden-1.0.0-py3-none-any.whl
- Upload date:
- Size: 6.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cefe72806c66fcce2e140bef20359be29e2e9f677892f13d5a09eccf0f77ddce
|
|
| MD5 |
0d894fe339ea68f0229f2bef693c2512
|
|
| BLAKE2b-256 |
4cec52ddf4caa705a6d9f798962f98b674bd21c12627ed33aadbd625950b0326
|