Core
MaskBase
Bases: ABC
Source code in src/anonymizer_data/core/base.py
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | |
anonymize()
Returns and persists the anonymized value
Source code in src/anonymizer_data/core/base.py
21 22 23 24 25 | |
MaskDict
Bases: MaskBase[DataDict]
Source code in src/anonymizer_data/core/dict.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | |
with_keys(keys)
Reconfigures the dictionary mask to use only the specified keys.
Source code in src/anonymizer_data/core/dict.py
46 47 48 49 50 51 52 53 | |
MaskList
Bases: MaskBase[list[T]]
This class anonymizes data contained in lists. Just like MaskDict, it can be data of type str, dict or list.
Attributes:
| Name | Type | Description |
|---|---|---|
value |
str
|
The string to anonymize. |
type_mask |
Optional[str]
|
The type mask to anonymize. Default is "string". |
string_masker |
bool
|
If false the string will never be anonymized. default is True. |
size_anonymization |
float
|
The size of the anonymized string. |
Note
The "size_anonymization" parameter will be passed to MaskStr for each string contained in "value" as well as the other parameters, keeping this in mind be aware that if you pass an invalid value a ValueError may occur when calling the "anonymize" method.
Examples:
>>> from anonymizer_data.core import MaskList
>>> mask_list = MaskList(["Hello world", "Hello Python"])
>>> print(mask_list)
["Hello world", "Hello Python"]
>>> mask_list.anonymize()
['*******orld', '********thon']
>>> mask_list = MaskList(["Hello world", "Hello Python"], size_anonymization=0.5) # anonymizing by half
>>> print(mask_list.anonymize())
['***** world', '******Python']
>>> mask_list.view() # View original list
["Hello world", "Hello Python"]
Raises:
| Type | Description |
|---|---|
ValueError
|
Value {value} is not valid. |
Source code in src/anonymizer_data/core/list.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | |
MaskStr
Bases: MaskBase[str]
Class to anonymize strings.
Attributes:
| Name | Type | Description |
|---|---|---|
value |
str
|
The string to anonymize. |
type_mask |
Optional[str]
|
The type mask to anonymize. Default is "string". |
anonymize_string |
Optional[bool]
|
If false the string will never be anonymized. default is True. |
size_anonymization |
Optional[float]
|
The size of the anonymized string. |
string_masker |
Optional[MaskDispatch]
|
Dispatcher of the string to anonymize. |
Examples:
>>> string = MaskStr("Hello world")
>>> print(string)
Hello world
>>> string.anonymize()
'*******ord'
>>> print(string)
*******ord
>>> string.view() # View original string
Hello Word
Raises:
| Type | Description |
|---|---|
ValueError
|
The 'size_anonymization' field must be between 0 and 1. |
ValueError
|
The 'size_anonymization' must be a float. |
ValueError
|
Value {value} is not valid. |
Source code in src/anonymizer_data/core/string.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | |
dispatch_value_mask(value, **extra)
Factory that contains the logic for choosing the correct masker for each type of data.
Source code in src/anonymizer_data/core/dispatcher.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | |