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
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 frozenMatchdataclasses (not plain dicts).redact()accepts a constantstror aCallable[[str], str]for replacements.Detectoris 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f42ef686c5ccaa417b3a1b0fe2ebc57d7a55141627695fe7478762cff6d41263
|
|
| MD5 |
22e998c092632b9cb991159e32e80ee8
|
|
| BLAKE2b-256 |
25df62c438b2252af3d6da058af284697eed5de1fb21b1df439505d6b7b32329
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b0f8a3adbb638bc777527b09b2098e2fb60e4dae64bfdd1005f8490eb3d037de
|
|
| MD5 |
f3ee0052b0bf2c4a3f790c5da8ec81fc
|
|
| BLAKE2b-256 |
073c55b2b465bef2495ee4368123b4c308f92241716f262e489b6ae600ba801e
|