isomorphism
Reversible anonymisation of Swiss personal data for Python. It replaces AHV numbers, IBANs, UID numbers, phone numbers and email addresses with placeholders before a text goes to a language model, and puts the real values back into the answer.
- Local only. No network calls, no telemetry, no dependencies, nothing downloaded at runtime.
- Reversible.
anonymize(text)returns the text with placeholders and a mapping,restore(text, mapping)undoes it. - Same value, same placeholder. The model can follow that
[AHV_1]appears three times. - Checksums. AHV (EAN-13), IBAN (mod 97) and UID (mod 11) are verified. Numbers that look right but fail the check are reported anyway, with lower confidence.
- Audit-friendly. Every hit comes back as kind, position, confidence and recogniser, without the value.
Python 3.12 or newer. MIT license.
pip install isomorphism
from isomorphism import anonymize, restore
text = "Anna Muster, AHV 756.1234.5678.97, IBAN CH93 0076 2011 6238 5295 7, Tel. 071 123 45 67"
safe, mapping = anonymize(text, lang="de")
# 'Anna Muster, AHV [AHV_1], IBAN [IBAN_1], Tel. [PHONE_1]'
answer = call_your_model(safe) # the model only sees placeholders
print(restore(answer, mapping)) # real values are back
The mapping holds the real values. This package never logs or stores it; keeping it (in memory, per request) is up to you. repr(mapping) shows only the number of placeholders.
What it finds
| Kind | Placeholder | Formats | Check |
|---|---|---|---|
| AHV number | [AHV_n] |
756.1234.5678.97, with spaces or without separators |
prefix 756, EAN-13 |
| IBAN (CH, LI) | [IBAN_n] |
with or without spaces, upper or lower case | mod 97 |
| UID number | [UID_n] |
CHE-123.456.788, CHE123456788; MWST/TVA/IVA/HR stay in the text |
mod 11 |
| Phone (Switzerland) | [PHONE_n] |
+41 71 123 45 67, 0041 …, +41 (0)71 …, 071 123 45 67, 071/123 45 67, (071) …, 0711234567 |
format |
[EMAIL_n] |
format |
detect(text) returns the hits without changing the text. Passing keep=["info@gemeinde.example"] leaves exact values untouched (case-insensitive), for example the address of an authority.
Measured on the test cases
tests/cases.py holds invented Swiss texts (payslip extract, client email, receipt, tax query, French and Italian letters, written-out variants, numbers with wrong check digits, and a text full of look-alikes that must not match). The numbers below come from python -m tests.measure, and a test fails if they are out of date or if a listed value slips through.
| Kind | Expected | Found | Missed | False alarms |
|---|---|---|---|---|
| AHV | 10 | 10 | 0 | 0 |
| IBAN | 10 | 10 | 0 | 0 |
| UID | 9 | 9 | 0 | 0 |
| PHONE | 15 | 15 | 0 | 0 |
| 6 | 6 | 0 | 0 |
This is a small invented set, not a benchmark on real documents. Read it as a regression guard, and test with your own (invented) samples before you rely on it.
Not in this version
Personal names, postal addresses, company names, dates of birth, account and card numbers, and restoring a streamed answer arrive in the next version. Until then names and addresses stay in the text. lang ("de", "fr", "it", "en") is accepted and checked already but has no effect yet. Foreign IBANs and the old 11-digit AHV format are not recognised.
No tool finds all personal data. Treat the result as one protective layer, not as a guarantee of anonymity.
Development
uv venv && uv pip install -e . pytest ruff mypy
ruff check . && ruff format --check . && mypy && pytest
Metadata
Release files for isomorphism 0.1.0
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 |
|---|---|---|---|---|
| isomorphism-0.1.0.tar.gz | 14.4 kB | With provenance | Details for isomorphism-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| isomorphism-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for isomorphism-0.1.0-py3-none-any.whl |
Total release size: 22.6 kB
Release files / isomorphism-0.1.0.tar.gz
| Download URL | isomorphism-0.1.0.tar.gz |
|---|---|
| Size | 14.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1bf4847c22a1959a62ee8b1be34c50731e36a799f1038c932f1223a67127bcae
|
|
BLAKE2b-256 checksum How to use checksums |
8961beb9ee7da6ef44870a78509284e4fc18933b44f79e5a0159c60c86bbf524
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 2, 2026.
Transparency logRelease files / isomorphism-0.1.0-py3-none-any.whl
| Download URL | isomorphism-0.1.0-py3-none-any.whl |
|---|---|
| Size | 8.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
39b139ba0769998de216209031e40954a1dc3f8452adbd2dc9daf3d2ba5833a4
|
|
BLAKE2b-256 checksum How to use checksums |
b1dde47c75a7346aea7f5a99b15b749cdf6c025df0eba29815910e81c654f7ed
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 2, 2026.
Transparency logSecurity for isomorphism 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.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for isomorphism-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 2, 2026.
Transparency logA 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.