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.2.1.tar.gz (13.2 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.2.1-py3-none-any.whl (12.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for redacta-1.2.1.tar.gz
Algorithm Hash digest
SHA256 398e5caaa1be70c2809c30e3983172f4833367ccf29b609ed498ffde89a85a98
MD5 740558bf260c2c0433592e196cc623b2
BLAKE2b-256 f4549f57056729fadd606d03301ef305681b02e74a2a1f30bab33eff5c4aa335

See more details on using hashes here.

File details

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

File metadata

  • Download URL: redacta-1.2.1-py3-none-any.whl
  • Upload date:
  • Size: 12.3 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.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 912fa764ff37b6e2fd9ece490db3c8adbd28fe56e0f4fd50e506fd66d85f57d2
MD5 77e2583c4a8695074b46d5a6133438b5
BLAKE2b-256 b652421533f7a049abdf164fd28196286c3a98635f51074013fe7e115effc984

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