🛡️ Data Privacy & Redaction¶
Privacy protection and sensitive data redaction functions.
🎯 Overview¶
Data privacy features provide automatic PII detection and redaction for secure data handling.
📦 Functions¶
RedactionEngine¶
datason.RedactionEngine(redact_fields: Optional[List[str]] = None, redact_patterns: Optional[List[str]] = None, redact_large_objects: bool = False, large_object_threshold: int = 10 * 1024 * 1024, redaction_replacement: str = '<REDACTED>', include_redaction_summary: bool = False, audit_trail: bool = False)
¶
Core redaction engine for sensitive data protection.
Initialize the redaction engine.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
redact_fields
|
Optional[List[str]]
|
List of field patterns to redact (e.g., ["password", "*.secret"]) |
None
|
redact_patterns
|
Optional[List[str]]
|
List of regex patterns to redact |
None
|
redact_large_objects
|
bool
|
Whether to redact objects larger than threshold |
False
|
large_object_threshold
|
int
|
Size threshold for large object redaction (bytes) |
10 * 1024 * 1024
|
redaction_replacement
|
str
|
Replacement text for redacted content |
'<REDACTED>'
|
include_redaction_summary
|
bool
|
Whether to include redaction summary |
False
|
audit_trail
|
bool
|
Whether to maintain audit trail for compliance |
False
|
Source code in datason/redaction.py
get_audit_trail() -> Optional[List[Dict[str, Any]]]
¶
Get audit trail if enabled.
Source code in datason/redaction.py
get_redaction_summary() -> Optional[Dict[str, Any]]
¶
Get redaction summary if enabled.
Source code in datason/redaction.py
process_object(obj: Any, field_path: str = '', _visited: Optional[Set[int]] = None) -> Any
¶
Process an object for redaction.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj
|
Any
|
Object to process |
required |
field_path
|
str
|
Current field path |
''
|
_visited
|
Optional[Set[int]]
|
Set of visited object IDs (for circular reference detection) |
None
|
Returns:
Type | Description |
---|---|
Any
|
Processed object with redactions applied |
Source code in datason/redaction.py
redact_field_value(value: Any, field_path: str) -> Any
¶
Redact a field value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
Any
|
Value to redact |
required |
field_path
|
str
|
Field path for audit trail |
required |
Returns:
Type | Description |
---|---|
Any
|
Redacted value |
Source code in datason/redaction.py
redact_large_object(obj: Any, field_path: str = '') -> Any
¶
Redact a large object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj
|
Any
|
Object to redact |
required |
field_path
|
str
|
Field path for audit trail |
''
|
Returns:
Type | Description |
---|---|
Any
|
Redacted representation |
Source code in datason/redaction.py
redact_text(text: str, context: str = '') -> Tuple[str, bool]
¶
Redact sensitive patterns from text.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text
|
str
|
Text to redact |
required |
context
|
str
|
Context for audit trail |
''
|
Returns:
Type | Description |
---|---|
Tuple[str, bool]
|
Tuple of (redacted_text, was_redacted) |
Source code in datason/redaction.py
should_redact_large_object(obj: Any) -> bool
¶
Check if object should be redacted due to size.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj
|
Any
|
Object to check |
required |
Returns:
Type | Description |
---|---|
bool
|
True if object should be redacted due to size |
Source code in datason/redaction.py
Pre-built Redaction Engines¶
datason.create_financial_redaction_engine() -> RedactionEngine
¶
Create a redaction engine optimized for financial data.
Source code in datason/redaction.py
datason.create_healthcare_redaction_engine() -> RedactionEngine
¶
Create a redaction engine optimized for healthcare data.
Source code in datason/redaction.py
datason.create_minimal_redaction_engine() -> RedactionEngine
¶
Create a minimal redaction engine for basic privacy protection.
Source code in datason/redaction.py
🔗 Related Documentation¶
- Modern API - dump_secure() function
- Core Functions - Using with traditional API