Skip to main content

redacta

Pseudonymise patient identifiers and PII in text — and restore them. A local, dependency-free Python pattern engine.

pip install redacta
from redacta import redact, reinstate

redacted, report, token_map = redact(
    "Dear patient, NHS Number: 943 476 5919, tel 0113 278 4532."
)
# redacted -> "Dear patient, NHS Number: [NHS_NUMBER_1], tel [PHONE_1]."

original = reinstate(redacted, token_map)
# original -> "Dear patient, NHS Number: 943 476 5919, tel 0113 278 4532."

What it detects

Deterministic, checksum-validated patterns: NHS numbers (Modulus-11), UK National Insurance numbers, dates of birth (keyword-anchored; appointment dates left intact by default), UK postcodes, US SSNs and ZIP codes, hospital/MRN numbers, emails, phone numbers, URLs, IP addresses, Luhn-validated payment cards, IBANs, account numbers, and UK vehicle registrations — plus keyword-anchored patient, relative and carer names (clinician names preserved). Same value → same token; a token_map lets you reverse it.

Names in free prose aren't caught (they need an LLM — see the Redacta agent skill). Stdlib only, no network calls; review output before sharing.

Safe Harbor mode

redacted, report, token_map = redact(text, safe_harbor=True)

Applies the stricter HIPAA Safe Harbor (§164.514) pass on top of the default: all dates (not just DOB — appointment dates included), specific ages, fax numbers, certificate/licence numbers, device serial numbers, VINs, and health-plan/beneficiary numbers. Over-redacts slightly versus the letter of the standard, on the safe side. Not legal advice.

Self-check

from redacta import self_check
leftovers = self_check(redacted)   # [{'label': ..., 'sample': ...}, ...]

CLI

redacta letter.txt                 # prints JSON: redacted_text, report, token_map
redacta letter.txt --text-only     # just the redacted text
redacta letter.txt --safe-harbor   # strict HIPAA Safe Harbor pass
redacta-reinstate redacted.txt --map token_map.json

License

MIT-0 (MIT No Attribution). Built by PharmaTools.AI.

Download files

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

Source Distribution

redacta-1.3.0.tar.gz (14.0 kB view details)

Uploaded Source

Built Distribution

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

redacta-1.3.0-py3-none-any.whl (12.8 kB view details)

Uploaded Python 3

File details

Details for the file redacta-1.3.0.tar.gz.

File metadata

  • Download URL: redacta-1.3.0.tar.gz
  • Upload date:
  • Size: 14.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for redacta-1.3.0.tar.gz
Algorithm Hash digest
SHA256 146f3d26859d773dbf3cd3ef19e3107c5ac49761aea0ae6a054bd338f949a424
MD5 0677a7c47d3df10281398d048a6bbe41
BLAKE2b-256 a8a5fcccb08ce745d17a1929251387d5092cc8f3ac12e4d15e03f3150a1d89fd

See more details on using hashes here.

File details

Details for the file redacta-1.3.0-py3-none-any.whl.

File metadata

  • Download URL: redacta-1.3.0-py3-none-any.whl
  • Upload date:
  • Size: 12.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for redacta-1.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 27bca41b9f3289da0fcabb1f9b1525255b04a50ede778b95b7e5f348621b972a
MD5 8b281b3c7727cb6b74136a6788223c70
BLAKE2b-256 be456e44dd2c4817328eb50c255285bfb3a7b965d1bb906464ac3d30731a0247

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