Skip to main content

scrubdaddy

Finds and removes personal data in text: email addresses, phone numbers, payment cards, bank accounts, IP addresses, API keys and passwords.

The core installs no third-party packages, so adding it to a service does not add a dependency tree to audit. Everything that needs one — phone number parsing, date parsing, named entity models — lives behind an extra.

import scrubdaddy

scrubdaddy.clean("contact joe@example.com or call +44 20 7183 8750")
# 'contact {{EMAIL}} or call {{PHONE}}'

Install

pip install scrubdaddy            # core, no dependencies
pip install 'scrubdaddy[phone]'   # adds phone number detection

Installing an extra is all it takes: the detector it enables joins the default set, and until then nothing fails on an import nobody asked for.

Command line

scrubdaddy clean notes.txt                  # cleaned text on standard output
cat app.log | scrubdaddy clean - --count    # {{EMAIL-0}}, numbered per entity
scrubdaddy find notes.txt --json            # one JSON object per finding
scrubdaddy list-detectors --locale ru_RU    # what would run here

find leaves the matched text out of its output unless --include-text is given, and --exit-code makes it exit non-zero when anything was found, which is enough to fail a build on a leaked key:

scrubdaddy find --detectors secret,password --exit-code src/**/*.py

Finding without replacing

Every finding carries its position, kind, detector and confidence, so it can be reviewed or logged instead of replaced. The matched text is left out of the serialised form unless asked for, since the usual reason to keep findings is an audit trail stored somewhere less protected than the document.

for finding in scrubdaddy.find("card 4111 1111 1111 1111"):
    print(finding.to_dict())
# {'beg': 5, 'end': 24, 'pii_type': 'credit_card', 'detector': 'credit_card',
#  'score': 1.0, 'locale': 'en_US'}

Readable output

A bare placeholder loses the fact that two mentions are the same person. Numbering keeps it, within a document and across a batch:

from scrubdaddy import Scrubber, Token

scrubber = Scrubber(renderer=Token(include_count=True))
scrubber.clean_documents({
    "a.txt": "joe@example.com wrote",
    "b.txt": "joe@example.com and kim@example.com replied",
})
# {'a.txt': '{{EMAIL-0}} wrote', 'b.txt': '{{EMAIL-0}} and {{EMAIL-1}} replied'}

The numbering lives on the scrubber, not on the class, so two scrubbers in one process cannot bleed into each other. It can also be stored and handed to a later run, so the same person keeps the same token tomorrow:

from scrubdaddy import TokenMap

stored = scrubber.tokens.to_dict()
later = Scrubber(renderer=Token(include_count=True), tokens=TokenMap.from_dict(stored))

Instead of numbering, a salted fingerprint gives the same stability without keeping a map. The salt is required rather than generated, because the space of phone or card numbers is small enough to walk through, which would make an unsalted fingerprint reversible by whoever holds the output:

Scrubber(renderer=Token(include_hash=True, salt="…")).clean("joe@example.com")
# '{{EMAIL-7C9A4F12}}'

Mask and Remove cover the cases where no label is wanted.

Confidence, and detectors that disagree

Detectors report how sure they are, so the caller sets the bar rather than the library:

Scrubber(min_score=0.8)

When two detectors claim overlapping text, the conflict is settled by a strategy you choose: the most confident match, the longest one, both fused into one replacement, or all of them kept for auditing. A long weak match that loses does not hide short strong ones underneath it. Findings that merely touch are never glued together.

from scrubdaddy import Strategy

Scrubber(strategy=Strategy.LONGEST)
Scrubber(strategy=Strategy.KEEP_ALL)  # for review, not for replacing

Locales

Identifiers like national insurance or tax numbers are country-specific, so a scrubber runs in a locale and only uses detectors that make sense there:

Scrubber(locale="en_GB")

Custom detectors

import re
from scrubdaddy import RegexDetector, Scrubber
from scrubdaddy.detectors import default_registry

class EmployeeIdDetector(RegexDetector):
    name = "employee_id"
    pii_type = "employee_id"
    pattern = re.compile(r"\bEMP-\d{6}\b")

registry = default_registry()
registry.register(EmployeeIdDetector, autoload=True)
Scrubber(registry=registry).clean("ticket from EMP-123456")
# 'ticket from {{EMPLOYEE_ID}}'

Registering does not enrol a detector into the default set unless asked, so importing a module cannot quietly change what every scrubber does. The registry is an object, not process-wide state: default_registry() hands out a fresh one and copy() branches it.

A package can also advertise its detectors so that they appear without being imported by hand:

[project.entry-points."scrubdaddy.detectors"]
employee_id = "my_package.detectors:EmployeeIdDetector"

They are listed by scrubdaddy list-detectors and usable by name, but stay out of the default set until enabled, and a plugin claiming a name that is already taken is passed over rather than allowed to shadow it. Nothing from the plugin is imported until the detector is used.

Patterns are expected to be free of nested unbounded quantifiers so that they stay linear on hostile input. The test suite runs every shipped pattern against a corpus of pathological strings under a time budget, with a known-bad pattern as a canary to prove the check still has teeth.

Metadata

Release files for scrubdaddy 0.1.1

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

Source distribution (sdist)

Source distribution for scrubdaddy 0.1.1
File Size Uploaded Provenance Actions
scrubdaddy-0.1.1.tar.gz 23.9 kB Without provenance Details for scrubdaddy-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for scrubdaddy 0.1.1
File Interpreter ABI Platform Actions
scrubdaddy-0.1.1-py3-none-any.whl Python 3 none any Details for scrubdaddy-0.1.1-py3-none-any.whl

Total release size: 58.0 kB

Release files / scrubdaddy-0.1.1.tar.gz

Download URL scrubdaddy-0.1.1.tar.gz
Size 23.9 kB
Tags Source
SHA-256 checksum
How to use checksums
a2eb0b669a4693092014bc9b5ba7823ba7960c205d2740840cddf197d70d6378
BLAKE2b-256 checksum
How to use checksums
ab917037fc13e49c57a1efd3772c8a5e057453d620a90882b17047eb5fe1af38
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.23 {"installer":{"name":"uv","version":"0.12.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / scrubdaddy-0.1.1-py3-none-any.whl

Download URL scrubdaddy-0.1.1-py3-none-any.whl
Size 34.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8f37c093524578d198b912c0678a04908ad90544b774a3ff7186eb60ba58cc93
BLAKE2b-256 checksum
How to use checksums
04b290e4ddeb520424f3022e494b5b40951d225eeee6ec66b54fa2de423ff089
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.23 {"installer":{"name":"uv","version":"0.12.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for scrubdaddy 0.1.1

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.1 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