Presidio Anonymizer API Reference
presidio_anonymizer
Anonymizer root module.
deanonymize_engine
Deanonymize anonymized text by using deanonymize operators.
DeanonymizeEngine
Bases: EngineBase
Deanonymize text that was previously anonymized.
| METHOD | DESCRIPTION |
|---|---|
deanonymize |
Receive the text, entities and operators to perform deanonymization over. |
get_deanonymizers |
Return a list of supported deanonymizers. |
add_deanonymizer |
Add a new deanonymizer to the engine. |
remove_deanonymizer |
Remove a deanonymizer from the engine. |
Source code in presidio_anonymizer/deanonymize_engine.py
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 | |
deanonymize
deanonymize(
text: str,
entities: List[OperatorResult],
operators: Dict[str, OperatorConfig],
) -> EngineResult
Receive the text, entities and operators to perform deanonymization over.
| PARAMETER | DESCRIPTION |
|---|---|
operators
|
the operators to apply on the anonymizer result entities
TYPE:
|
text
|
the full text with the encrypted entities
TYPE:
|
entities
|
list of encrypted entities
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
EngineResult
|
EngineResult - the new text and data about the deanonymized entities. |
Source code in presidio_anonymizer/deanonymize_engine.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | |
get_deanonymizers
get_deanonymizers() -> List[str]
Return a list of supported deanonymizers.
Source code in presidio_anonymizer/deanonymize_engine.py
32 33 34 35 | |
add_deanonymizer
add_deanonymizer(deanonymizer_cls: Type[Operator]) -> None
Add a new deanonymizer to the engine.
anonymizer_cls: The deanonymizer class to add to the engine.
Source code in presidio_anonymizer/deanonymize_engine.py
37 38 39 40 41 42 43 44 | |
remove_deanonymizer
remove_deanonymizer(deanonymizer_cls: Type[Operator]) -> None
Remove a deanonymizer from the engine.
deanonymizer_cls: The deanonymizer class to remove from the engine.
Source code in presidio_anonymizer/deanonymize_engine.py
46 47 48 49 50 51 52 53 | |
anonymizer_engine
Handles the entire logic of the Presidio-anonymizer and text anonymizing.
AnonymizerEngine
Bases: EngineBase
AnonymizerEngine class.
Handles the entire logic of the Presidio-anonymizer. Gets the original text and replaces the PII entities with the desired anonymizers.
| METHOD | DESCRIPTION |
|---|---|
anonymize |
Anonymize method to anonymize the given text. |
add_anonymizer |
Add a new anonymizer to the engine. |
remove_anonymizer |
Remove an anonymizer from the engine. |
get_anonymizers |
Return a list of supported anonymizers. |
Source code in presidio_anonymizer/anonymizer_engine.py
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 76 77 78 79 80 81 82 83 84 85 86 87 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 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 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 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 | |
anonymize
anonymize(
text: str,
analyzer_results: List[RecognizerResult],
operators: Optional[Dict[str, OperatorConfig]] = None,
conflict_resolution: ConflictResolutionStrategy = ConflictResolutionStrategy.MERGE_SIMILAR_OR_CONTAINED,
) -> EngineResult
Anonymize method to anonymize the given text.
:example:
from presidio_anonymizer import AnonymizerEngine from presidio_anonymizer.entities import RecognizerResult, OperatorConfig
Initialize the engine with logger.
engine = AnonymizerEngine()
Invoke the anonymize function with the text, analyzer results and
Operators to define the anonymization type.
result = engine.anonymize( text="My name is Bond, James Bond", analyzer_results=[RecognizerResult(entity_type="PERSON", start=11, end=15, score=0.8), RecognizerResult(entity_type="PERSON", start=17, end=27, score=0.8)], operators={"PERSON": OperatorConfig("replace", {"new_value": "BIP"})} )
print(result) text: My name is BIP, BIP. items: [ {'start': 16, 'end': 19, 'entity_type': 'PERSON', 'text': 'BIP', 'operator': 'replace'}, {'start': 11, 'end': 14, 'entity_type': 'PERSON', 'text': 'BIP', 'operator': 'replace'} ]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
the text we are anonymizing
TYPE:
|
analyzer_results
|
A list of RecognizerResult class -> The results we received from the analyzer
TYPE:
|
operators
|
The configuration of the anonymizers we would like to use for each entity e.g.: {"PHONE_NUMBER":OperatorConfig("redact", {})} received from the analyzer
TYPE:
|
conflict_resolution
|
The configuration designed to handle conflicts among entities
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
EngineResult
|
the anonymized text and a list of information about the anonymized entities. |
Source code in presidio_anonymizer/anonymizer_engine.py
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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | |
add_anonymizer
add_anonymizer(anonymizer_cls: Type[Operator]) -> None
Add a new anonymizer to the engine.
anonymizer_cls: The anonymizer class to add to the engine.
Source code in presidio_anonymizer/anonymizer_engine.py
103 104 105 106 107 108 109 110 | |
remove_anonymizer
remove_anonymizer(anonymizer_cls: Type[Operator]) -> None
Remove an anonymizer from the engine.
anonymizer_cls: The anonymizer class to remove from the engine.
Source code in presidio_anonymizer/anonymizer_engine.py
112 113 114 115 116 117 118 119 | |
get_anonymizers
get_anonymizers() -> List[str]
Return a list of supported anonymizers.
Source code in presidio_anonymizer/anonymizer_engine.py
224 225 226 227 | |
batch_anonymizer_engine
BatchAnonymizerEngine
BatchAnonymizerEngine class.
A class that provides functionality to anonymize in batches.
| PARAMETER | DESCRIPTION |
|---|---|
anonymizer_engine
|
An instance of the AnonymizerEngine class.
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
anonymize_list |
Anonymize a list of strings. |
anonymize_dict |
Anonymize values in a dictionary. |
Source code in presidio_anonymizer/batch_anonymizer_engine.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 76 77 78 79 80 81 82 83 84 | |
anonymize_list
anonymize_list(
texts: List[Optional[Union[str, bool, int, float]]],
recognizer_results_list: List[List[RecognizerResult]],
**kwargs
) -> List[Union[str, Any]]
Anonymize a list of strings.
| PARAMETER | DESCRIPTION |
|---|---|
texts
|
List containing the texts to be anonymized (original texts). Items with a
TYPE:
|
recognizer_results_list
|
A list of lists of RecognizerResult, the output of the AnalyzerEngine on each text in the list.
TYPE:
|
kwargs
|
Additional kwargs for the
DEFAULT:
|
Source code in presidio_anonymizer/batch_anonymizer_engine.py
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 | |
anonymize_dict
anonymize_dict(
analyzer_results: Iterable[DictRecognizerResult], **kwargs
) -> Dict[str, str]
Anonymize values in a dictionary.
| PARAMETER | DESCRIPTION |
|---|---|
analyzer_results
|
Iterator of
TYPE:
|
kwargs
|
Additional kwargs for the
DEFAULT:
|
Source code in presidio_anonymizer/batch_anonymizer_engine.py
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 76 77 78 79 80 81 82 83 84 | |
services
Services init.
validators
Anomnymizers validations utility methods.
| FUNCTION | DESCRIPTION |
|---|---|
validate_parameter_in_range |
Validate an anonymizer parameter. |
validate_parameter_not_empty |
Validate parameter exists and not only empty. |
validate_parameter_exists |
Validate parameter is not empty. |
validate_parameter |
Validate an anonymizer parameter. |
validate_type |
Validate an anonymizer parameter. |
validate_parameter_in_range
validate_parameter_in_range(
values_range, parameter_value, parameter_name: str, parameter_type: type
) -> None
Validate an anonymizer parameter.
validates the existence of an anonymizer parameter and that it is an instance of the parameter_type and that it is within the range of provided values. Otherwise, raise the appropriate InvalidParamException with the parameter_name as content.
Source code in presidio_anonymizer/services/validators.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | |
validate_parameter_not_empty
validate_parameter_not_empty(
parameter_value, entity: str, parameter_name: str
) -> None
Validate parameter exists and not only empty.
Source code in presidio_anonymizer/services/validators.py
24 25 26 27 28 29 30 31 | |
validate_parameter_exists
validate_parameter_exists(
parameter_value, entity: str, parameter_name: str
) -> None
Validate parameter is not empty.
Source code in presidio_anonymizer/services/validators.py
34 35 36 37 38 39 40 41 | |
validate_parameter
validate_parameter(
parameter_value, parameter_name: str, parameter_type: type
) -> None
Validate an anonymizer parameter.
Both validate the existence of an anonymizer parameter and that it is an instance of the parameter_type. Otherwise, raise the appropriate InvalidParamException with the parameter_name as content.
Source code in presidio_anonymizer/services/validators.py
44 45 46 47 48 49 50 51 52 53 54 55 | |
validate_type
validate_type(parameter_value, parameter_name, parameter_type)
Validate an anonymizer parameter.
Validate it exists and if so, that it is the instance of the parameter_type. Otherwise, raise the appropriate InvalidParamException with the parameter_name as content.
Source code in presidio_anonymizer/services/validators.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | |
app_entities_convertor
AppEntitiesConvertor
Assisting class to convert API json entities to engine entities.
| METHOD | DESCRIPTION |
|---|---|
analyzer_results_from_json |
Go over analyzer results, validate them and convert to List[RecognizerResult]. |
operators_config_from_json |
Go over the operators list and get the relevant create operator config entity. |
deanonymize_entities_from_json |
Create DecryptEntity list. |
check_custom_operator |
Check if an operator is of type custom. |
Source code in presidio_anonymizer/services/app_entities_convertor.py
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 | |
analyzer_results_from_json
staticmethod
analyzer_results_from_json(data: List[Dict]) -> List[RecognizerResult]
Go over analyzer results, validate them and convert to List[RecognizerResult].
| PARAMETER | DESCRIPTION |
|---|---|
data
|
contains the anonymizers and analyzer_results_json
TYPE:
|
Source code in presidio_anonymizer/services/app_entities_convertor.py
14 15 16 17 18 19 20 21 22 23 24 25 | |
operators_config_from_json
staticmethod
operators_config_from_json(data: Dict) -> Dict[str, OperatorConfig]
Go over the operators list and get the relevant create operator config entity.
| PARAMETER | DESCRIPTION |
|---|---|
data
|
contains the list of configuration value - OperatorConfig
TYPE:
|
Source code in presidio_anonymizer/services/app_entities_convertor.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 | |
deanonymize_entities_from_json
staticmethod
deanonymize_entities_from_json(json: Dict) -> List[OperatorResult]
Create DecryptEntity list.
| PARAMETER | DESCRIPTION |
|---|---|
json
|
{ "text": text, "encrypt_results": [{ "start": 0, "end": 10, "key": "1111111111111111", "entity_type":"PHONE_NUMBER" }], }
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[OperatorResult]
|
List[OperatorResult] |
Source code in presidio_anonymizer/services/app_entities_convertor.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | |
check_custom_operator
staticmethod
check_custom_operator(operators: Dict[str, OperatorConfig])
Check if an operator is of type custom.
Source code in presidio_anonymizer/services/app_entities_convertor.py
66 67 68 69 | |
operators
Initializing all the existing anonymizers.
decrypt
Decrypt
Bases: Operator
Decrypt text to from its encrypted form.
| METHOD | DESCRIPTION |
|---|---|
operate |
Decrypt the text. |
validate |
Validate Decrypt parameters. |
operator_name |
Return operator name. |
operator_type |
Return operator type. |
Source code in presidio_anonymizer/operators/decrypt.py
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 | |
operate
operate(text: str = None, params: Dict = None) -> str
Decrypt the text.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The text for decryption.
TYPE:
|
params
|
*key The key supplied by the user for the encryption (bytes or str).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The encrypted text |
Source code in presidio_anonymizer/operators/decrypt.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 | |
validate
validate(params: Dict = None) -> None
Validate Decrypt parameters.
| PARAMETER | DESCRIPTION |
|---|---|
params
|
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
InvalidParamException
|
in case on an invalid parameter. |
Source code in presidio_anonymizer/operators/decrypt.py
28 29 30 31 32 33 34 35 36 37 | |
operator_name
operator_name() -> str
Return operator name.
Source code in presidio_anonymizer/operators/decrypt.py
39 40 41 | |
operator_type
operator_type() -> OperatorType
Return operator type.
Source code in presidio_anonymizer/operators/decrypt.py
43 44 45 | |
custom
Replaces the PII text with function result.
Custom
Bases: Operator
Replace PII text entity with the results of a function executed on the PII text.
The function retrun type must be a string
| METHOD | DESCRIPTION |
|---|---|
operate |
:return: result of function executed on the text. |
validate |
Validate the provided function is returning a string. |
operator_name |
Return operator name. |
operator_type |
Return operator type. |
Source code in presidio_anonymizer/operators/custom.py
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 | |
operate
operate(text: str = None, params: Dict = None) -> str
| RETURNS | DESCRIPTION |
|---|---|
str
|
result of function executed on the text. |
Source code in presidio_anonymizer/operators/custom.py
18 19 20 21 | |
validate
validate(params: Dict) -> None
Validate the provided function is returning a string.
Source code in presidio_anonymizer/operators/custom.py
23 24 25 26 27 28 29 30 31 | |
operator_name
operator_name() -> str
Return operator name.
Source code in presidio_anonymizer/operators/custom.py
33 34 35 | |
operator_type
operator_type() -> OperatorType
Return operator type.
Source code in presidio_anonymizer/operators/custom.py
37 38 39 | |
redact
Replaces the PII text entity with empty string.
Redact
Bases: Operator
Redact the string - empty value.
| METHOD | DESCRIPTION |
|---|---|
operate |
:return: an empty value. |
validate |
Redact does not require any paramters so no validation is needed. |
operator_name |
Return operator name. |
operator_type |
Return operator type. |
Source code in presidio_anonymizer/operators/redact.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | |
operate
operate(text: str = None, params: Dict = None) -> str
| RETURNS | DESCRIPTION |
|---|---|
str
|
an empty value. |
Source code in presidio_anonymizer/operators/redact.py
11 12 13 | |
validate
validate(params: Dict = None) -> None
Redact does not require any paramters so no validation is needed.
Source code in presidio_anonymizer/operators/redact.py
15 16 17 | |
operator_name
operator_name() -> str
Return operator name.
Source code in presidio_anonymizer/operators/redact.py
19 20 21 | |
operator_type
operator_type() -> OperatorType
Return operator type.
Source code in presidio_anonymizer/operators/redact.py
23 24 25 | |
deanonymize_keep
DeanonymizeKeep
Bases: BaseKeep
No-op deanonymizer that keeps the PII text unmodified.
This is useful when you don't want to anonymize some types of PII, but wants to keep track of it with the other PIIs.
| METHOD | DESCRIPTION |
|---|---|
operate |
:return: original text. |
validate |
Keep does not require any paramters so no validation is needed. |
operator_name |
Return operator name. |
operator_type |
Return operator type. |
Source code in presidio_anonymizer/operators/deanonymize_keep.py
5 6 7 8 9 10 11 12 13 14 15 16 17 18 | |
operate
operate(text: str = None, params: Dict = None) -> str
| RETURNS | DESCRIPTION |
|---|---|
str
|
original text. |
Source code in presidio_anonymizer/operators/keep.py
16 17 18 | |
validate
validate(params: Dict = None) -> None
Keep does not require any paramters so no validation is needed.
Source code in presidio_anonymizer/operators/keep.py
20 21 22 | |
operator_name
operator_name() -> str
Return operator name.
Source code in presidio_anonymizer/operators/deanonymize_keep.py
12 13 14 | |
operator_type
operator_type() -> OperatorType
Return operator type.
Source code in presidio_anonymizer/operators/deanonymize_keep.py
16 17 18 | |
hash
Hashes the PII text entity.
Hash
Bases: Operator
Hash given text with sha256/sha512/md5 algorithm.
| METHOD | DESCRIPTION |
|---|---|
operate |
Hash given value using sha256. |
validate |
Validate the hash type is string and in range of allowed hash types. |
operator_name |
Return operator name. |
operator_type |
Return operator type. |
Source code in presidio_anonymizer/operators/hash.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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | |
operate
operate(text: str = None, params: Dict = None) -> str
Hash given value using sha256.
| RETURNS | DESCRIPTION |
|---|---|
str
|
hashed original text |
Source code in presidio_anonymizer/operators/hash.py
18 19 20 21 22 23 24 25 26 27 28 29 30 | |
validate
validate(params: Dict = None) -> None
Validate the hash type is string and in range of allowed hash types.
Source code in presidio_anonymizer/operators/hash.py
32 33 34 35 36 37 38 39 40 | |
operator_name
operator_name() -> str
Return operator name.
Source code in presidio_anonymizer/operators/hash.py
42 43 44 | |
operator_type
operator_type() -> OperatorType
Return operator type.
Source code in presidio_anonymizer/operators/hash.py
49 50 51 | |
operators_factory
OperatorsFactory
Operators factory to get the correct operator class.
| METHOD | DESCRIPTION |
|---|---|
add_anonymize_operator |
Add a new anonymizer to the factory. |
add_deanonymize_operator |
Add a new deanonymizer to the factory. |
remove_anonymize_operator |
Remove an anonymizer from the factory. |
remove_deanonymize_operator |
Remove a deanonymizer from the factory. |
create_operator_class |
Extract the operator class from the operators list. |
get_anonymizers |
Return all anonymizers classes currently available. |
get_deanonymizers |
Return all deanonymizers classes currently available. |
Source code in presidio_anonymizer/operators/operators_factory.py
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 76 77 78 79 80 81 82 83 84 85 86 87 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 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | |
add_anonymize_operator
add_anonymize_operator(operator: Type[Operator])
Add a new anonymizer to the factory.
| PARAMETER | DESCRIPTION |
|---|---|
operator
|
The operator class to add.
TYPE:
|
Source code in presidio_anonymizer/operators/operators_factory.py
69 70 71 72 73 74 | |
add_deanonymize_operator
add_deanonymize_operator(operator: Type[Operator])
Add a new deanonymizer to the factory.
| PARAMETER | DESCRIPTION |
|---|---|
operator
|
The operator class to add.
TYPE:
|
Source code in presidio_anonymizer/operators/operators_factory.py
76 77 78 79 80 81 | |
remove_anonymize_operator
remove_anonymize_operator(operator: Type[Operator])
Remove an anonymizer from the factory.
| PARAMETER | DESCRIPTION |
|---|---|
operator
|
The operator class to remove.
TYPE:
|
Source code in presidio_anonymizer/operators/operators_factory.py
83 84 85 86 87 88 89 90 91 92 93 94 95 | |
remove_deanonymize_operator
remove_deanonymize_operator(operator: Type[Operator])
Remove a deanonymizer from the factory.
| PARAMETER | DESCRIPTION |
|---|---|
operator
|
The operator class to remove.
TYPE:
|
Source code in presidio_anonymizer/operators/operators_factory.py
97 98 99 100 101 102 103 104 105 106 107 108 109 | |
create_operator_class
create_operator_class(
operator_name: str, operator_type: OperatorType
) -> Operator
Extract the operator class from the operators list.
| PARAMETER | DESCRIPTION |
|---|---|
operator_type
|
Either Anonymize or Decrypt to defer between operators.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Operator
|
operator class entity. |
Source code in presidio_anonymizer/operators/operators_factory.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | |
get_anonymizers
get_anonymizers() -> Dict[str, Type[Operator]]
Return all anonymizers classes currently available.
Source code in presidio_anonymizer/operators/operators_factory.py
141 142 143 | |
get_deanonymizers
get_deanonymizers() -> Dict[str, Type[Operator]]
Return all deanonymizers classes currently available.
Source code in presidio_anonymizer/operators/operators_factory.py
145 146 147 | |
keep
Keeps the PII text unmodified.
BaseKeep
Bases: Operator, ABC
Abstract base class for keep operators.
Implements the common functionality of keep operators, leaving the operator type to be implemented by concrete classes
| METHOD | DESCRIPTION |
|---|---|
operator_name |
Return operator name. |
operator_type |
Return operator type. |
operate |
:return: original text. |
validate |
Keep does not require any paramters so no validation is needed. |
Source code in presidio_anonymizer/operators/keep.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 | |
operator_name
abstractmethod
operator_name() -> str
Return operator name.
Source code in presidio_anonymizer/operators/operator.py
31 32 33 34 | |
operator_type
abstractmethod
operator_type() -> OperatorType
Return operator type.
Source code in presidio_anonymizer/operators/operator.py
36 37 38 39 | |
operate
operate(text: str = None, params: Dict = None) -> str
| RETURNS | DESCRIPTION |
|---|---|
str
|
original text. |
Source code in presidio_anonymizer/operators/keep.py
16 17 18 | |
validate
validate(params: Dict = None) -> None
Keep does not require any paramters so no validation is needed.
Source code in presidio_anonymizer/operators/keep.py
20 21 22 | |
Keep
Bases: BaseKeep
No-op anonymizer that keeps the PII text unmodified.
This is useful when you don't want to anonymize some types of PII, but wants to keep track of it with the other PIIs.
| METHOD | DESCRIPTION |
|---|---|
operate |
:return: original text. |
validate |
Keep does not require any paramters so no validation is needed. |
operator_name |
Return operator name. |
operator_type |
Return operator type. |
Source code in presidio_anonymizer/operators/keep.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 | |
operate
operate(text: str = None, params: Dict = None) -> str
| RETURNS | DESCRIPTION |
|---|---|
str
|
original text. |
Source code in presidio_anonymizer/operators/keep.py
16 17 18 | |
validate
validate(params: Dict = None) -> None
Keep does not require any paramters so no validation is needed.
Source code in presidio_anonymizer/operators/keep.py
20 21 22 | |
operator_name
operator_name() -> str
Return operator name.
Source code in presidio_anonymizer/operators/keep.py
32 33 34 | |
operator_type
operator_type() -> OperatorType
Return operator type.
Source code in presidio_anonymizer/operators/keep.py
36 37 38 | |
replace
Replaces the PII text entity with new string.
Replace
Bases: Operator
Receives new text to replace old PII text entity with.
| METHOD | DESCRIPTION |
|---|---|
operate |
:return: new_value. |
validate |
Validate the new value is string. |
operator_name |
Return operator name. |
operator_type |
Return operator type. |
Source code in presidio_anonymizer/operators/replace.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | |
operate
operate(text: str = None, params: Dict = None) -> str
| RETURNS | DESCRIPTION |
|---|---|
str
|
new_value. |
Source code in presidio_anonymizer/operators/replace.py
14 15 16 17 18 19 | |
validate
validate(params: Dict = None) -> None
Validate the new value is string.
Source code in presidio_anonymizer/operators/replace.py
21 22 23 24 | |
operator_name
operator_name() -> str
Return operator name.
Source code in presidio_anonymizer/operators/replace.py
26 27 28 | |
operator_type
operator_type() -> OperatorType
Return operator type.
Source code in presidio_anonymizer/operators/replace.py
30 31 32 | |
encrypt
Encrypt
Bases: Operator
Anonymizes text to an encrypted form, or it to be restored using decrypted.
| METHOD | DESCRIPTION |
|---|---|
operate |
Anonymize the text with an encrypted text. |
validate |
Validate Encrypt parameters. |
operator_name |
Return operator name. |
operator_type |
Return operator type. |
Source code in presidio_anonymizer/operators/encrypt.py
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 | |
operate
operate(text: str = None, params: Dict = None) -> str
Anonymize the text with an encrypted text.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The text for encryption.
TYPE:
|
params
|
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The encrypted text |
Source code in presidio_anonymizer/operators/encrypt.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 | |
validate
validate(params: Dict = None) -> None
Validate Encrypt parameters.
| PARAMETER | DESCRIPTION |
|---|---|
params
|
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
InvalidParamException
|
in case on an invalid parameter. |
Source code in presidio_anonymizer/operators/encrypt.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | |
operator_name
operator_name() -> str
Return operator name.
Source code in presidio_anonymizer/operators/encrypt.py
52 53 54 | |
operator_type
operator_type() -> OperatorType
Return operator type.
Source code in presidio_anonymizer/operators/encrypt.py
56 57 58 | |
operator
Operator abstraction - each operator should implement this class.
OperatorType
Bases: Enum
Operator type either anonymize or decrypt to separate the operators.
Source code in presidio_anonymizer/operators/operator.py
8 9 10 11 12 | |
Operator
Bases: ABC
Operator abstract class to be implemented by each operator.
| METHOD | DESCRIPTION |
|---|---|
operate |
Operate method to be implemented in each operator. |
validate |
Validate each operator parameters. |
operator_name |
Return operator name. |
operator_type |
Return operator type. |
Source code in presidio_anonymizer/operators/operator.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | |
operate
abstractmethod
operate(text: str, params: Dict = None) -> str
Operate method to be implemented in each operator.
Source code in presidio_anonymizer/operators/operator.py
21 22 23 24 | |
validate
abstractmethod
validate(params: Dict = None) -> None
Validate each operator parameters.
Source code in presidio_anonymizer/operators/operator.py
26 27 28 29 | |
operator_name
abstractmethod
operator_name() -> str
Return operator name.
Source code in presidio_anonymizer/operators/operator.py
31 32 33 34 | |
operator_type
abstractmethod
operator_type() -> OperatorType
Return operator type.
Source code in presidio_anonymizer/operators/operator.py
36 37 38 39 | |
aes_cipher
AESCipher
Advanced Encryption Standard (aka Rijndael) en/decryption in CBC mode.
| METHOD | DESCRIPTION |
|---|---|
encrypt |
Encrypts a text using AES cypher in CBC mode. |
decrypt |
Decrypts a previously AES-CBC encrypted text. |
is_valid_key_size |
Validate key size for AES. |
Source code in presidio_anonymizer/operators/aes_cipher.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 | |
encrypt
staticmethod
encrypt(key: bytes, text: str) -> str
Encrypts a text using AES cypher in CBC mode.
Uses padding and random IV.
| PARAMETER | DESCRIPTION |
|---|---|
key
|
AES encryption key in bytes.
TYPE:
|
text
|
The text for encryption.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The encrypted text. |
Source code in presidio_anonymizer/operators/aes_cipher.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | |
decrypt
staticmethod
decrypt(key: bytes, text: str) -> str
Decrypts a previously AES-CBC encrypted text.
| PARAMETER | DESCRIPTION |
|---|---|
key
|
AES encryption key in bytes.
TYPE:
|
text
|
The text for decryption.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The decrypted text. |
Source code in presidio_anonymizer/operators/aes_cipher.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | |
is_valid_key_size
staticmethod
is_valid_key_size(key: bytes) -> bool
Validate key size for AES.
| PARAMETER | DESCRIPTION |
|---|---|
key
|
AES encryption key in bytes.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if the key is of valid size, False otherwise. |
Source code in presidio_anonymizer/operators/aes_cipher.py
45 46 47 48 49 50 51 52 53 | |
mask
Mask some or all given text entity PII with given character.
Mask
Bases: Operator
Mask the given text with given value.
| METHOD | DESCRIPTION |
|---|---|
operate |
Mask a given amount of text with a given character. |
validate |
Validate the parameters for mask. |
operator_name |
Return operator name. |
operator_type |
Return operator type. |
Source code in presidio_anonymizer/operators/mask.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 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 | |
operate
operate(text: str = None, params: Dict = None) -> str
Mask a given amount of text with a given character.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
the text to be masked
TYPE:
|
params
|
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
the masked text |
Source code in presidio_anonymizer/operators/mask.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | |
validate
validate(params: Dict = None) -> None
Validate the parameters for mask.
| PARAMETER | DESCRIPTION |
|---|---|
params
|
TYPE:
|
Source code in presidio_anonymizer/operators/mask.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | |
operator_name
operator_name() -> str
Return operator name.
Source code in presidio_anonymizer/operators/mask.py
56 57 58 | |
operator_type
operator_type() -> OperatorType
Return operator type.
Source code in presidio_anonymizer/operators/mask.py
60 61 62 | |
OperatorType
Bases: Enum
Operator type either anonymize or decrypt to separate the operators.
Source code in presidio_anonymizer/operators/operator.py
8 9 10 11 12 | |
Operator
Bases: ABC
Operator abstract class to be implemented by each operator.
| METHOD | DESCRIPTION |
|---|---|
operate |
Operate method to be implemented in each operator. |
validate |
Validate each operator parameters. |
operator_name |
Return operator name. |
operator_type |
Return operator type. |
Source code in presidio_anonymizer/operators/operator.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | |
operate
abstractmethod
operate(text: str, params: Dict = None) -> str
Operate method to be implemented in each operator.
Source code in presidio_anonymizer/operators/operator.py
21 22 23 24 | |
validate
abstractmethod
validate(params: Dict = None) -> None
Validate each operator parameters.
Source code in presidio_anonymizer/operators/operator.py
26 27 28 29 | |
operator_name
abstractmethod
operator_name() -> str
Return operator name.
Source code in presidio_anonymizer/operators/operator.py
31 32 33 34 | |
operator_type
abstractmethod
operator_type() -> OperatorType
Return operator type.
Source code in presidio_anonymizer/operators/operator.py
36 37 38 39 | |
AESCipher
Advanced Encryption Standard (aka Rijndael) en/decryption in CBC mode.
| METHOD | DESCRIPTION |
|---|---|
encrypt |
Encrypts a text using AES cypher in CBC mode. |
decrypt |
Decrypts a previously AES-CBC encrypted text. |
is_valid_key_size |
Validate key size for AES. |
Source code in presidio_anonymizer/operators/aes_cipher.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 | |
encrypt
staticmethod
encrypt(key: bytes, text: str) -> str
Encrypts a text using AES cypher in CBC mode.
Uses padding and random IV.
| PARAMETER | DESCRIPTION |
|---|---|
key
|
AES encryption key in bytes.
TYPE:
|
text
|
The text for encryption.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The encrypted text. |
Source code in presidio_anonymizer/operators/aes_cipher.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | |
decrypt
staticmethod
decrypt(key: bytes, text: str) -> str
Decrypts a previously AES-CBC encrypted text.
| PARAMETER | DESCRIPTION |
|---|---|
key
|
AES encryption key in bytes.
TYPE:
|
text
|
The text for decryption.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The decrypted text. |
Source code in presidio_anonymizer/operators/aes_cipher.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | |
is_valid_key_size
staticmethod
is_valid_key_size(key: bytes) -> bool
Validate key size for AES.
| PARAMETER | DESCRIPTION |
|---|---|
key
|
AES encryption key in bytes.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if the key is of valid size, False otherwise. |
Source code in presidio_anonymizer/operators/aes_cipher.py
45 46 47 48 49 50 51 52 53 | |
Custom
Bases: Operator
Replace PII text entity with the results of a function executed on the PII text.
The function retrun type must be a string
| METHOD | DESCRIPTION |
|---|---|
operate |
:return: result of function executed on the text. |
validate |
Validate the provided function is returning a string. |
operator_name |
Return operator name. |
operator_type |
Return operator type. |
Source code in presidio_anonymizer/operators/custom.py
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 | |
operate
operate(text: str = None, params: Dict = None) -> str
| RETURNS | DESCRIPTION |
|---|---|
str
|
result of function executed on the text. |
Source code in presidio_anonymizer/operators/custom.py
18 19 20 21 | |
validate
validate(params: Dict) -> None
Validate the provided function is returning a string.
Source code in presidio_anonymizer/operators/custom.py
23 24 25 26 27 28 29 30 31 | |
operator_name
operator_name() -> str
Return operator name.
Source code in presidio_anonymizer/operators/custom.py
33 34 35 | |
operator_type
operator_type() -> OperatorType
Return operator type.
Source code in presidio_anonymizer/operators/custom.py
37 38 39 | |
DeanonymizeKeep
Bases: BaseKeep
No-op deanonymizer that keeps the PII text unmodified.
This is useful when you don't want to anonymize some types of PII, but wants to keep track of it with the other PIIs.
| METHOD | DESCRIPTION |
|---|---|
operate |
:return: original text. |
validate |
Keep does not require any paramters so no validation is needed. |
operator_name |
Return operator name. |
operator_type |
Return operator type. |
Source code in presidio_anonymizer/operators/deanonymize_keep.py
5 6 7 8 9 10 11 12 13 14 15 16 17 18 | |
operate
operate(text: str = None, params: Dict = None) -> str
| RETURNS | DESCRIPTION |
|---|---|
str
|
original text. |
Source code in presidio_anonymizer/operators/keep.py
16 17 18 | |
validate
validate(params: Dict = None) -> None
Keep does not require any paramters so no validation is needed.
Source code in presidio_anonymizer/operators/keep.py
20 21 22 | |
operator_name
operator_name() -> str
Return operator name.
Source code in presidio_anonymizer/operators/deanonymize_keep.py
12 13 14 | |
operator_type
operator_type() -> OperatorType
Return operator type.
Source code in presidio_anonymizer/operators/deanonymize_keep.py
16 17 18 | |
Encrypt
Bases: Operator
Anonymizes text to an encrypted form, or it to be restored using decrypted.
| METHOD | DESCRIPTION |
|---|---|
operate |
Anonymize the text with an encrypted text. |
validate |
Validate Encrypt parameters. |
operator_name |
Return operator name. |
operator_type |
Return operator type. |
Source code in presidio_anonymizer/operators/encrypt.py
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 | |
operate
operate(text: str = None, params: Dict = None) -> str
Anonymize the text with an encrypted text.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The text for encryption.
TYPE:
|
params
|
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The encrypted text |
Source code in presidio_anonymizer/operators/encrypt.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 | |
validate
validate(params: Dict = None) -> None
Validate Encrypt parameters.
| PARAMETER | DESCRIPTION |
|---|---|
params
|
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
InvalidParamException
|
in case on an invalid parameter. |
Source code in presidio_anonymizer/operators/encrypt.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | |
operator_name
operator_name() -> str
Return operator name.
Source code in presidio_anonymizer/operators/encrypt.py
52 53 54 | |
operator_type
operator_type() -> OperatorType
Return operator type.
Source code in presidio_anonymizer/operators/encrypt.py
56 57 58 | |
Decrypt
Bases: Operator
Decrypt text to from its encrypted form.
| METHOD | DESCRIPTION |
|---|---|
operate |
Decrypt the text. |
validate |
Validate Decrypt parameters. |
operator_name |
Return operator name. |
operator_type |
Return operator type. |
Source code in presidio_anonymizer/operators/decrypt.py
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 | |
operate
operate(text: str = None, params: Dict = None) -> str
Decrypt the text.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The text for decryption.
TYPE:
|
params
|
*key The key supplied by the user for the encryption (bytes or str).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The encrypted text |
Source code in presidio_anonymizer/operators/decrypt.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 | |
validate
validate(params: Dict = None) -> None
Validate Decrypt parameters.
| PARAMETER | DESCRIPTION |
|---|---|
params
|
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
InvalidParamException
|
in case on an invalid parameter. |
Source code in presidio_anonymizer/operators/decrypt.py
28 29 30 31 32 33 34 35 36 37 | |
operator_name
operator_name() -> str
Return operator name.
Source code in presidio_anonymizer/operators/decrypt.py
39 40 41 | |
operator_type
operator_type() -> OperatorType
Return operator type.
Source code in presidio_anonymizer/operators/decrypt.py
43 44 45 | |
Hash
Bases: Operator
Hash given text with sha256/sha512/md5 algorithm.
| METHOD | DESCRIPTION |
|---|---|
operate |
Hash given value using sha256. |
validate |
Validate the hash type is string and in range of allowed hash types. |
operator_name |
Return operator name. |
operator_type |
Return operator type. |
Source code in presidio_anonymizer/operators/hash.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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | |
operate
operate(text: str = None, params: Dict = None) -> str
Hash given value using sha256.
| RETURNS | DESCRIPTION |
|---|---|
str
|
hashed original text |
Source code in presidio_anonymizer/operators/hash.py
18 19 20 21 22 23 24 25 26 27 28 29 30 | |
validate
validate(params: Dict = None) -> None
Validate the hash type is string and in range of allowed hash types.
Source code in presidio_anonymizer/operators/hash.py
32 33 34 35 36 37 38 39 40 | |
operator_name
operator_name() -> str
Return operator name.
Source code in presidio_anonymizer/operators/hash.py
42 43 44 | |
operator_type
operator_type() -> OperatorType
Return operator type.
Source code in presidio_anonymizer/operators/hash.py
49 50 51 | |
Keep
Bases: BaseKeep
No-op anonymizer that keeps the PII text unmodified.
This is useful when you don't want to anonymize some types of PII, but wants to keep track of it with the other PIIs.
| METHOD | DESCRIPTION |
|---|---|
operate |
:return: original text. |
validate |
Keep does not require any paramters so no validation is needed. |
operator_name |
Return operator name. |
operator_type |
Return operator type. |
Source code in presidio_anonymizer/operators/keep.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 | |
operate
operate(text: str = None, params: Dict = None) -> str
| RETURNS | DESCRIPTION |
|---|---|
str
|
original text. |
Source code in presidio_anonymizer/operators/keep.py
16 17 18 | |
validate
validate(params: Dict = None) -> None
Keep does not require any paramters so no validation is needed.
Source code in presidio_anonymizer/operators/keep.py
20 21 22 | |
operator_name
operator_name() -> str
Return operator name.
Source code in presidio_anonymizer/operators/keep.py
32 33 34 | |
operator_type
operator_type() -> OperatorType
Return operator type.
Source code in presidio_anonymizer/operators/keep.py
36 37 38 | |
Mask
Bases: Operator
Mask the given text with given value.
| METHOD | DESCRIPTION |
|---|---|
operate |
Mask a given amount of text with a given character. |
validate |
Validate the parameters for mask. |
operator_name |
Return operator name. |
operator_type |
Return operator type. |
Source code in presidio_anonymizer/operators/mask.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 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 | |
operate
operate(text: str = None, params: Dict = None) -> str
Mask a given amount of text with a given character.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
the text to be masked
TYPE:
|
params
|
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
the masked text |
Source code in presidio_anonymizer/operators/mask.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | |
validate
validate(params: Dict = None) -> None
Validate the parameters for mask.
| PARAMETER | DESCRIPTION |
|---|---|
params
|
TYPE:
|
Source code in presidio_anonymizer/operators/mask.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | |
operator_name
operator_name() -> str
Return operator name.
Source code in presidio_anonymizer/operators/mask.py
56 57 58 | |
operator_type
operator_type() -> OperatorType
Return operator type.
Source code in presidio_anonymizer/operators/mask.py
60 61 62 | |
Redact
Bases: Operator
Redact the string - empty value.
| METHOD | DESCRIPTION |
|---|---|
operate |
:return: an empty value. |
validate |
Redact does not require any paramters so no validation is needed. |
operator_name |
Return operator name. |
operator_type |
Return operator type. |
Source code in presidio_anonymizer/operators/redact.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | |
operate
operate(text: str = None, params: Dict = None) -> str
| RETURNS | DESCRIPTION |
|---|---|
str
|
an empty value. |
Source code in presidio_anonymizer/operators/redact.py
11 12 13 | |
validate
validate(params: Dict = None) -> None
Redact does not require any paramters so no validation is needed.
Source code in presidio_anonymizer/operators/redact.py
15 16 17 | |
operator_name
operator_name() -> str
Return operator name.
Source code in presidio_anonymizer/operators/redact.py
19 20 21 | |
operator_type
operator_type() -> OperatorType
Return operator type.
Source code in presidio_anonymizer/operators/redact.py
23 24 25 | |
Replace
Bases: Operator
Receives new text to replace old PII text entity with.
| METHOD | DESCRIPTION |
|---|---|
operate |
:return: new_value. |
validate |
Validate the new value is string. |
operator_name |
Return operator name. |
operator_type |
Return operator type. |
Source code in presidio_anonymizer/operators/replace.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | |
operate
operate(text: str = None, params: Dict = None) -> str
| RETURNS | DESCRIPTION |
|---|---|
str
|
new_value. |
Source code in presidio_anonymizer/operators/replace.py
14 15 16 17 18 19 | |
validate
validate(params: Dict = None) -> None
Validate the new value is string.
Source code in presidio_anonymizer/operators/replace.py
21 22 23 24 | |
operator_name
operator_name() -> str
Return operator name.
Source code in presidio_anonymizer/operators/replace.py
26 27 28 | |
operator_type
operator_type() -> OperatorType
Return operator type.
Source code in presidio_anonymizer/operators/replace.py
30 31 32 | |
OperatorsFactory
Operators factory to get the correct operator class.
| METHOD | DESCRIPTION |
|---|---|
add_anonymize_operator |
Add a new anonymizer to the factory. |
add_deanonymize_operator |
Add a new deanonymizer to the factory. |
remove_anonymize_operator |
Remove an anonymizer from the factory. |
remove_deanonymize_operator |
Remove a deanonymizer from the factory. |
create_operator_class |
Extract the operator class from the operators list. |
get_anonymizers |
Return all anonymizers classes currently available. |
get_deanonymizers |
Return all deanonymizers classes currently available. |
Source code in presidio_anonymizer/operators/operators_factory.py
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 76 77 78 79 80 81 82 83 84 85 86 87 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 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | |
add_anonymize_operator
add_anonymize_operator(operator: Type[Operator])
Add a new anonymizer to the factory.
| PARAMETER | DESCRIPTION |
|---|---|
operator
|
The operator class to add.
TYPE:
|
Source code in presidio_anonymizer/operators/operators_factory.py
69 70 71 72 73 74 | |
add_deanonymize_operator
add_deanonymize_operator(operator: Type[Operator])
Add a new deanonymizer to the factory.
| PARAMETER | DESCRIPTION |
|---|---|
operator
|
The operator class to add.
TYPE:
|
Source code in presidio_anonymizer/operators/operators_factory.py
76 77 78 79 80 81 | |
remove_anonymize_operator
remove_anonymize_operator(operator: Type[Operator])
Remove an anonymizer from the factory.
| PARAMETER | DESCRIPTION |
|---|---|
operator
|
The operator class to remove.
TYPE:
|
Source code in presidio_anonymizer/operators/operators_factory.py
83 84 85 86 87 88 89 90 91 92 93 94 95 | |
remove_deanonymize_operator
remove_deanonymize_operator(operator: Type[Operator])
Remove a deanonymizer from the factory.
| PARAMETER | DESCRIPTION |
|---|---|
operator
|
The operator class to remove.
TYPE:
|
Source code in presidio_anonymizer/operators/operators_factory.py
97 98 99 100 101 102 103 104 105 106 107 108 109 | |
create_operator_class
create_operator_class(
operator_name: str, operator_type: OperatorType
) -> Operator
Extract the operator class from the operators list.
| PARAMETER | DESCRIPTION |
|---|---|
operator_type
|
Either Anonymize or Decrypt to defer between operators.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Operator
|
operator class entity. |
Source code in presidio_anonymizer/operators/operators_factory.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | |
get_anonymizers
get_anonymizers() -> Dict[str, Type[Operator]]
Return all anonymizers classes currently available.
Source code in presidio_anonymizer/operators/operators_factory.py
141 142 143 | |
get_deanonymizers
get_deanonymizers() -> Dict[str, Type[Operator]]
Return all deanonymizers classes currently available.
Source code in presidio_anonymizer/operators/operators_factory.py
145 146 147 | |
core
The core text functionality.
text_replace_builder
Handles the original text and creates a new one according to changes requests.
TextReplaceBuilder
Creates new text according to users request.
| METHOD | DESCRIPTION |
|---|---|
get_text_in_position |
Get part of the text inside the original text. |
replace_text_get_insertion_index |
Replace text in a specific position with the text. |
Source code in presidio_anonymizer/core/text_replace_builder.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 | |
get_text_in_position
get_text_in_position(start: int, end: int) -> str
Get part of the text inside the original text.
| PARAMETER | DESCRIPTION |
|---|---|
start
|
start position of inner text
TYPE:
|
end
|
end position of inner text
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
str - part of the original text |
Source code in presidio_anonymizer/core/text_replace_builder.py
18 19 20 21 22 23 24 25 26 27 | |
replace_text_get_insertion_index
replace_text_get_insertion_index(
replacement_text: str, start: int, end: int
) -> int
Replace text in a specific position with the text.
| PARAMETER | DESCRIPTION |
|---|---|
replacement_text
|
new text to replace the old text according to indices
TYPE:
|
start
|
the startpoint to replace the text
TYPE:
|
end
|
the endpoint to replace the text
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
int
|
The index of inserted text |
Source code in presidio_anonymizer/core/text_replace_builder.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | |
engine_base
Handle the entire text operations using the operators.
EngineBase
Bases: ABC
Handle the logic of operations over the text using the operators.
Source code in presidio_anonymizer/core/engine_base.py
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 76 77 78 79 80 81 82 83 84 85 86 87 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 | |
EngineBase
Bases: ABC
Handle the logic of operations over the text using the operators.
Source code in presidio_anonymizer/core/engine_base.py
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 76 77 78 79 80 81 82 83 84 85 86 87 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 | |
TextReplaceBuilder
Creates new text according to users request.
| METHOD | DESCRIPTION |
|---|---|
get_text_in_position |
Get part of the text inside the original text. |
replace_text_get_insertion_index |
Replace text in a specific position with the text. |
Source code in presidio_anonymizer/core/text_replace_builder.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 | |
get_text_in_position
get_text_in_position(start: int, end: int) -> str
Get part of the text inside the original text.
| PARAMETER | DESCRIPTION |
|---|---|
start
|
start position of inner text
TYPE:
|
end
|
end position of inner text
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
str - part of the original text |
Source code in presidio_anonymizer/core/text_replace_builder.py
18 19 20 21 22 23 24 25 26 27 | |
replace_text_get_insertion_index
replace_text_get_insertion_index(
replacement_text: str, start: int, end: int
) -> int
Replace text in a specific position with the text.
| PARAMETER | DESCRIPTION |
|---|---|
replacement_text
|
new text to replace the old text according to indices
TYPE:
|
start
|
the startpoint to replace the text
TYPE:
|
end
|
the endpoint to replace the text
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
int
|
The index of inserted text |
Source code in presidio_anonymizer/core/text_replace_builder.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | |
entities
Handles all the entities objects (structs) of the anonymizer.
invalid_exception
Exception to indicate the request we received is invalid.
InvalidParamError
Bases: Exception
Throw exception with error when user input is not valid.
param msg: Message to be added to the exception
Source code in presidio_anonymizer/entities/invalid_exception.py
4 5 6 7 8 9 10 11 12 | |
conflict_resolution_strategy
An Enum class designed to manage all types of conflicts among entities or text.
ConflictResolutionStrategy
Bases: Enum
Conflict resolution strategy.
The strategy to use when there is a conflict between two entities.
MERGE_SIMILAR_OR_CONTAINED: This default strategy resolves conflicts between similar or contained entities. REMOVE_INTERSECTIONS: Effectively resolves both intersection conflicts among entities and default strategy conflicts. NONE: No conflict resolution will be performed.
Source code in presidio_anonymizer/entities/conflict_resolution_strategy.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 | |
engine
Engine request entities.
operator_config
OperatorConfig
Hold the data of the required operator.
| METHOD | DESCRIPTION |
|---|---|
from_json |
Create OperatorConfig from json. |
Source code in presidio_anonymizer/entities/engine/operator_config.py
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 | |
classmethod
from_json(params: Dict) -> OperatorConfig
Create OperatorConfig from json.
| PARAMETER | DESCRIPTION |
|---|---|
params
|
json e.g.: { "type": "mask", "masking_char": "*", "chars_to_mask": 4, "from_end": true }
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
OperatorConfig
|
OperatorConfig |
Source code in presidio_anonymizer/entities/engine/operator_config.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | |
dict_recognizer_result
DictRecognizerResult
dataclass
Data class for holding the output of the Presidio Analyzer on dictionaries.
| PARAMETER | DESCRIPTION |
|---|---|
key
|
key in dictionary
TYPE:
|
value
|
value to run analysis on (either string or list of strings)
TYPE:
|
recognizer_results
|
Analyzer output for one value. Could be either: - A list of recognizer results if the input is one string - A list of lists of recognizer results, if the input is a list of strings. - An iterator of a DictRecognizerResult, if the input is a dictionary. In this case the recognizer_results would be the iterator of the DictRecognizerResult next level in the dictionary.
TYPE:
|
Source code in presidio_anonymizer/entities/engine/dict_recognizer_result.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | |
pii_entity
PIIEntity
Bases: ABC
Abstract class to hold the text we are going to operate on metadata.
Source code in presidio_anonymizer/entities/engine/pii_entity.py
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 | |
recognizer_result
RecognizerResult is an exact copy of the RecognizerResult object from presidio-analyzer.
Represents the findings of detected entity.
RecognizerResult
Bases: PIIEntity
Recognizer Result represents the findings of the detected entity.
Result of a recognizer analyzing the text.
| PARAMETER | DESCRIPTION |
|---|---|
entity_type
|
the type of the entity
TYPE:
|
start
|
the start location of the detected entity
TYPE:
|
end
|
the end location of the detected entity
TYPE:
|
score
|
the score of the detection
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
from_json |
Create RecognizerResult from json. |
has_conflict |
Check if two recognizer results are conflicted or not. |
contains |
Check if one result is contained or equal to another result. |
equal_indices |
Check if the indices are equal between two results. |
intersects |
Check if self intersects with a different RecognizerResult. |
Source code in presidio_anonymizer/entities/engine/recognizer_result.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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 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 130 131 132 133 134 135 136 137 138 139 | |
classmethod
from_json(data: Dict)
Create RecognizerResult from json.
| PARAMETER | DESCRIPTION |
|---|---|
data
|
e.g. { "start": 24, "end": 32, "score": 0.8, "entity_type": "NAME" }
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
RecognizerResult |
Source code in presidio_anonymizer/entities/engine/recognizer_result.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | |
has_conflict(other)
Check if two recognizer results are conflicted or not.
I have a conflict if: 1. My indices are the same as the other and my score is lower. 2. If my indices are contained in another.
| PARAMETER | DESCRIPTION |
|---|---|
other
|
RecognizerResult
|
| RETURNS | DESCRIPTION |
|---|---|
|
|
Source code in presidio_anonymizer/entities/engine/recognizer_result.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 | |
contains(other)
Check if one result is contained or equal to another result.
| PARAMETER | DESCRIPTION |
|---|---|
other
|
another RecognizerResult
|
| RETURNS | DESCRIPTION |
|---|---|
|
bool |
Source code in presidio_anonymizer/entities/engine/recognizer_result.py
108 109 110 111 112 113 114 115 | |
equal_indices(other)
Check if the indices are equal between two results.
| PARAMETER | DESCRIPTION |
|---|---|
other
|
another RecognizerResult
|
| RETURNS | DESCRIPTION |
|---|---|
|
|
Source code in presidio_anonymizer/entities/engine/recognizer_result.py
117 118 119 120 121 122 123 124 | |
intersects(other) -> int
Check if self intersects with a different RecognizerResult.
| RETURNS | DESCRIPTION |
|---|---|
int
|
If intersecting, returns the number of intersecting characters. If not, returns 0 |
Source code in presidio_anonymizer/entities/engine/recognizer_result.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 | |
result
Engine result items either for anonymize or decrypt.
operator_result
Bases: PIIEntity
A class to hold data for engines results either anonymize or deanonymize.
| METHOD | DESCRIPTION |
|---|---|
to_dict |
Return object as Dict. |
from_json |
Create OperatorResult from user json. |
Source code in presidio_anonymizer/entities/engine/result/operator_result.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 65 66 67 68 69 70 71 72 73 74 | |
to_dict() -> Dict
Return object as Dict.
Source code in presidio_anonymizer/entities/engine/result/operator_result.py
25 26 27 | |
classmethod
from_json(json: Dict) -> OperatorResult
Create OperatorResult from user json.
| PARAMETER | DESCRIPTION |
|---|---|
json
|
json representation for this operator result. For example: { "start": 0, "end": 10, "key": "1111111111111111", "entity_type":"PERSON", "text":"resulted_text", "operator":"encrypt", }
TYPE:
|
Source code in presidio_anonymizer/entities/engine/result/operator_result.py
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 | |
engine_result
Handle a serializable anonymizer result.
Engine result.
| METHOD | DESCRIPTION |
|---|---|
set_text |
Set a text. |
add_item |
Add an item. |
normalize_item_indexes |
Normalize the indexes to be index from start. |
to_json |
Return a json string serializing this instance. |
Source code in presidio_anonymizer/entities/engine/result/engine_result.py
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 | |
set_text(text: str)
Set a text.
Source code in presidio_anonymizer/entities/engine/result/engine_result.py
24 25 26 | |
add_item(item: OperatorResult)
Add an item.
| PARAMETER | DESCRIPTION |
|---|---|
item
|
an item to add to the list.
TYPE:
|
Source code in presidio_anonymizer/entities/engine/result/engine_result.py
28 29 30 31 32 33 | |
normalize_item_indexes()
Normalize the indexes to be index from start.
Source code in presidio_anonymizer/entities/engine/result/engine_result.py
35 36 37 38 39 40 | |
to_json() -> str
Return a json string serializing this instance.
Source code in presidio_anonymizer/entities/engine/result/engine_result.py
42 43 44 | |
OperatorResult
Bases: PIIEntity
A class to hold data for engines results either anonymize or deanonymize.
| METHOD | DESCRIPTION |
|---|---|
to_dict |
Return object as Dict. |
from_json |
Create OperatorResult from user json. |
Source code in presidio_anonymizer/entities/engine/result/operator_result.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 65 66 67 68 69 70 71 72 73 74 | |
to_dict() -> Dict
Return object as Dict.
Source code in presidio_anonymizer/entities/engine/result/operator_result.py
25 26 27 | |
classmethod
from_json(json: Dict) -> OperatorResult
Create OperatorResult from user json.
| PARAMETER | DESCRIPTION |
|---|---|
json
|
json representation for this operator result. For example: { "start": 0, "end": 10, "key": "1111111111111111", "entity_type":"PERSON", "text":"resulted_text", "operator":"encrypt", }
TYPE:
|
Source code in presidio_anonymizer/entities/engine/result/operator_result.py
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 | |
EngineResult
Engine result.
| METHOD | DESCRIPTION |
|---|---|
set_text |
Set a text. |
add_item |
Add an item. |
normalize_item_indexes |
Normalize the indexes to be index from start. |
to_json |
Return a json string serializing this instance. |
Source code in presidio_anonymizer/entities/engine/result/engine_result.py
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 | |
set_text(text: str)
Set a text.
Source code in presidio_anonymizer/entities/engine/result/engine_result.py
24 25 26 | |
add_item(item: OperatorResult)
Add an item.
| PARAMETER | DESCRIPTION |
|---|---|
item
|
an item to add to the list.
TYPE:
|
Source code in presidio_anonymizer/entities/engine/result/engine_result.py
28 29 30 31 32 33 | |
normalize_item_indexes()
Normalize the indexes to be index from start.
Source code in presidio_anonymizer/entities/engine/result/engine_result.py
35 36 37 38 39 40 | |
to_json() -> str
Return a json string serializing this instance.
Source code in presidio_anonymizer/entities/engine/result/engine_result.py
42 43 44 | |
OperatorConfig
Hold the data of the required operator.
| METHOD | DESCRIPTION |
|---|---|
from_json |
Create OperatorConfig from json. |
Source code in presidio_anonymizer/entities/engine/operator_config.py
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 | |
from_json
classmethod
from_json(params: Dict) -> OperatorConfig
Create OperatorConfig from json.
| PARAMETER | DESCRIPTION |
|---|---|
params
|
json e.g.: { "type": "mask", "masking_char": "*", "chars_to_mask": 4, "from_end": true }
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
OperatorConfig
|
OperatorConfig |
Source code in presidio_anonymizer/entities/engine/operator_config.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | |
PIIEntity
Bases: ABC
Abstract class to hold the text we are going to operate on metadata.
Source code in presidio_anonymizer/entities/engine/pii_entity.py
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 | |
RecognizerResult
Bases: PIIEntity
Recognizer Result represents the findings of the detected entity.
Result of a recognizer analyzing the text.
| PARAMETER | DESCRIPTION |
|---|---|
entity_type
|
the type of the entity
TYPE:
|
start
|
the start location of the detected entity
TYPE:
|
end
|
the end location of the detected entity
TYPE:
|
score
|
the score of the detection
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
from_json |
Create RecognizerResult from json. |
has_conflict |
Check if two recognizer results are conflicted or not. |
contains |
Check if one result is contained or equal to another result. |
equal_indices |
Check if the indices are equal between two results. |
intersects |
Check if self intersects with a different RecognizerResult. |
Source code in presidio_anonymizer/entities/engine/recognizer_result.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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 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 130 131 132 133 134 135 136 137 138 139 | |
from_json
classmethod
from_json(data: Dict)
Create RecognizerResult from json.
| PARAMETER | DESCRIPTION |
|---|---|
data
|
e.g. { "start": 24, "end": 32, "score": 0.8, "entity_type": "NAME" }
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
RecognizerResult |
Source code in presidio_anonymizer/entities/engine/recognizer_result.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | |
has_conflict
has_conflict(other)
Check if two recognizer results are conflicted or not.
I have a conflict if: 1. My indices are the same as the other and my score is lower. 2. If my indices are contained in another.
| PARAMETER | DESCRIPTION |
|---|---|
other
|
RecognizerResult
|
| RETURNS | DESCRIPTION |
|---|---|
|
|
Source code in presidio_anonymizer/entities/engine/recognizer_result.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 | |
contains
contains(other)
Check if one result is contained or equal to another result.
| PARAMETER | DESCRIPTION |
|---|---|
other
|
another RecognizerResult
|
| RETURNS | DESCRIPTION |
|---|---|
|
bool |
Source code in presidio_anonymizer/entities/engine/recognizer_result.py
108 109 110 111 112 113 114 115 | |
equal_indices
equal_indices(other)
Check if the indices are equal between two results.
| PARAMETER | DESCRIPTION |
|---|---|
other
|
another RecognizerResult
|
| RETURNS | DESCRIPTION |
|---|---|
|
|
Source code in presidio_anonymizer/entities/engine/recognizer_result.py
117 118 119 120 121 122 123 124 | |
intersects
intersects(other) -> int
Check if self intersects with a different RecognizerResult.
| RETURNS | DESCRIPTION |
|---|---|
int
|
If intersecting, returns the number of intersecting characters. If not, returns 0 |
Source code in presidio_anonymizer/entities/engine/recognizer_result.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 | |
InvalidParamError
Bases: Exception
Throw exception with error when user input is not valid.
param msg: Message to be added to the exception
Source code in presidio_anonymizer/entities/invalid_exception.py
4 5 6 7 8 9 10 11 12 | |
ConflictResolutionStrategy
Bases: Enum
Conflict resolution strategy.
The strategy to use when there is a conflict between two entities.
MERGE_SIMILAR_OR_CONTAINED: This default strategy resolves conflicts between similar or contained entities. REMOVE_INTERSECTIONS: Effectively resolves both intersection conflicts among entities and default strategy conflicts. NONE: No conflict resolution will be performed.
Source code in presidio_anonymizer/entities/conflict_resolution_strategy.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 | |
OperatorConfig
Hold the data of the required operator.
| METHOD | DESCRIPTION |
|---|---|
from_json |
Create OperatorConfig from json. |
Source code in presidio_anonymizer/entities/engine/operator_config.py
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 | |
from_json
classmethod
from_json(params: Dict) -> OperatorConfig
Create OperatorConfig from json.
| PARAMETER | DESCRIPTION |
|---|---|
params
|
json e.g.: { "type": "mask", "masking_char": "*", "chars_to_mask": 4, "from_end": true }
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
OperatorConfig
|
OperatorConfig |
Source code in presidio_anonymizer/entities/engine/operator_config.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | |
PIIEntity
Bases: ABC
Abstract class to hold the text we are going to operate on metadata.
Source code in presidio_anonymizer/entities/engine/pii_entity.py
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 | |
RecognizerResult
Bases: PIIEntity
Recognizer Result represents the findings of the detected entity.
Result of a recognizer analyzing the text.
| PARAMETER | DESCRIPTION |
|---|---|
entity_type
|
the type of the entity
TYPE:
|
start
|
the start location of the detected entity
TYPE:
|
end
|
the end location of the detected entity
TYPE:
|
score
|
the score of the detection
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
from_json |
Create RecognizerResult from json. |
has_conflict |
Check if two recognizer results are conflicted or not. |
contains |
Check if one result is contained or equal to another result. |
equal_indices |
Check if the indices are equal between two results. |
intersects |
Check if self intersects with a different RecognizerResult. |
Source code in presidio_anonymizer/entities/engine/recognizer_result.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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 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 130 131 132 133 134 135 136 137 138 139 | |
from_json
classmethod
from_json(data: Dict)
Create RecognizerResult from json.
| PARAMETER | DESCRIPTION |
|---|---|
data
|
e.g. { "start": 24, "end": 32, "score": 0.8, "entity_type": "NAME" }
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
RecognizerResult |
Source code in presidio_anonymizer/entities/engine/recognizer_result.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | |
has_conflict
has_conflict(other)
Check if two recognizer results are conflicted or not.
I have a conflict if: 1. My indices are the same as the other and my score is lower. 2. If my indices are contained in another.
| PARAMETER | DESCRIPTION |
|---|---|
other
|
RecognizerResult
|
| RETURNS | DESCRIPTION |
|---|---|
|
|
Source code in presidio_anonymizer/entities/engine/recognizer_result.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 | |
contains
contains(other)
Check if one result is contained or equal to another result.
| PARAMETER | DESCRIPTION |
|---|---|
other
|
another RecognizerResult
|
| RETURNS | DESCRIPTION |
|---|---|
|
bool |
Source code in presidio_anonymizer/entities/engine/recognizer_result.py
108 109 110 111 112 113 114 115 | |
equal_indices
equal_indices(other)
Check if the indices are equal between two results.
| PARAMETER | DESCRIPTION |
|---|---|
other
|
another RecognizerResult
|
| RETURNS | DESCRIPTION |
|---|---|
|
|
Source code in presidio_anonymizer/entities/engine/recognizer_result.py
117 118 119 120 121 122 123 124 | |
intersects
intersects(other) -> int
Check if self intersects with a different RecognizerResult.
| RETURNS | DESCRIPTION |
|---|---|
int
|
If intersecting, returns the number of intersecting characters. If not, returns 0 |
Source code in presidio_anonymizer/entities/engine/recognizer_result.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 | |
EngineResult
Engine result.
| METHOD | DESCRIPTION |
|---|---|
set_text |
Set a text. |
add_item |
Add an item. |
normalize_item_indexes |
Normalize the indexes to be index from start. |
to_json |
Return a json string serializing this instance. |
Source code in presidio_anonymizer/entities/engine/result/engine_result.py
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 | |
set_text
set_text(text: str)
Set a text.
Source code in presidio_anonymizer/entities/engine/result/engine_result.py
24 25 26 | |
add_item
add_item(item: OperatorResult)
Add an item.
| PARAMETER | DESCRIPTION |
|---|---|
item
|
an item to add to the list.
TYPE:
|
Source code in presidio_anonymizer/entities/engine/result/engine_result.py
28 29 30 31 32 33 | |
normalize_item_indexes
normalize_item_indexes()
Normalize the indexes to be index from start.
Source code in presidio_anonymizer/entities/engine/result/engine_result.py
35 36 37 38 39 40 | |
to_json
to_json() -> str
Return a json string serializing this instance.
Source code in presidio_anonymizer/entities/engine/result/engine_result.py
42 43 44 | |
OperatorResult
Bases: PIIEntity
A class to hold data for engines results either anonymize or deanonymize.
| METHOD | DESCRIPTION |
|---|---|
to_dict |
Return object as Dict. |
from_json |
Create OperatorResult from user json. |
Source code in presidio_anonymizer/entities/engine/result/operator_result.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 65 66 67 68 69 70 71 72 73 74 | |
to_dict
to_dict() -> Dict
Return object as Dict.
Source code in presidio_anonymizer/entities/engine/result/operator_result.py
25 26 27 | |
from_json
classmethod
from_json(json: Dict) -> OperatorResult
Create OperatorResult from user json.
| PARAMETER | DESCRIPTION |
|---|---|
json
|
json representation for this operator result. For example: { "start": 0, "end": 10, "key": "1111111111111111", "entity_type":"PERSON", "text":"resulted_text", "operator":"encrypt", }
TYPE:
|
Source code in presidio_anonymizer/entities/engine/result/operator_result.py
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 | |
DictRecognizerResult
dataclass
Data class for holding the output of the Presidio Analyzer on dictionaries.
| PARAMETER | DESCRIPTION |
|---|---|
key
|
key in dictionary
TYPE:
|
value
|
value to run analysis on (either string or list of strings)
TYPE:
|
recognizer_results
|
Analyzer output for one value. Could be either: - A list of recognizer results if the input is one string - A list of lists of recognizer results, if the input is a list of strings. - An iterator of a DictRecognizerResult, if the input is a dictionary. In this case the recognizer_results would be the iterator of the DictRecognizerResult next level in the dictionary.
TYPE:
|
Source code in presidio_anonymizer/entities/engine/dict_recognizer_result.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | |
AnonymizerEngine
Bases: EngineBase
AnonymizerEngine class.
Handles the entire logic of the Presidio-anonymizer. Gets the original text and replaces the PII entities with the desired anonymizers.
| METHOD | DESCRIPTION |
|---|---|
anonymize |
Anonymize method to anonymize the given text. |
add_anonymizer |
Add a new anonymizer to the engine. |
remove_anonymizer |
Remove an anonymizer from the engine. |
get_anonymizers |
Return a list of supported anonymizers. |
Source code in presidio_anonymizer/anonymizer_engine.py
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 76 77 78 79 80 81 82 83 84 85 86 87 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 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 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 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 | |
anonymize
anonymize(
text: str,
analyzer_results: List[RecognizerResult],
operators: Optional[Dict[str, OperatorConfig]] = None,
conflict_resolution: ConflictResolutionStrategy = ConflictResolutionStrategy.MERGE_SIMILAR_OR_CONTAINED,
) -> EngineResult
Anonymize method to anonymize the given text.
:example:
from presidio_anonymizer import AnonymizerEngine from presidio_anonymizer.entities import RecognizerResult, OperatorConfig
Initialize the engine with logger.
engine = AnonymizerEngine()
Invoke the anonymize function with the text, analyzer results and
Operators to define the anonymization type.
result = engine.anonymize( text="My name is Bond, James Bond", analyzer_results=[RecognizerResult(entity_type="PERSON", start=11, end=15, score=0.8), RecognizerResult(entity_type="PERSON", start=17, end=27, score=0.8)], operators={"PERSON": OperatorConfig("replace", {"new_value": "BIP"})} )
print(result) text: My name is BIP, BIP. items: [ {'start': 16, 'end': 19, 'entity_type': 'PERSON', 'text': 'BIP', 'operator': 'replace'}, {'start': 11, 'end': 14, 'entity_type': 'PERSON', 'text': 'BIP', 'operator': 'replace'} ]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
the text we are anonymizing
TYPE:
|
analyzer_results
|
A list of RecognizerResult class -> The results we received from the analyzer
TYPE:
|
operators
|
The configuration of the anonymizers we would like to use for each entity e.g.: {"PHONE_NUMBER":OperatorConfig("redact", {})} received from the analyzer
TYPE:
|
conflict_resolution
|
The configuration designed to handle conflicts among entities
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
EngineResult
|
the anonymized text and a list of information about the anonymized entities. |
Source code in presidio_anonymizer/anonymizer_engine.py
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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | |
add_anonymizer
add_anonymizer(anonymizer_cls: Type[Operator]) -> None
Add a new anonymizer to the engine.
anonymizer_cls: The anonymizer class to add to the engine.
Source code in presidio_anonymizer/anonymizer_engine.py
103 104 105 106 107 108 109 110 | |
remove_anonymizer
remove_anonymizer(anonymizer_cls: Type[Operator]) -> None
Remove an anonymizer from the engine.
anonymizer_cls: The anonymizer class to remove from the engine.
Source code in presidio_anonymizer/anonymizer_engine.py
112 113 114 115 116 117 118 119 | |
get_anonymizers
get_anonymizers() -> List[str]
Return a list of supported anonymizers.
Source code in presidio_anonymizer/anonymizer_engine.py
224 225 226 227 | |
BatchAnonymizerEngine
BatchAnonymizerEngine class.
A class that provides functionality to anonymize in batches.
| PARAMETER | DESCRIPTION |
|---|---|
anonymizer_engine
|
An instance of the AnonymizerEngine class.
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
anonymize_list |
Anonymize a list of strings. |
anonymize_dict |
Anonymize values in a dictionary. |
Source code in presidio_anonymizer/batch_anonymizer_engine.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 76 77 78 79 80 81 82 83 84 | |
anonymize_list
anonymize_list(
texts: List[Optional[Union[str, bool, int, float]]],
recognizer_results_list: List[List[RecognizerResult]],
**kwargs
) -> List[Union[str, Any]]
Anonymize a list of strings.
| PARAMETER | DESCRIPTION |
|---|---|
texts
|
List containing the texts to be anonymized (original texts). Items with a
TYPE:
|
recognizer_results_list
|
A list of lists of RecognizerResult, the output of the AnalyzerEngine on each text in the list.
TYPE:
|
kwargs
|
Additional kwargs for the
DEFAULT:
|
Source code in presidio_anonymizer/batch_anonymizer_engine.py
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 | |
anonymize_dict
anonymize_dict(
analyzer_results: Iterable[DictRecognizerResult], **kwargs
) -> Dict[str, str]
Anonymize values in a dictionary.
| PARAMETER | DESCRIPTION |
|---|---|
analyzer_results
|
Iterator of
TYPE:
|
kwargs
|
Additional kwargs for the
DEFAULT:
|
Source code in presidio_anonymizer/batch_anonymizer_engine.py
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 76 77 78 79 80 81 82 83 84 | |
DeanonymizeEngine
Bases: EngineBase
Deanonymize text that was previously anonymized.
| METHOD | DESCRIPTION |
|---|---|
deanonymize |
Receive the text, entities and operators to perform deanonymization over. |
get_deanonymizers |
Return a list of supported deanonymizers. |
add_deanonymizer |
Add a new deanonymizer to the engine. |
remove_deanonymizer |
Remove a deanonymizer from the engine. |
Source code in presidio_anonymizer/deanonymize_engine.py
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 | |
deanonymize
deanonymize(
text: str,
entities: List[OperatorResult],
operators: Dict[str, OperatorConfig],
) -> EngineResult
Receive the text, entities and operators to perform deanonymization over.
| PARAMETER | DESCRIPTION |
|---|---|
operators
|
the operators to apply on the anonymizer result entities
TYPE:
|
text
|
the full text with the encrypted entities
TYPE:
|
entities
|
list of encrypted entities
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
EngineResult
|
EngineResult - the new text and data about the deanonymized entities. |
Source code in presidio_anonymizer/deanonymize_engine.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | |
get_deanonymizers
get_deanonymizers() -> List[str]
Return a list of supported deanonymizers.
Source code in presidio_anonymizer/deanonymize_engine.py
32 33 34 35 | |
add_deanonymizer
add_deanonymizer(deanonymizer_cls: Type[Operator]) -> None
Add a new deanonymizer to the engine.
anonymizer_cls: The deanonymizer class to add to the engine.
Source code in presidio_anonymizer/deanonymize_engine.py
37 38 39 40 41 42 43 44 | |
remove_deanonymizer
remove_deanonymizer(deanonymizer_cls: Type[Operator]) -> None
Remove a deanonymizer from the engine.
deanonymizer_cls: The deanonymizer class to remove from the engine.
Source code in presidio_anonymizer/deanonymize_engine.py
46 47 48 49 50 51 52 53 | |
ConflictResolutionStrategy
Bases: Enum
Conflict resolution strategy.
The strategy to use when there is a conflict between two entities.
MERGE_SIMILAR_OR_CONTAINED: This default strategy resolves conflicts between similar or contained entities. REMOVE_INTERSECTIONS: Effectively resolves both intersection conflicts among entities and default strategy conflicts. NONE: No conflict resolution will be performed.
Source code in presidio_anonymizer/entities/conflict_resolution_strategy.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 | |
DictRecognizerResult
dataclass
Data class for holding the output of the Presidio Analyzer on dictionaries.
| PARAMETER | DESCRIPTION |
|---|---|
key
|
key in dictionary
TYPE:
|
value
|
value to run analysis on (either string or list of strings)
TYPE:
|
recognizer_results
|
Analyzer output for one value. Could be either: - A list of recognizer results if the input is one string - A list of lists of recognizer results, if the input is a list of strings. - An iterator of a DictRecognizerResult, if the input is a dictionary. In this case the recognizer_results would be the iterator of the DictRecognizerResult next level in the dictionary.
TYPE:
|
Source code in presidio_anonymizer/entities/engine/dict_recognizer_result.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | |
EngineResult
Engine result.
| METHOD | DESCRIPTION |
|---|---|
set_text |
Set a text. |
add_item |
Add an item. |
normalize_item_indexes |
Normalize the indexes to be index from start. |
to_json |
Return a json string serializing this instance. |
Source code in presidio_anonymizer/entities/engine/result/engine_result.py
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 | |
set_text
set_text(text: str)
Set a text.
Source code in presidio_anonymizer/entities/engine/result/engine_result.py
24 25 26 | |
add_item
add_item(item: OperatorResult)
Add an item.
| PARAMETER | DESCRIPTION |
|---|---|
item
|
an item to add to the list.
TYPE:
|
Source code in presidio_anonymizer/entities/engine/result/engine_result.py
28 29 30 31 32 33 | |
normalize_item_indexes
normalize_item_indexes()
Normalize the indexes to be index from start.
Source code in presidio_anonymizer/entities/engine/result/engine_result.py
35 36 37 38 39 40 | |
to_json
to_json() -> str
Return a json string serializing this instance.
Source code in presidio_anonymizer/entities/engine/result/engine_result.py
42 43 44 | |
InvalidParamError
Bases: Exception
Throw exception with error when user input is not valid.
param msg: Message to be added to the exception
Source code in presidio_anonymizer/entities/invalid_exception.py
4 5 6 7 8 9 10 11 12 | |
OperatorConfig
Hold the data of the required operator.
| METHOD | DESCRIPTION |
|---|---|
from_json |
Create OperatorConfig from json. |
Source code in presidio_anonymizer/entities/engine/operator_config.py
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 | |
from_json
classmethod
from_json(params: Dict) -> OperatorConfig
Create OperatorConfig from json.
| PARAMETER | DESCRIPTION |
|---|---|
params
|
json e.g.: { "type": "mask", "masking_char": "*", "chars_to_mask": 4, "from_end": true }
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
OperatorConfig
|
OperatorConfig |
Source code in presidio_anonymizer/entities/engine/operator_config.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | |
OperatorResult
Bases: PIIEntity
A class to hold data for engines results either anonymize or deanonymize.
| METHOD | DESCRIPTION |
|---|---|
to_dict |
Return object as Dict. |
from_json |
Create OperatorResult from user json. |
Source code in presidio_anonymizer/entities/engine/result/operator_result.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 65 66 67 68 69 70 71 72 73 74 | |
to_dict
to_dict() -> Dict
Return object as Dict.
Source code in presidio_anonymizer/entities/engine/result/operator_result.py
25 26 27 | |
from_json
classmethod
from_json(json: Dict) -> OperatorResult
Create OperatorResult from user json.
| PARAMETER | DESCRIPTION |
|---|---|
json
|
json representation for this operator result. For example: { "start": 0, "end": 10, "key": "1111111111111111", "entity_type":"PERSON", "text":"resulted_text", "operator":"encrypt", }
TYPE:
|
Source code in presidio_anonymizer/entities/engine/result/operator_result.py
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 | |
PIIEntity
Bases: ABC
Abstract class to hold the text we are going to operate on metadata.
Source code in presidio_anonymizer/entities/engine/pii_entity.py
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 | |
RecognizerResult
Bases: PIIEntity
Recognizer Result represents the findings of the detected entity.
Result of a recognizer analyzing the text.
| PARAMETER | DESCRIPTION |
|---|---|
entity_type
|
the type of the entity
TYPE:
|
start
|
the start location of the detected entity
TYPE:
|
end
|
the end location of the detected entity
TYPE:
|
score
|
the score of the detection
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
from_json |
Create RecognizerResult from json. |
has_conflict |
Check if two recognizer results are conflicted or not. |
contains |
Check if one result is contained or equal to another result. |
equal_indices |
Check if the indices are equal between two results. |
intersects |
Check if self intersects with a different RecognizerResult. |
Source code in presidio_anonymizer/entities/engine/recognizer_result.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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 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 130 131 132 133 134 135 136 137 138 139 | |
from_json
classmethod
from_json(data: Dict)
Create RecognizerResult from json.
| PARAMETER | DESCRIPTION |
|---|---|
data
|
e.g. { "start": 24, "end": 32, "score": 0.8, "entity_type": "NAME" }
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
RecognizerResult |
Source code in presidio_anonymizer/entities/engine/recognizer_result.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | |
has_conflict
has_conflict(other)
Check if two recognizer results are conflicted or not.
I have a conflict if: 1. My indices are the same as the other and my score is lower. 2. If my indices are contained in another.
| PARAMETER | DESCRIPTION |
|---|---|
other
|
RecognizerResult
|
| RETURNS | DESCRIPTION |
|---|---|
|
|
Source code in presidio_anonymizer/entities/engine/recognizer_result.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 | |
contains
contains(other)
Check if one result is contained or equal to another result.
| PARAMETER | DESCRIPTION |
|---|---|
other
|
another RecognizerResult
|
| RETURNS | DESCRIPTION |
|---|---|
|
bool |
Source code in presidio_anonymizer/entities/engine/recognizer_result.py
108 109 110 111 112 113 114 115 | |
equal_indices
equal_indices(other)
Check if the indices are equal between two results.
| PARAMETER | DESCRIPTION |
|---|---|
other
|
another RecognizerResult
|
| RETURNS | DESCRIPTION |
|---|---|
|
|
Source code in presidio_anonymizer/entities/engine/recognizer_result.py
117 118 119 120 121 122 123 124 | |
intersects
intersects(other) -> int
Check if self intersects with a different RecognizerResult.
| RETURNS | DESCRIPTION |
|---|---|
int
|
If intersecting, returns the number of intersecting characters. If not, returns 0 |
Source code in presidio_anonymizer/entities/engine/recognizer_result.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 | |