anonymize-data is a powerful, flexible, and extensible Python library designed to sanitize and anonymize sensitive data. It provides seamless anonymization for strings, lists, and dictionaries, ensuring data privacy in your applications and logs.
- Multi-Type Support: Easily mask primitive strings, nested lists, and complex dictionaries.
- Fluent API: Chain methods for elegant dictionary manipulation (e.g.,
.with_keys(['cpf', 'password'])). - Global Configuration: Centrally manage default mask characters and security policies.
- Strict Data Privacy: Built-in fallback protection masks invalid sensitive data entirely to prevent silent data leaks.
- Extensible Architecture: Customize behavior easily thanks to an underlying Registry Pattern.
- Command-Line Interface (CLI): Quickly anonymize text right from your terminal.
Choose your preferred package manager:
pip:
pip install anonymize-datauv:
uv add anonymize-dataAnonymize data with just a few lines of code:
from anonymizer_data import MaskStr, MaskDict
# String Anonymization
string_mask = MaskStr("Hello World")
print(string_mask.anonymize()) # Output: *******orld
# Dictionary Anonymization with Fluent API
user_data = {
"username": "JhonDoe",
"password": "123Change",
"roles": ['Admin', 'developer'],
"contact": {
"number": "+55 (99) 99999-9999"
}
}
masked_dict = MaskDict(user_data).with_keys(['password', 'number'])
print(masked_dict.anonymize())
# Output: {'username': 'JhonDoe', 'password': '*********', 'roles': ['Admin', 'developer'], 'contact': {'number': '*******************'}}Note: Dictionary anonymization allows for exclusive targeting based on keys. For example, specific sensitive fields like emails or phone numbers can be mapped to specialized masking functions under the hood.
You can anonymize strings directly from your terminal using uv:
uv run anonymize "Hello World"
# Output: *******orld
uv run anonymize --helpFor comprehensive guides, advanced usage, global configurations, and API reference, please visit our Official Documentation.
