Anonymise UK bank statement PDFs by scrambling personal data while preserving document structure.
Project description
uk-bank-statement-anonymiser
Anonymise UK bank statement PDFs by scrambling personal data while preserving layout.
Why?
You need to share bank statements with your accountant, solicitor, or lender — but the PDF contains sensitive data: account numbers, sort codes, IBANs, card numbers, and transaction details.
This tool scrambles that data while keeping the PDF looking like a real bank statement. Your financial data never leaves your machine.
Quick start
pip install uk-bank-statement-anonymiser
from bank_statement_anonymiser import anonymise_pdf
anonymise_pdf("statement.pdf", "anonymised.pdf")
One function. One command. Done.
Important: check before you share
This tool handles known patterns but cannot guarantee that all personally identifiable information has been removed. Bank statement PDFs may contain data in places this tool does not currently scan (e.g. embedded metadata, images, or unusual formatting).
- You must review every anonymised PDF yourself before sharing it with any third party. Verify that no account numbers, names, addresses, balances, or other sensitive data remain visible.
- Do not attach PDFs — anonymised or otherwise — to GitHub issues or discussion threads. Use text excerpts or screenshots with sensitive data redacted instead.
What gets anonymised
| Data type | Method |
|---|---|
| Sort codes | Scrambled to valid format |
| Account numbers | Replaced with random numbers |
| IBANs | Replaced with random IBANs |
| Card numbers | Replaced with random card numbers |
| Merchant names | Scrambled |
| All other text | Letters scrambled, layout preserved |
Supported banks
- HSBC UK (current & savings)
- Natwest
- TSB (Spend & Save & credit card)
- Halifax
More banks can be added — see Contributing.
Why these banks? Each bank uses a different PDF encoding strategy. HSBC uses Latin-1, Natwest uses Identity-H CID fonts, and TSB uses custom ToUnicode CMaps. Other UK bank PDFs may work if they use one of the same approaches.
Custom rules
By default, the library handles common patterns automatically. You can supplement with your own rules:
anonymise_pdf(
"statement.pdf",
"output.pdf",
always_anonymise_path="my_replacements.toml",
never_anonymise_path="my_protected_phrases.toml",
)
-
always_anonymise.toml— Force specific strings to known replacements:"40-37-28" = "00-00-00" "Jason Farrar" = "John Doe"
-
never_anonymise.toml— Protect phrases from being scrambled:exclude = ["My Employer Ltd", "Salary Payment"]
User config files override system config on clashes. Both system and user never_anonymise lists are combined.
Do not commit user config files to source control — they may contain real account numbers or names.
API reference
def anonymise_pdf(
input_path: str | Path,
output_path: str | Path | None = None,
always_anonymise_path: str | Path | None = None,
never_anonymise_path: str | Path | None = None,
debug: bool = False,
) -> Path
| Parameter | Description |
|---|---|
input_path |
Path to the input PDF |
output_path |
Output path. If omitted, writes anonymised_<stem><suffix> alongside the input |
always_anonymise_path |
User replacement rules (optional) |
never_anonymise_path |
User protected phrases (optional) |
debug |
Print diagnostic info to stdout (default False) |
| Returns | Absolute path to the output PDF |
| Raises | FileNotFoundError if input_path does not exist |
How it works
-
Identify sensitive data — Detects sort codes, account numbers, IBANs, card numbers, and other patterns. Each gets a deterministic fake replacement so the same data is always replaced consistently across pages.
-
Protect structural text — Dates, payment type codes, bank URLs, and configured protected phrases are left unchanged.
-
Scramble remaining text — All other letters are replaced with random alternatives; digits and symbols stay intact. The PDF's layout, fonts, images, and line breaks are preserved.
All processing happens locally via pikepdf. No network requests, no accounts, no data collection.
Development
git clone https://github.com/boscorat/uk-bank-statement-anonymiser.git
cd uk-bank-statement-anonymiser
uv sync
uv run pytest
License
MIT — see LICENSE.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file uk_bank_statement_anonymiser-0.1.7.tar.gz.
File metadata
- Download URL: uk_bank_statement_anonymiser-0.1.7.tar.gz
- Upload date:
- Size: 26.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
39a034e3808dc3d474303c3562c81564739b2f1ed62856d92ce3fb4add7a3468
|
|
| MD5 |
56f25822911282deb409421effc45e7a
|
|
| BLAKE2b-256 |
57c30fd2a766f57baafd4cb5369b2d3c41960529af013043c16060fc910eb38a
|
File details
Details for the file uk_bank_statement_anonymiser-0.1.7-py3-none-any.whl.
File metadata
- Download URL: uk_bank_statement_anonymiser-0.1.7-py3-none-any.whl
- Upload date:
- Size: 29.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6d25f73478abfd90d385312d0a137b452d0e09e02ff82990551372398d1dafa8
|
|
| MD5 |
1475822c781c58272084d12e62a39050
|
|
| BLAKE2b-256 |
e5ec10d209b13760074453530eff1a524f9bb19c7ac05136be8dc6578bebb1e9
|