Skip to main content

Detect and redact PII and secret-like values before logging or sending text to AI providers. Python port of @mukundakatta/pii-sentry.

Project description

pii-sentry-py

PyPI Python License: MIT

Detect and redact PII and secret-like values before logging or sending text to AI providers. Zero runtime dependencies.

Python port of @mukundakatta/pii-sentry. The JS sibling has the full design notes; this README sticks to the Python API.

Install

pip install pii-sentry-py

Usage

from pii_sentry import detect, redact, Detector

text = "Contact alice@example.com or 555-123-4567. SSN: 123-45-6789."

# Find PII matches.
for match in detect(text):
    print(match.type, match.value, match.start, match.end)
# email   alice@example.com   8   25
# phone   555-123-4567        29  41
# ssn     123-45-6789         48  59

# Inline redaction. Default replacement is f"[REDACTED:{type}]".
redact(text)
# 'Contact [REDACTED:email] or [REDACTED:phone]. SSN: [REDACTED:ssn].'

# Constant or callable replacements work too.
redact(text, "[X]")
redact(text, lambda kind: f"<{kind.upper()}>")

Custom detectors

det = Detector()
det.add_detector("ticket", r"\bJIRA-\d{3,}\b")
det.detect("see JIRA-4892 for details")
# [Match(type='ticket', value='JIRA-4892', start=4, end=13)]

Pre-compiled re.Pattern objects are accepted too, so you can pass flags like re.IGNORECASE.

Bundled detectors

Name Catches
email RFC-shaped email addresses
phone US-format phone numbers (with optional +1)
ssn ###-##-#### US SSNs
credit_card 13-19 digit sequences (loose; pair with Luhn for accuracy)
api_key sk-, ghp_, xoxb-, api_ prefixed keys

Override or remove any of them via Detector.add_detector / Detector.remove_detector.

API differences from the JS sibling

  • detect() returns a list of frozen Match dataclasses (not plain dicts).
  • redact() accepts a constant str or a Callable[[str], str] for replacements.
  • Detector is a real class -- create instances per workload to keep custom detectors isolated.

See the JS sibling's README for the full design notes.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pii_sentry_py-0.1.0.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pii_sentry_py-0.1.0-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file pii_sentry_py-0.1.0.tar.gz.

File metadata

  • Download URL: pii_sentry_py-0.1.0.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for pii_sentry_py-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f42ef686c5ccaa417b3a1b0fe2ebc57d7a55141627695fe7478762cff6d41263
MD5 22e998c092632b9cb991159e32e80ee8
BLAKE2b-256 25df62c438b2252af3d6da058af284697eed5de1fb21b1df439505d6b7b32329

See more details on using hashes here.

File details

Details for the file pii_sentry_py-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pii_sentry_py-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for pii_sentry_py-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b0f8a3adbb638bc777527b09b2098e2fb60e4dae64bfdd1005f8490eb3d037de
MD5 f3ee0052b0bf2c4a3f790c5da8ec81fc
BLAKE2b-256 073c55b2b465bef2495ee4368123b4c308f92241716f262e489b6ae600ba801e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page