-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.py
More file actions
57 lines (50 loc) · 1.4 KB
/
Copy pathexample.py
File metadata and controls
57 lines (50 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env python3
"""Example usage of the redactpii package."""
from redactpii import Redactor
# Basic usage
print("=== Basic Usage ===")
redactor = Redactor()
text = "Hi David Johnson, call 555-555-5555 or email david@example.com"
clean = redactor.redact(text)
print(f"Original: {text}")
print(f"Redacted: {clean}")
print()
# Check for PII without redacting
print("=== Check for PII ===")
if redactor.has_pii("Contact test@example.com for details"):
print("PII detected!")
clean = redactor.redact("Contact test@example.com for details")
print(f"Redacted: {clean}")
print()
# Redact objects
print("=== Redact Objects ===")
redactor = Redactor({"rules": {"EMAIL": True}})
user = {
"name": "John Doe",
"email": "john@example.com",
"profile": {
"contact": "contact@example.com",
},
}
clean = redactor.redact_object(user)
print(f"Original: {user}")
print(f"Redacted: {clean}")
print()
# Custom rules
print("=== Custom Rules ===")
import re
redactor = Redactor({
"rules": {"EMAIL": True},
"custom_rules": [re.compile(r"\b\d{5}\b")], # 5-digit codes
})
result = redactor.redact("Email: test@example.com, Code: 12345")
print(f"Result: {result}")
print()
# Global replacement
print("=== Global Replacement ===")
redactor = Redactor({
"rules": {"EMAIL": True},
"global_replace_with": "[REDACTED]",
})
result = redactor.redact("test@example.com")
print(f"Result: {result}")