Presidio Anonymizer API Reference
Anonymizer root module.
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.
Source code in /opt/hostedtoolcache/Python/3.10.11/x64/lib/python3.10/site-packages/presidio_anonymizer/anonymizer_engine.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 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 |
|
anonymize(text, analyzer_results, operators=None)
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'} ]
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text |
str
|
the text we are anonymizing |
required |
analyzer_results |
List[RecognizerResult]
|
A list of RecognizerResult class -> The results we received from the analyzer |
required |
operators |
Optional[Dict[str, OperatorConfig]]
|
The configuration of the anonymizers we would like to use for each entity e.g.: {"PHONE_NUMBER":OperatorConfig("redact", {})} received from the analyzer |
None
|
Returns:
Type | Description |
---|---|
EngineResult
|
the anonymized text and a list of information about the anonymized entities. |
Source code in /opt/hostedtoolcache/Python/3.10.11/x64/lib/python3.10/site-packages/presidio_anonymizer/anonymizer_engine.py
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 |
|
get_anonymizers()
Return a list of supported anonymizers.
Source code in /opt/hostedtoolcache/Python/3.10.11/x64/lib/python3.10/site-packages/presidio_anonymizer/anonymizer_engine.py
142 143 144 145 |
|
BatchAnonymizerEngine
BatchAnonymizerEngine class.
A class that provides functionality to anonymize in batches.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
anonymizer_engine |
Optional[AnonymizerEngine]
|
An instance of the AnonymizerEngine class. |
None
|
Source code in /opt/hostedtoolcache/Python/3.10.11/x64/lib/python3.10/site-packages/presidio_anonymizer/batch_anonymizer_engine.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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
|
anonymize_dict(analyzer_results, **kwargs)
Anonymize values in a dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
analyzer_results |
Iterable[DictRecognizerResult]
|
Iterator of |
required |
kwargs |
Additional kwargs for the |
{}
|
Source code in /opt/hostedtoolcache/Python/3.10.11/x64/lib/python3.10/site-packages/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 |
|
anonymize_list(texts, recognizer_results_list, **kwargs)
Anonymize a list of strings.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
texts |
List[Union[str, bool, int, float]]
|
List containing the texts to be anonymized (original texts) |
required |
recognizer_results_list |
List[List[RecognizerResult]]
|
A list of lists of RecognizerResult, the output of the AnalyzerEngine on each text in the list. |
required |
kwargs |
Additional kwargs for the |
{}
|
Source code in /opt/hostedtoolcache/Python/3.10.11/x64/lib/python3.10/site-packages/presidio_anonymizer/batch_anonymizer_engine.py
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 |
|
DeanonymizeEngine
Bases: EngineBase
Deanonymize text that was previously anonymized.
Source code in /opt/hostedtoolcache/Python/3.10.11/x64/lib/python3.10/site-packages/presidio_anonymizer/deanonymize_engine.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 |
|
deanonymize(text, entities, operators)
Receive the text, entities and operators to perform deanonymization over.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
operators |
Dict[str, OperatorConfig]
|
the operators to apply on the anonymizer result entities |
required |
text |
str
|
the full text with the encrypted entities |
required |
entities |
List[OperatorResult]
|
list of encrypted entities |
required |
Returns:
Type | Description |
---|---|
EngineResult
|
EngineResult - the new text and data about the deanonymized entities. |
Source code in /opt/hostedtoolcache/Python/3.10.11/x64/lib/python3.10/site-packages/presidio_anonymizer/deanonymize_engine.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
|
get_deanonymizers()
Return a list of supported deanonymizers.
Source code in /opt/hostedtoolcache/Python/3.10.11/x64/lib/python3.10/site-packages/presidio_anonymizer/deanonymize_engine.py
33 34 35 36 |
|