Skip to content

Instantly share code, notes, and snippets.

@suryavanshi
Last active May 19, 2021 08:09
Show Gist options
  • Save suryavanshi/13c0f3299930155964473dbd3934fba7 to your computer and use it in GitHub Desktop.
Save suryavanshi/13c0f3299930155964473dbd3934fba7 to your computer and use it in GitHub Desktop.
presidio_pii.py
#From - https://microsoft.github.io/presidio/getting_started/
from presidio_analyzer import AnalyzerEngine
from presidio_anonymizer import AnonymizerEngine
text="My phone number is 212-555-5555"
# Set up the engine, loads the NLP module (spaCy model by default)
# and other PII recognizers
analyzer = AnalyzerEngine()
# Call analyzer to get results
results = analyzer.analyze(text=text,
entities=["PHONE_NUMBER"],
language='en')
print(results)
# Analyzer results are passed to the AnonymizerEngine for anonymization
anonymizer = AnonymizerEngine()
anonymized_text = anonymizer.anonymize(text=text,analyzer_results=results)
print(anonymized_text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment