Presidio Analyzer package
Actively maintained. Last release 5 weeks ago, commits in 23 of the last 26 weeks. A safe choice.
pip install presidio-analyzerPresidio analyzer
Description
The Presidio analyzer is a Python based service for detecting PII entities in text.
During analysis, it runs a set of different PII Recognizers, each one in charge of detecting one or more PII entities using different mechanisms.
Presidio analyzer comes with a set of predefined recognizers, but can easily be extended with other types of custom recognizers. Predefined and custom recognizers leverage regex, Named Entity Recognition and other types of logic to detect PII in unstructured text.
Language Model-based PII/PHI Detection
Presidio analyzer supports language model-based PII/PHI detection (LLMs, SLMs) for flexible entity recognition. The current implementation uses LangExtract with support for multiple providers:
- Ollama - Local model deployment for privacy-sensitive environments
- Azure OpenAI - Cloud-based deployment with enterprise features
pip install "presidio-analyzer[langextract]"
Quick Usage
Ollama (local models):
from presidio_analyzer.predefined_recognizers import BasicLangExtractRecognizer
recognizer = BasicLangExtractRecognizer() # Uses default config
Azure OpenAI (cloud models):
from presidio_analyzer.predefined_recognizers import AzureOpenAILangExtractRecognizer
# Simple usage - pass everything as parameters
recognizer = AzureOpenAILangExtractRecognizer(
model_id="gpt-4", # Your Azure deployment name
azure_endpoint="https://your-resource.openai.azure.com/",
api_key="your-api-key"
)
# Or use environment variables (AZURE_OPENAI_ENDPOINT, AZURE_OPENAI_API_KEY):
recognizer = AzureOpenAILangExtractRecognizer(
model_id="gpt-4" # Your Azure deployment name
)
# Advanced: Customize entities/prompts with config file
recognizer = AzureOpenAILangExtractRecognizer(
model_id="gpt-4",
config_path="./custom_config.yaml", # Optional: for custom entities/prompts
azure_endpoint="https://your-resource.openai.azure.com/",
api_key="your-api-key"
)
Note: LangExtract recognizers do not validate connectivity during initialization. Connection errors or missing models will be reported when analyze() is first called.
See the Language Model-based PII/PHI Detection guide for complete setup and usage instructions.