The Anonymize library provides functionality to anonymize sensitive data in different formats, such as strings, lists, and dictionaries. This library is useful for developers who need to ensure data privacy in their applications.
Project description
Anonymize
The Anonymize library provides functionality to anonymize sensitive data in different formats, such as strings, lists, and dictionaries. This library is useful for developers who need to ensure data privacy in their applications.
Quickstart
Installation
pip
pip install anonymize
uv
uv add anonymize
Anonymize strings
To anonymize strings in your project you can use the MaskStr
class.
Example:
from anonymizer_data import MaskStr
string = MaskStr("Hello Word")
string.anonymize()
print(string) # result: *******ord
You can control how much percent the string will be anonymized relative to its length via the size_anonymization
parameter. You can pass a value from 0 to 1.
You can also pass a negative value to reverse the anonymization.
Example:
from anonymizer_data import MaskStr
string = MaskStr("Hello Word", size_anonymization=0.5)
string.anonymize()
print(string) # result: ***** Word
MaskStr("Hello Word", size_anonymization=0.5).anonymize() # result: Hello*****
Anonymize lists
List anonymization is done by the MaskList
class.
Example:
from anonymizer_data import MaskList
list_data = MaskList(['1234435', '98765432', '24295294', 'Jhon Doe'])
list_data.anonymize()
print(list_data) # result: ['****435', '*****432', '*****294', '*****Doe']
Anonymize dict
Dictionary's anonymization is done by the MaskList
class.
Example:
from anonymizer_data import MaskDict
dict_data = MaskDict(
{
"username": "JhonDoe",
"password": "123Change",
"roles": ['Admin', 'developer'],
"contact": {
"number": "+55 (99) 99999-9999"
}
}
)
dict_data.anonymize()
print(dict_data) # result: {'username': '****Doe', 'password': '******nge', 'roles': ['***in', '******per'], 'contact': {'number': '*************9-9999'}}
Note: Dictionary anonymization brings with it other advantages such as: choosing which keys in the dictionary should be anonymized; enabling exclusive anonymization based on the key. For example,
jhondue@example.com
would become******e@example.com
. To learn more, access the tutorial
cli
You can anonymize strings from the command line. For this you need to have uv installed.
Exemple:
{{ commands.run }} "Hello Word"
*******ord
{{ commands.run }} --help
Usage: anonymize [OPTIONS] VALUE [TYPE_MASK] [SIZE_ANONYMIZATION]
cli anonymization string
╭─ Arguments ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ * value TEXT The string you want to anonymize [default: None] [required] │
│ type_mask [TYPE_MASK] The type mask to use [default: string] │
│ size_anonymization [SIZE_ANONYMIZATION] The size anonymization factor [default: 0.7] │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─ Options ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ --install-completion Install completion for the current shell. │
│ --show-completion Show completion for the current shell, to copy it or customize the installation. │
│ --help Show this message and exit. │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file anonymizer_data-0.1.0.tar.gz
.
File metadata
- Download URL: anonymizer_data-0.1.0.tar.gz
- Upload date:
- Size: 211.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 500005b07e6a529f8f71ee5fe111bfe17c82a4dd462936037890512d0561182e |
|
MD5 | fcb3839fce984c98a12dac292f3b8a40 |
|
BLAKE2b-256 | 7cccac4372ef3e43eeff386045110b8fcea0479769e58b62d67f07ccfb9313e1 |
File details
Details for the file anonymizer_data-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: anonymizer_data-0.1.0-py3-none-any.whl
- Upload date:
- Size: 11.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ba454d4a3f1194dc19d252be0da3ac0a74344231b7db39f66dffdcbfc5326664 |
|
MD5 | 845d0dd6dc4625bb2b81fcc7764e1b31 |
|
BLAKE2b-256 | 554fe66263f07929be8fc03c45742772a93488d9a0b2d44432c59668cde03830 |