Functions
create_redactor()
def create_redactor(config: RedactorConfig) -> Callable[[Any], Any]
Builds a redactor function from a RedactorConfig. The returned callable recursively redacts strings in any value (strings, dicts, lists, tuples).
create_default_redactor()
def create_default_redactor() -> Callable[[Any], Any]
Equivalent to create_redactor(RedactorConfig()) — returns a redactor with all default patterns enabled.
Parameters
Configuration specifying which patterns to apply.
Returns
A callable (value: Any) -> Any that recursively redacts PII. Safe to call on strings, dicts, lists, or nested structures.
Examples
Build and pass to init()
import re
from rdk import RedactorConfig, create_redactor, init
redactor = create_redactor(RedactorConfig(
redact_emails=True,
redact_phones=True,
custom_patterns=[
(re.compile(r"ACC-\d{8}"), "[ACCOUNT REDACTED]"),
],
))
init(
endpoint="...",
api_key="...",
redactor=redactor,
)
Standalone use
from rdk import create_redactor, RedactorConfig
redactor = create_redactor(RedactorConfig(redact_emails=True, redact_phones=False))
clean = redactor({
"user": "john@example.com",
"phone": "555-123-4567",
"note": "Contact john@example.com for details",
})
# {"user": "[EMAIL REDACTED]", "phone": "555-123-4567", "note": "Contact [EMAIL REDACTED] for details"}
Default redactor
from rdk.filters import create_default_redactor
redactor = create_default_redactor()
clean = redactor("Call 555-123-4567 or email me at john@example.com")
# "Call [PHONE REDACTED] or email me at [EMAIL REDACTED]"
See Also