nyms
Reversible pseudonymisation of text before it reaches an AI. A deterministic (non-AI) pass finds personal and sensitive identifiers in Danish and English text, replaces them with surrogates, remembers the mapping per project so the same person is [PERSON_1] in every document, and puts the originals back into whatever the AI answers.
pip install nyms # add "nyms[crypto]" for an encrypted mapping store
from nyms import Pseudonymiser
p = Pseudonymiser("case-2026", names=["Rasmus Østergaard Jensen"])
r = p.pseudonymise("Rasmus Jensen (CPR 010190-1234) skylder 12.500 kr. Rasmus Jensens advokat ringede.")
r.text
# '[PERSON_1] (CPR [CPR_1]) skylder [AMOUNT_1]. [PERSON_1]s advokat ringede.'
p.reidentify("Svar: [PERSON_1] skal betale [AMOUNT_1].").text
# 'Svar: Rasmus Jensen skal betale 12.500 kr.'
p.check("Rasmus Jensen bor her") # what would leak if this were sent
# ['Rasmus Jensen']
The same four verbs from the shell:
nyms pseudonymise --path letter.md --project case-2026 --names "Rasmus Østergaard Jensen" --out letter.pseud.md
nyms reidentify --path answer.md --project case-2026 --out answer.clear.md
nyms check --path draft.md --project case-2026 # {"ok": false, "leaks": [...]} if an original is in it
nyms detect "Rasmus Jensen, tlf. 12 34 56 78" # every span and the policy's decision; nothing stored
nyms readable 010190-1234 --project case-2026 # a keyed hash as two readable words
Content is positional text or --path (a file, or - for stdin), never guessed from one another.
</code></pre>
<p><code>r.report</code> says what was replaced (by type and by detector), what was detected and kept (dates, postcodes and URLs, under the default policy) and which detectors ran, and ends with the caveat that this is pseudonymisation, not anonymisation.</p>
<h2 id="user-content-what-it-finds">What it finds<a href="#user-content-what-it-finds" aria-label="Link to heading 'What it finds'" data-heading-content="What it finds" class="anchor"></a></h2>
<p>Danish: CPR numbers (the date part must be valid; the pre-2007 modulus-11 check only raises confidence, because numbers issued since October 2007 need not pass it), CVR numbers (modulus-11 and context), DK VAT numbers, phone numbers, bank account numbers (registreringsnummer and kontonummer), IBAN (mod-97), street addresses with floor and postcode, postcode and town, amounts (<code>12.500 kr.</code>, <code>DKK 12.500</code>, <code>36.000,-</code>), dates, court and journal numbers. English: addresses, phone numbers, amounts (<code>£4,250.00</code>, <code>$5,000</code>), dates. Both: e-mail, URLs, IBAN, credentials (API keys, tokens, private keys), organisation names by legal form (<code>ApS</code>, <code>A/S</code>, <code>Ltd</code>, <code>GmbH</code>), names after a title (<code>Hr.</code>, <code>advokat</code>, <code>Mr</code>, <code>Dr</code>), names from a bundled Danish and English first-name list, names you pass in (<code>names=</code>), and a low-confidence heuristic for capitalised sequences.</p>
<p>Once a value has been replaced anywhere in a project, every later occurrence is replaced too, including a Danish genitive (<code>Rasmus Jensens</code> becomes <code>[PERSON_1]s</code>), ALL-CAPS headings, and a surname or first name alone when it identifies exactly one known person (<code>Jensen blev</code> becomes <code>[PERSON_1] blev</code>). An identifier inside something the policy keeps (a CPR number in a URL) is still replaced. Pseudonymising already pseudonymised text changes nothing.</p>
<p>It does not find: names it has never seen and the heuristic misses, roles and rare facts that identify without an identifier, inflected compounds, OCR-damaged identifiers. The report's <code>kept</code> list and the <code>check</code> command exist so a reader sees what stayed.</p>
<h2 id="user-content-choosing-what-is-sensitive">Choosing what is sensitive<a href="#user-content-choosing-what-is-sensitive" aria-label="Link to heading 'Choosing what is sensitive'" data-heading-content="Choosing what is sensitive" class="anchor"></a></h2>
<p>A <code>Policy</code> decides after detection, so the report can say what it saw and kept. <code>Policy.default()</code> replaces credentials, persons, CPR, e-mail, phone, addresses, IBAN, bank accounts, case numbers, CVR, organisations and amounts; <code>Policy.identifiers()</code> leaves amounts and organisations; <code>Policy.strict()</code> replaces everything detected, dates and postcodes included. <code>include</code>, <code>exclude</code>, per-type <code>min_score</code>, <code>allow</code> (never replace) and <code>deny</code> (always replace) lists refine any of them. The taxonomy behind the types, with tiers and the equivalent Presidio, Google DLP and HIPAA names, is <code>nyms.taxonomy.ENTITY_TYPES</code>.</p>
<h2 id="user-content-choosing-the-surrogates">Choosing the surrogates<a href="#user-content-choosing-the-surrogates" aria-label="Link to heading 'Choosing the surrogates'" data-heading-content="Choosing the surrogates" class="anchor"></a></h2>
<table>
<thead>
<tr>
<th>Strategy</th>
<th>Example</th>
<th>When</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>Counter()</code> (default)</td>
<td><code>[PERSON_1]</code>, <code>[CPR_2]</code></td>
<td>the form LLMs alter least in the one published benchmark; numbered per project</td>
</tr>
<tr>
<td><code>KeyedWords(key)</code></td>
<td><code>Alder Brook</code>, <code>[CPR:mustard-suitcase]</code></td>
<td>the same surrogate on any machine that has the key, no shared store needed; readable</td>
</tr>
<tr>
<td><code>RandomWords()</code></td>
<td><code>Lunar Cobweb</code></td>
<td>a classic tokenisation vault: random, readable, no key</td>
</tr>
<tr>
<td><code>Aliases({...}, fallback=...)</code></td>
<td><code>the landlord</code></td>
<td>you choose the pseudonym for some values yourself</td>
</tr>
</tbody>
</table>
<p><code>KeyedWords</code> is an HMAC-SHA-256 under the project key rendered as words from the EFF short wordlist (1,296 words, 10.3 bits each). The renderer stands alone as <code>nyms.readable(value, key=...)</code> and <code>nyms readable</code>. There is no unkeyed option: a plain hash of a CPR number is undone by enumerating the ten billion candidates.</p>
<p>Re-identification is tolerant of what models do to bracketed tokens (case, spacing, a dropped bracket, a genitive after it); name-shaped surrogates and aliases are matched exactly, so ordinary prose is left alone. It never guesses: tokens it did not issue come back in <code>unmatched</code>.</p>
<h2 id="user-content-where-the-mapping-and-the-key-live">Where the mapping and the key live<a href="#user-content-where-the-mapping-and-the-key-live" aria-label="Link to heading 'Where the mapping and the key live'" data-heading-content="Where the mapping and the key live" class="anchor"></a></h2>
<p>The mapping store (surrogate, original, type) is the key to the text. By default it is a set of JSON files under <code>~/.local/share/nyms/<project>/mapping/</code>, and the project key is 32 random bytes in <code>~/.config/nyms/keys/<project>.key</code> (mode 0600), created on first use; <code>NYMS_KEY</code> in the environment overrides it, and <code>Pseudonymiser(..., key=...)</code> accepts any bytes. With <code>pip install "nyms[crypto]"</code> and <code>encrypt=True</code> the records are Fernet-encrypted under the key before they hit disk; without it they are plaintext in your user directory, which is the trade-off of needing no dependency. Lose the store and <code>[PERSON_1]</code> cannot be reversed; lose the key and an encrypted store cannot be read. Back both up, apart from each other.</p>
<p>Any <code>MutableMapping</code> works as the store (<code>store=</code>), so <a href="https://github.com/i2mint/dol">dol</a> backends (SQLite, S3) drop in, and <code>store={}</code> keeps a run in memory.</p>
<h2 id="user-content-for-ai-agents">For AI agents<a href="#user-content-for-ai-agents" aria-label="Link to heading 'For AI agents'" data-heading-content="For AI agents" class="anchor"></a></h2>
<!-- epythet:agentic-readme:start -->
<p><code>nyms</code> ships a skill for coding agents, in <a href="https://agentskills.io">Agent Skills</a> format:</p>
<pre><code class="language-bash">gh skill install thorwhalen/nyms nyms --agent claude-code # or copilot, cursor, codex, gemini
| Skill | Use it to |
|---|---|
nyms |
pseudonymise documents before they reach a model, re-identify the answer, and check that nothing leaks |
The skill folder also ships inside the wheel: python -c "import nyms, os; print(os.path.join(nyms.__path__[0], 'data', 'skills'))".
Design
The research behind the design (terminology and regulation, detection libraries and methods, surrogates and key management, pipeline architecture) is in docs/research/, with a synthesis; the decisions are in docs/adr/. Six seams, each one keyword argument of Pseudonymiser: detectors, post_detectors, policy, strategy, store, key. The model-based second pass is the post_detectors seam: any callable text -> spans, run on the already-pseudonymised text with the surrogates protected; none ships in v1.
The EFF wordlist is CC BY 3.0 (see nyms/data/wordlists/NOTICE.md). Everything else is MIT.
Metadata
Release files for nyms 0.0.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| nyms-0.0.5.tar.gz | 103.6 kB | Without provenance | Details for nyms-0.0.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| nyms-0.0.5-py3-none-any.whl | Python 3 | none | any | Details for nyms-0.0.5-py3-none-any.whl |
Total release size: 159.0 kB
Release files / nyms-0.0.5.tar.gz
| Download URL | nyms-0.0.5.tar.gz |
|---|---|
| Size | 103.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
aad00304cb32c5dc77cb5dae108aa8023954ee5c1ba4e13f473c34f061a17df0
|
|
BLAKE2b-256 checksum How to use checksums |
259a8000b707b306ae21bb32f27b0d8ebc697d3c97f780cc053a108937a59b3a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / nyms-0.0.5-py3-none-any.whl
| Download URL | nyms-0.0.5-py3-none-any.whl |
|---|---|
| Size | 55.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f58eb3902a49e399f30a4a0065e33230ee9e5d431b74510274c3dad2ac1937fb
|
|
BLAKE2b-256 checksum How to use checksums |
d8ecf74e6efdd47094f68775a59c63b59b3b7243f311548c45059cd08a7e84c4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for nyms 0.0.5
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.