Skip to main content

rahasya

Thirty-four kinds of personal identifier, each a pattern with a checksum, read in context. 1.000 precision at recall 1.000 on a held-out corpus; 0.996 on the corpus they were tuned against. No model, no network, no gigabyte on disk.

Install

uv add rahasya

The one call

r = pii_report('Invoice for ada@example.com. Card 4111 1111 1111 1111. '
                'KEY=sk-abcdefghijklmnopqrstuvwxyz123456')
r.has_pii, r.identifying

has_pii counts only IDENTIFYING kinds. An IP address is reported and does not tip the gate.

redact('Card 4111 1111 1111 1111 charged to ada@example.com')

Digits are read in context

A number that fails its checksum is not the thing the checksum protects, and a number introduced by a word that makes it a reference is not an identifier at all.

[pii_report(t).has_pii for t in
 ('Order 4111 1111 1111 1112 shipped',   # fails Luhn
  'Conforms to EN 60601-1',              # a standard, not a ZIP
  'Card 4111 1111 1111 1111')]           # this one is a card

DESIGNATOR holds the words that do it: ISO, RFC, invoice, page, commit, order and thirty more. It is matched against the 48 characters to the left of a candidate.

Nineteen regional identifiers, each with its own checksum

Aadhaar, PAN and GSTIN; Australian TFN, ABN and Medicare; Singapore NRIC; Thai national ID; Dutch BSN; French NIR; Spanish DNI and NIE; Italian codice fiscale; Polish PESEL; Swedish personnummer; Norwegian fødselsnummer; German Steuer-IdNr; UK NINO; IMEI.

import random
a = gen_aadhaar(random.Random(0))            # a valid one, for a fixture
a, aadhaar_ok(a), pesel_ok('44051401359'), nino_ok('AB123456C')

Names are opt-in

ner=True turns on an honorific-anchored pass. Dr Charles Babbage matches; a bare Ada Lovelace does not. scanned_ner says whether anything looked, which keeps “none found” apart from “not looked for”.

(pii_report('Dr Charles Babbage signed it.').has_pii,
 pii_report('Dr Charles Babbage signed it.', ner=True).identifying,
 redact('Dr Charles Babbage signed it.', ner=True))

What is here

name what it does
pii_report spans found, and whether they tip has_pii
pii_spans (start, end, kind, value), de-overlapped longest-first
redact mask matched spans; [EMAIL], [CARD], or a mask you name
redact_obj redact over the strings inside a nested dict or list
person_names / person_spans the honorific-anchored name pass
PATTERNS kind to (pattern, validator); the whole detector as data
IDENTIFYING which kinds tip the gate

luhn, aadhaar_ok, pesel_ok and the rest are exported too, because a checksum is useful on its own.

Why no model

Two learned detectors were measured against these patterns and neither is shipped. Both lose on precision and recall, and are 200 times slower. A DeBERTa-v3 ONNX classifier earns its gigabyte only on names no honorific introduces (2/8 to 5/8 of them). A 350M tflite encoder finds no names at all.

Development

The notebooks in nbs/ are the source; the modules are generated.

pip install -e .
nbdev_prepare

Download files

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

Source Distribution

rahasya-0.0.1.tar.gz (17.0 kB view details)

Uploaded Source

Built Distribution

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

rahasya-0.0.1-py3-none-any.whl (17.3 kB view details)

Uploaded Python 3

File details

Details for the file rahasya-0.0.1.tar.gz.

File metadata

  • Download URL: rahasya-0.0.1.tar.gz
  • Upload date:
  • Size: 17.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.1

File hashes

Hashes for rahasya-0.0.1.tar.gz
Algorithm Hash digest
SHA256 fe619dcabef029d2e94386521af5346ca34b45bada77ed2a2608783444f6d53e
MD5 a6dc4eb99a9f97e895178472658fe952
BLAKE2b-256 316d206ea7e9dd6e847f640e840dfc23050145eea4f59207511b0d373aaf1fe3

See more details on using hashes here.

File details

Details for the file rahasya-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: rahasya-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 17.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.1

File hashes

Hashes for rahasya-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 14117d8eacc988a53d7046cd0970d20f590c298dbbd917d67f797549ab8d394f
MD5 88a11479602d2d57ecf04f304d6664bd
BLAKE2b-256 61daaed8220025830b42ea659cb178488829d5f2efe34a46c5c09e8b54f5a711

See more details on using hashes here.

Release history Release notifications | RSS feed

0.0.2

2 files

This release

0.0.1 This release

2 files

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