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 one 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 failing its checksum is not the thing the checksum protects. A number introduced by a reference word is not an identifier.

[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

where kinds
India Aadhaar, PAN, GSTIN
Australia TFN, ABN, Medicare
Europe Dutch BSN, French NIR, Spanish DNI and NIE, Italian codice fiscale, Polish PESEL, Swedish personnummer, Norwegian fødselsnummer, German Steuer-IdNr, UK NINO
Asia-Pacific Singapore NRIC, Thai national ID
anywhere 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.

No model

Two learned detectors were measured against these patterns. 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.2.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.2-py3-none-any.whl (17.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for rahasya-0.0.2.tar.gz
Algorithm Hash digest
SHA256 b1da4171c09eeaf8d3459c4d05f110d21586575c51de5334b49fdc968c7ae6cc
MD5 71c6846032b1f3e0bbf9d16fc16225e4
BLAKE2b-256 03b442706ed241c673c573a8ee201e4978d0320f92b9c76f2c87f330a5fe62c0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: rahasya-0.0.2-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.14.6

File hashes

Hashes for rahasya-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7bf0902c549d002b8e4894acd5183cb3d3862c601209d6808fec7218ec42fab8
MD5 181c84038bd7f634ec62d9aee68c4bcd
BLAKE2b-256 7174ea2540becce789f5002c0547f3b4e1072beedbeb042a0d91a941affef45a

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 files

0.0.1

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