Skip to main content

pii-eraser

Find personal data and secrets in text and code. Replace them with stable placeholders. Do it locally, before the text goes to a model, a log or a vendor.

Contact Jane Doe <jane.doe@example.org>, key AKIA…      →   Contact [NAME_1] <[EMAIL_1]>, key [SECRET_1]
  • Local. Regex rules and an optional NER model run on your machine. No network.
  • Stable. A session keeps one placeholder table across many texts: Jane Doe is [NAME_1] in the diff, in every file an agent reads afterwards, and in the next file, even where no rule fires again.
  • Code-aware. The code profile drops rules that misfire on source (dates in changelogs, numbers that look like phones) and checks card numbers (Luhn) and IBANs (mod-97). Line counts never change, so line numbers in a review still hold.
  • Reversible for the owner. session.restore(text) puts the originals back into a model's answer, on your side.

Install

pip install pii-eraser              # regex rules only, no dependencies
pip install 'pii-eraser[gliner]'    # + GLiNER NER for names and organisations (~400 MB model)

Use

from pii_eraser import Eraser

eraser = Eraser.for_prose()  # documents, emails, MR descriptions
result = eraser.erase("Name: Jane Doe, jane.doe@example.org")
result.text  # 'Name: [NAME_1], [EMAIL_1]'
result.mapping  # {'[NAME_1]': 'Jane Doe', '[EMAIL_1]': 'jane.doe@example.org'}

session = Eraser.for_code().session()  # many texts, one table
session.erase(diff_text)
session.erase(file_the_agent_read)
answer = session.restore(model_answer)

With NER:

from pii_eraser.detectors.gliner import GlinerDetector

Eraser.for_prose(GlinerDetector())  # NER hits are replaced
Eraser.for_code(GlinerDetector())  # NER hits are only reported in result.signals

On source code an NER model tags variable names and authors as people. In the code profile its hits are signals for a human, not replacements.

CLI

pii-eraser contract.txt > contract.clean.txt
git diff origin/main | pii-eraser --profile code --report --fail-on-secret > /dev/null

The report on stderr lists kind, line and rule, never the original value, so it is safe for CI logs. --fail-on-secret exits 1 when a secret is found.

What it finds

Kind Examples
SECRET private key blocks, AWS / GitHub / GitLab / Slack / Anthropic / OpenAI / Google / Stripe keys, JWTs, passwords in URLs, password = "…" / API_KEY=… assignments, long random quoted strings
EMAIL, PHONE emails; international, US, Swiss, German phone formats
NAME labelled names, titles, salutations, signature blocks, contract parties; with NER: any person or organisation
ADDRESS US street / city / state / ZIP, UK postcodes, German streets, labelled addresses
FINANCIAL payment cards (Luhn), IBAN (mod-97), account, routing, tax ids
SSN, NATIONAL_ID, DOB, MRN, HEALTH_PLAN_ID US SSN, Swiss AHV, Spanish NIE/DNI, UK NI, passports, licences, dates of birth, medical record and insurance numbers (EN/DE)

References to secrets are left alone: ${DB_PASSWORD}, <your-token>, os.environ['SECRET'], changeme.

Limits

Detection is heuristic. Rules miss formats they don't know; NER misses rare names and catches some non-names. Treat the output as reduced exposure, not as anonymisation in the legal sense, and keep a secret scanner such as gitleaks in your pipeline: a leaked key must be rotated, not just masked.

Origin

The personal-data rules and NER filters come from the scrubber of 37lab's contract analyzer, tuned on real contracts, medical notes and business email. The secret rules, sessions and the code profile were added for agentic code review in semantic-diff.

License

MIT — 37lab. The default NER model urchade/gliner_medium-v2.1 is Apache-2.0.

Metadata

Release files for pii-eraser 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pii-eraser 0.1.0
File Size Uploaded Provenance Actions
pii_eraser-0.1.0.tar.gz 19.7 kB Without provenance Details for pii_eraser-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pii-eraser 0.1.0
File Interpreter ABI Platform Actions
pii_eraser-0.1.0-py3-none-any.whl Python 3 none any Details for pii_eraser-0.1.0-py3-none-any.whl

Total release size: 41.3 kB

Release files / pii_eraser-0.1.0.tar.gz

Download URL pii_eraser-0.1.0.tar.gz
Size 19.7 kB
Tags Source
SHA-256 checksum
How to use checksums
6170dd8fdbebb2ed2c2d7263ee6a35be3f2a6aab6148d9f5f8bba49b40f6676e
BLAKE2b-256 checksum
How to use checksums
3ff3a473b6629ffaf3d56f484bb5e0da2e2f112a5210d52d7bfe01705bf4d53b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.13

Release files / pii_eraser-0.1.0-py3-none-any.whl

Download URL pii_eraser-0.1.0-py3-none-any.whl
Size 21.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
38954e542a428e2e66a63b227fea04a1df98255a681c35299eeb216ef750f9b9
BLAKE2b-256 checksum
How to use checksums
a38473b663c4ba8e9d873fcacef14a73ad35822dd24729433353d007243c5666
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.13

Security for pii-eraser 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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page