Registry / auth-security / presidio-anonymizer

presidio-anonymizer

JSON →
library2.2.364pypypi✓ verified 26d ago

Presidio Anonymizer is a Python-based module designed for anonymizing detected Personally Identifiable Information (PII) entities in text. It offers a range of built-in operators (e.g., replace, mask, redact, hash, encrypt) and supports custom anonymization logic. It also includes deanonymization capabilities for reversible operations like decryption. The library is actively maintained by Microsoft, with frequent releases, and is currently at version 2.2.362.

pip install presidio-anonymizer
INSTALL
IMPORT
SIG · PRESIDIO-ANONYMIZE
P
presidio-anonymizer
auth-securitypythonv2.2.364
Install
13.0s avg
Import
109ms
Disk
32MB
Pass rate
8/ 10
Env Coverage8 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.2.364 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
✓ —
✓ 14.3s
py 3.11
✓ —
✓ 13.2s
py 3.12
✓ —
✓ 11.85s
py 3.13
✓ —
✓ 12.7s
py 3.9
1/2 runs
1/2 runs
32MB installed
● package 32MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

AnonymizerEngine
from presidio_anonymizer import AnonymizerEngine
RecognizerResult
from presidio_anonymizer.entities import RecognizerResult
from presidio_analyzer.recognizer_result import RecognizerResult
While presidio-analyzer also has a RecognizerResult, it's a separate type. For direct use with AnonymizerEngine, import from `presidio_anonymizer.entities` to avoid mypy type errors.
OperatorConfig
from presidio_anonymizer.entities import OperatorConfig

This quickstart demonstrates how to use `AnonymizerEngine` to anonymize text. It manually defines `RecognizerResult` objects, which would typically be generated by `presidio-analyzer`. It shows custom operators for different entity types.

from presidio_anonymizer import AnonymizerEngine from presidio_anonymizer.entities import RecognizerResult, OperatorConfig # Sample text and mock analyzer results (typically from presidio-analyzer) text = "My name is John Doe and my phone number is 123-456-7890." analyzer_results = [ RecognizerResult(entity_type="PERSON", start=11, end=19, score=0.9), RecognizerResult(entity_type="PHONE_NUMBER", start=38, end=50, score=0.8), ] # Initialize the anonymizer engine anonymizer = AnonymizerEngine() # Define anonymization operators # Here, PERSON will be replaced with "<PERSON>", and PHONE_NUMBER will be masked operators = { "PERSON": OperatorConfig("replace", {"new_value": "<PERSON>"}), "PHONE_NUMBER": OperatorConfig("mask", { "masking_char": "*", "chars_to_mask": 10, "from_end": True }) } # Perform anonymization anonymized_result = anonymizer.anonymize( text=text, analyzer_results=analyzer_results, operators=operators ) print(f"Original text: {text}") print(f"Anonymized text: {anonymized_result.text}")
Debug
Known issues
breakingThe default behavior of the 'hash' operator changed in version 2.2.361. It now uses a random salt by default for enhanced security, which means the same PII value will yield different hashes across calls or entities. This breaks referential integrity unless a salt is explicitly provided.
fix
If referential integrity (same hash for the same value) is required, you must explicitly provide a consistent 'salt' parameter to the 'hash' operator config. Use a secure method to generate and store this salt.
affects: >=2.2.361
gotchaWhen using `presidio-analyzer` and `presidio-anonymizer` together in a typed Python environment, `mypy` might report type errors due to `RecognizerResult` existing in both packages with incompatible types. The `AnonymizerEngine` expects `RecognizerResult` from `presidio_anonymizer.entities`.
fix
Always import `RecognizerResult` specifically from `presidio_anonymizer.entities` when passing results to `AnonymizerEngine`. You may need to cast or convert `presidio-analyzer`'s `RecognizerResult` objects if you generate them from `AnalyzerEngine` and need to satisfy strict type checking.
affects: >=2.2.354
gotchaStarting from version 2.2.359, many country-specific recognizers (e.g., SgFinRecognizer, AuAbnRecognizer) are disabled by default to prevent false positives when they are not explicitly needed. Users expecting these to work out-of-the-box might find them inactive.
fix
If specific country-specific recognizers are required, ensure they are explicitly enabled or configured within your `presidio-analyzer` setup.
affects: >=2.2.359
gotchaIn versions prior to 2.2.362, `AnonymizerEngine` could fail to anonymize all instances of an entity if multiple identical entities were separated only by spaces, potentially leading to PII leakage (e.g., 'email1@example.com email2@example.com'). A fix was implemented in 2.2.362.
fix
Upgrade to version 2.2.362 or later. Ensure thorough testing of anonymization output, especially for texts with repeated PII entities separated by whitespace.
affects: <2.2.362
gotchaWhile `presidio-anonymizer` is a standalone package, a complete PII detection and anonymization pipeline typically requires `presidio-analyzer` for detection and an underlying NLP engine (like spaCy with a language model such as `en_core_web_lg`). Not installing these dependencies will prevent the full workflow from functioning.
fix
For a complete solution, install `presidio-analyzer` and a spaCy language model using `pip install presidio-analyzer "spacy[en]"` and `python -m spacy download en_core_web_lg`.
affects: All versions
Errors
Common errors & fixes
ImportError: cannot import name 'AnonymizerConfig' from 'presidio_anonymizer'
The `AnonymizerConfig` class has been deprecated or moved to a different location in recent versions of `presidio-anonymizer`.
fix
Instead of `AnonymizerConfig`, you should typically use `OperatorConfig` or directly define operator parameters within the `anonymize` method. Remove the import for `AnonymizerConfig` and adjust your code to use `OperatorConfig` for configuring anonymization operators, if needed.
AttributeError: 'RecognizerResult' object has no attribute 'has_conflict'
This error often occurs due to an incompatibility between the versions of `presidio-analyzer` and `presidio-anonymizer`, where the `RecognizerResult` object structure or its methods have changed.
fix
Ensure both `presidio-analyzer` and `presidio-anonymizer` are updated to compatible versions, ideally the latest stable releases, by running `pip install --upgrade presidio-analyzer presidio-anonymizer`.
ModuleNotFoundError: No module named 'presidio_anonymizer'
The `presidio-anonymizer` package is not installed in your Python environment or the environment is not correctly activated.
fix
Install the package using pip: `pip install presidio-anonymizer`. If you also use the analyzer, install both: `pip install presidio-analyzer presidio-anonymizer`. Additionally, remember to download a spaCy model if using the default NLP engine: `python -m spacy download en_core_web_lg`.
AnonymizerEngine only anonymizes first entity when multiple entities are space-separated
By default, `AnonymizerEngine` might merge space-separated entities of the same type, leading to only the first occurrence being anonymized, and subsequent entities being exposed.
fix
To prevent this behavior, pass the `merge_whitespace_entities=False` parameter to the `anonymize` method of `AnonymizerEngine`.
Upgrade
Version history
2.2.364latest on PyPI · released Jul 22, 2026
Audit
Dependencies
pythonrequiredRequired Python version.
presidio-analyzeroptionalOften used in conjunction for PII detection before anonymization. Provides the RecognizerResult objects needed by AnonymizerEngine.
spacyoptionalRequired by presidio-analyzer for NLP capabilities and language models (e.g., en_core_web_lg) to detect PII.
Agent activity
19 hits · last 30 days
node
14
OpenAI (training)
2
Resources
presidio-anonymizer — pip install presidio-anonymizer · libregistry