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
Metadata
Release files for pii-sentry-py 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pii_sentry_py-0.1.0.tar.gz | 7.2 kB | Without provenance | Details for pii_sentry_py-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pii_sentry_py-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for pii_sentry_py-0.1.0-py3-none-any.whl |
Total release size: 13.8 kB
Release files / pii_sentry_py-0.1.0.tar.gz
| Download URL | pii_sentry_py-0.1.0.tar.gz |
|---|---|
| Size | 7.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f42ef686c5ccaa417b3a1b0fe2ebc57d7a55141627695fe7478762cff6d41263
|
|
BLAKE2b-256 checksum How to use checksums |
25df62c438b2252af3d6da058af284697eed5de1fb21b1df439505d6b7b32329
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.4
|
Release files / pii_sentry_py-0.1.0-py3-none-any.whl
| Download URL | pii_sentry_py-0.1.0-py3-none-any.whl |
|---|---|
| Size | 6.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b0f8a3adbb638bc777527b09b2098e2fb60e4dae64bfdd1005f8490eb3d037de
|
|
BLAKE2b-256 checksum How to use checksums |
073c55b2b465bef2495ee4368123b4c308f92241716f262e489b6ae600ba801e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.4
|
Security for pii-sentry-py 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.