A Python library for anonymizing, masking, and encrypting sensitive data with a small, focused API.
- Anonymization — free-form text, IPv4 addresses, emails, phone numbers
- Localized identifiers — US SSN, Brazil CPF/CNPJ
- Masking — credit cards with Luhn validation, formatted identifiers, partial emails
- Pseudonymization — reversible tokens, plus deterministic tokens for joins
- Encryption — symmetric encryption and decryption via Fernet
- PII detection — named entity recognition with spaCy (optional extra)
Requires Python 3.10 or newer.
pip install shadow_dataWith PII detection:
pip install "shadow_data[spacy]"
python -m spacy download en_core_web_smfrom shadow_data import (
EmailAnonymization,
Pseudonymizer,
UsaIdentifierAnonymizer,
mask_credit_card,
)
EmailAnonymization.anonymize_email('user@example.com') # '****@****ple.com'
UsaIdentifierAnonymizer('SSN: 479-92-5042').anonymize() # 'SSN: XXX-XX-5042'
mask_credit_card('4111 1111 1111 1111') # '**** **** **** 1111'
pseudonymizer = Pseudonymizer()
token = pseudonymizer.pseudonymize('user@example.com')
pseudonymizer.depseudonymize(token) # 'user@example.com'See Getting started for a full tour, and Choosing a technique if you are unsure which helper fits your case.
poetry install --with dev,docs --extras spacy
make all # ruff, mypy, docs build, and pytest with coverageSee Contributing.
See CHANGELOG.md.
MIT — see LICENSE.