Fast, zero-dependency DLP pattern scanner — detects PII, secrets, and sensitive data in text
Project description
dlp-patterns
Fast, zero-dependency DLP pattern scanner for Python.
Detects PII, secrets, and sensitive data in any text — documents, logs, source code, emails. Built from the scanning engine that powers Spidercob, an enterprise DLP platform.
import dlp_patterns
result = dlp_patterns.scan("My SSN is 432-78-9012 and CC 4111 1111 1111 1111")
print(result.highest_severity) # CRITICAL
print(result.critical[0].type) # credit_card
clean = dlp_patterns.redact("Send to alice@corp.com with CC 4111 1111 1111 1111")
# "Send to [REDACTED: Email Address] with [REDACTED: Credit Card Number]"
Install
pip install dlp-patterns
No external dependencies. Python 3.9+.
What it detects
| Category | Patterns |
|---|---|
| Financial | Credit cards (Luhn + BIN), SSN, IBAN, bank account, routing number |
| PII | Email, US phone, passport, driver's license, date of birth |
| Healthcare | Medical record numbers, ICD-10 codes, NPI, DEA numbers, NDC codes |
| Secrets | AWS keys, GitHub PATs, Slack tokens, Google API keys, Bearer tokens, JWTs |
| Cloud / SaaS | Stripe, SendGrid, Mailgun, Twilio, HuggingFace, NPM, Cloudflare, Azure |
| Infrastructure | DB connection strings, hardcoded passwords, Docker registry auth |
| Crypto | RSA/EC/SSH/PGP private keys, X.509 certs |
| Webhooks | Slack webhooks, Discord webhooks, Telegram bot tokens |
| Cryptocurrency | Bitcoin addresses, Ethereum addresses |
50+ pattern categories total.
Features
- Validators — Luhn check for credit cards, FICA rules for SSNs, JSON decode for JWTs. Reduces false positives before they reach you.
- Entropy gating — Shannon entropy + sliding-window analysis rejects low-entropy matches (e.g.
aaaaaaa...) from generic secret patterns. - Context scoring — Each finding gets a
context_score(0–1) based on surrounding words. Proximity toproduction,secret,deployboosts the score; proximity toexample,placeholder,testlowers it. - Required context keywords — Patterns like ICD-10 codes and Telegram tokens only fire when relevant keywords appear nearby.
secrets_onlymode — Scan just for API keys and credentials, skipping PII. Faster for CI/CD secret scanning.redact()— Replace all findings with[REDACTED: <type>].fuzz()— Replace findings with realistic fake values (requiresfaker). Useful for building safe test datasets from production data.- CLI —
dlp-scancommand for shell pipelines and CI.
Usage
Python API
import dlp_patterns
# Scan
result = dlp_patterns.scan(text)
result.has_findings # bool
result.highest_severity # "CRITICAL" | "HIGH" | "MEDIUM" | "LOW" | None
result.critical # list[Finding]
result.all # all findings across severities
result.elapsed_ms # scan time in milliseconds
# Each Finding:
f = result.critical[0]
f.type # "credit_card"
f.description # "Credit Card Number"
f.value # masked: "4111...1111"
f.severity # "CRITICAL"
f.position # "char 10-29"
f.context # surrounding text (±100 chars)
f.context_score # float 0.0–1.0
f.context_keywords_found # ["payment", "billing"]
# Secrets only (faster for source code scanning)
result = dlp_patterns.scan(code, secrets_only=True)
# Redact
clean = dlp_patterns.redact(text)
# Fuzz (pip install dlp-patterns[fuzz])
safe = dlp_patterns.fuzz(text)
# JSON output
result.to_dict()
CLI
# Scan a string
dlp-scan "My SSN is 432-78-9012"
# Scan a file
dlp-scan path/to/document.txt
# Pipe from stdin
cat logfile.txt | dlp-scan
# JSON output
dlp-scan --json document.txt
# Redact in place
dlp-scan --redact document.txt > clean.txt
# Secrets only (for source code)
dlp-scan --secrets-only src/config.py
# Exit code: 1 if CRITICAL findings, 0 otherwise — useful in CI
dlp-scan --secrets-only . && echo "clean"
Use in CI (GitHub Actions)
- name: DLP secret scan
run: |
pip install dlp-patterns
dlp-scan --secrets-only --json src/ | tee dlp-report.json
Advanced — use Scanner directly
from dlp_patterns import Scanner
scanner = Scanner()
# Reuse the same instance (compiled patterns cached)
for text in documents:
result = scanner.scan(text)
if result.has_findings:
print(result.to_dict())
Enterprise
Need a full DLP platform with dashboards, audit logs, ICAP proxy integration, Gmail/Slack scanning, compliance reports, and AI-powered analysis?
→ Spidercob — the enterprise DLP platform this library is extracted from.
License
Apache 2.0 — free for commercial use.
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 dlp_patterns-0.1.0.tar.gz.
File metadata
- Download URL: dlp_patterns-0.1.0.tar.gz
- Upload date:
- Size: 15.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ca43f416be2308197c2bc3491e339227f2fa781070bcebdd2322c9dda83f1a4a
|
|
| MD5 |
03c7c56134d23c56f231b9f45e7d8909
|
|
| BLAKE2b-256 |
b70bc5d4045e380abdd29f7ab92b6946436886912dec52d3e42c0155617d830e
|
File details
Details for the file dlp_patterns-0.1.0-py3-none-any.whl.
File metadata
- Download URL: dlp_patterns-0.1.0-py3-none-any.whl
- Upload date:
- Size: 14.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fb17891929f43f739d4bf8d38ecebc23cbb4024e4293b42cccd60d59c130d7e3
|
|
| MD5 |
c32268619e64c39ee57bed58107f89ee
|
|
| BLAKE2b-256 |
c95d70450fe087e1a62de00aebf97c3ea978fc0d4aff7c239eb8d429ad279b8d
|