Handlers
MaskDispatch
Class responsible for managing anonymization handlers.
Source code in src/anonymizer_data/handlers/dispatch.py
4 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 | |
add_handler(type_mask, handler)
classmethod
Adds a handler for a specific mask type.
Source code in src/anonymizer_data/handlers/dispatch.py
20 21 22 23 | |
mask(type_mask, data, **kwargs)
Applies the appropriate mask to the given data if the type exists.
Source code in src/anonymizer_data/handlers/dispatch.py
25 26 27 28 29 | |
register(*type_masks)
classmethod
Decorator to register a handler for specific mask types.
Source code in src/anonymizer_data/handlers/dispatch.py
9 10 11 12 13 14 15 16 17 18 | |
anonymize_all_string(string, **kwargs)
Anonymize all characters of a string.
Source code in src/anonymizer_data/handlers/functions.py
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 | |
anonymize_cep(cep, **kwargs)
Anonymize a Brazilian CEP (Código de Endereçamento Postal) by masking parts of it.
This function takes a CEP number as input, removes any non-numeric characters, and returns a masked version of the CEP. If the input CEP is formatted with a hyphen, it will mask the first five digits while revealing the last three digits. If the CEP is provided without formatting, it will mask all but the last three digits.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cep
|
str
|
The original CEP number to be anonymized, which may include non-numeric characters. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The masked version of the CEP number. |
Source code in src/anonymizer_data/handlers/functions.py
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 | |
anonymize_cnpj(cnpj, **kwargs)
Anonymize a Brazilian CNPJ (Cadastro Nacional da Pessoa Jurídica) number by masking parts of it.
This function takes a CNPJ number as input, removes any non-numeric characters, and returns a masked version of the CNPJ. If the input CNPJ is formatted with dots, slashes, and a dash, it will mask the first two digits and the last four digits, while revealing the middle digits. If the CNPJ is provided without formatting, it will mask all but the last four digits.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cnpj
|
str
|
The original CNPJ number to be anonymized, which may include non-numeric characters. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The masked version of the CNPJ number. |
Source code in src/anonymizer_data/handlers/functions.py
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 | |
anonymize_cpf(cpf, **kwargs)
Anonymize a Brazilian CPF (Cadastro de Pessoas Físicas) number by masking parts of it.
This function takes a CPF number as input, removes any non-numeric characters, and returns a masked version of the CPF. If the input CPF is formatted with dots and a dash, it will mask the first three digits and the last two digits, while revealing the middle digits. If the CPF is provided without formatting, it will mask all but the last four digits.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cpf
|
str
|
The original CPF number to be anonymized, which may include non-numeric characters. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The masked version of the CPF number. |
Source code in src/anonymizer_data/handlers/functions.py
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 | |
anonymize_email(email, **kwargs)
Anonymize an email address by masking the username part.
This function takes an email address as input and replaces the username part (the part before the '@') with a masked version, while keeping the domain part intact. The level of anonymization for the username can be adjusted using additional parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
email
|
str
|
The original email address to be anonymized. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The masked version of the email address. |
Source code in src/anonymizer_data/handlers/functions.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | |
anonymize_numeric_digits(string, **kwargs)
Anonymize all numeric digits in a string by replacing them with asterisks.
This function scans the input string and replaces every numeric digit (0-9) with an asterisk (*), effectively anonymizing any sensitive numerical information.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
string
|
str
|
The original string containing numeric digits to be anonymized. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The modified string with all numeric digits replaced by asterisks. |
Source code in src/anonymizer_data/handlers/functions.py
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | |
anonymize_phone_number(phone, **kwargs)
Anonymize a phone number by masking parts of it while preserving its format.
This function takes a phone number as input, removes any non-numeric characters, and returns a masked version of the phone number. The format is preserved, with specific parts masked according to the rules defined.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
phone
|
str
|
The original phone number to be anonymized, which may include non-numeric characters. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The masked version of the phone number. |
Source code in src/anonymizer_data/handlers/functions.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | |
anonymize_pis(pis, **kwargs)
Anonymize a Brazilian PIS (Programa de Integração Social) number by masking parts of it.
This function takes a PIS number as input, removes any non-numeric characters, and returns a masked version of the PIS. If the input PIS is formatted with a hyphen, it will mask the first five digits and the last two digits, while revealing the middle digits. If the PIS is provided without formatting, it will mask all but the last four digits.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pis
|
str
|
The original PIS number to be anonymized, which may include non-numeric characters. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The masked version of the PIS number. |
Source code in src/anonymizer_data/handlers/functions.py
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 | |
anonymize_rg(rg, **kwargs)
Anonymize a Brazilian RG (Registro Geral) number by masking parts of it.
This function takes an RG number as input, removes any non-numeric characters, and returns a masked version of the RG. If the input RG is formatted with dots and a dash, it will mask the first two digits and the last two digits, while revealing the middle digits. If the RG is provided without formatting, it will mask all but the last four digits.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rg
|
str
|
The original RG number to be anonymized, which may include non-numeric characters. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The masked version of the RG number. |
Source code in src/anonymizer_data/handlers/functions.py
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 | |
anonymize_string(value, size_anonymization, **kwargs)
Anonymize a string by masking a specified portion of it.
This function takes a string and replaces a portion of its characters with asterisks (*).
The extent of the masking is determined by the size_anonymization parameter, which
specifies the fraction of the string to be masked.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str
|
The original string to be anonymized. |
required |
size_anonymization
|
float
|
A float value between 0 and 1 indicating the proportion of the string to mask. For example, 0.5 will mask half of the characters in the string. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The masked version of the input string. If |
Source code in src/anonymizer_data/handlers/functions.py
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 | |
anonymize_substring(main_text, substring, occurrences=1, **kwargs)
Anonymize a specified substring in the main text by replacing it with asterisks.
This function searches for the given substring within the main text and replaces it with asterisks. The number of occurrences to replace can be specified.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
main_text
|
str
|
The original text in which the substring will be anonymized. |
required |
substring
|
str
|
The substring to be replaced with asterisks. |
required |
occurrences
|
Optional[int]
|
The number of times to replace the substring with asterisks (default is 1). |
1
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The modified text with the specified substring replaced by asterisks. |
Source code in src/anonymizer_data/handlers/functions.py
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | |
mask_string_part(string, start, end, occurrences=1, **kwargs)
Mask a specific part of a string with asterisks.
This function replaces a substring of the provided string, defined by the start and end indices, with asterisks. The number of occurrences to replace can be specified.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
string
|
str
|
The original string in which the substring will be masked. |
required |
start
|
int
|
The starting index of the substring to be masked. |
required |
end
|
int
|
The ending index of the substring to be masked. |
required |
occurrences
|
Optional[int]
|
The number of times to replace the substring with asterisks (default is 1). |
1
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The modified string with the specified substring replaced by asterisks. |
Source code in src/anonymizer_data/handlers/functions.py
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | |