iban-pure
Zero-dependency pure-Python IBAN mod-97 validator (ISO 13616-1:2007).
"Would I be sad if this repo didn't exist?" — A tiny, no-dependency library for validating and formatting IBANs in any Python project, including strict environments where adding a package is friction.
pip install git+https://github.com/prasad-a-abhishek/iban-pure.git
>>> from iban_pure import validate, compute_check_digits, format_display
>>> validate("DE89370400440532013000")
True
>>> compute_check_digits("DE370400440532013000") # BBAN = country + account
'89'
>>> format_display("DE89370400440532013000")
'DE89 3704 0044 0532 0130 00'
Why iban-pure?
- Zero dependencies — pure stdlib, no
pip installsurprises - Strict mode by default — rejects malformed input immediately (no silently ignored errors)
- ISO 13616-1:2007 compliant — full mod-97 check, letter substitution, rearrangement
- 103 tests covering all 8 acceptance criteria — every edge case documented and tested
Key Features
validate(iban)— ReturnsTrue/Falseafter mod-97 check. Accepts spaces, lower-case.compute_check_digits(bban)— Given a BBAN ("DE370400440532013000"), returns the two check digits ("89"). Prependcountry + check + accountto get a valid IBAN.format_display(iban)— Groups IBAN into 4-character blocks (e.g."DE89 3704 0044 0532 0130 00").
CLI
python -m iban_pure "DE89370400440532013000"
# DE89370400440532013000 — VALID
python -m iban_pure --check "DE370400440532013000"
# Check digits: 89
python -m iban_pure --format "DE89 3704 0044 0532 0130 00"
# DE89 3704 0044 0532 0130 00
API Reference
validate(iban: str) -> bool
Passes iban through ISO 13616-1:2007 mod-97 check:
- Strips spaces and hyphens, uppercases
- Rearranges: moves first 4 chars to the end
- Substitutes letters: A→10, B→11, ..., Z→35
- Returns
int(numeric) % 97 == 1
Returns False for empty strings, non-alphanumeric characters, or wrong lengths per country.
compute_check_digits(bban: str) -> str
Input: a BBAN string = country code (2 chars) + account portion (N chars).
Example:
compute_check_digits("DE370400440532013000") # → "89"
# DE89 + 370400440532013000 = DE89370400440532013000 (valid IBAN)
Raises ValueError for strings shorter than 5 characters or containing non-alphanumeric characters.
format_display(iban: str) -> str
Formats iban with spaces every 4 characters, uppercased. Existing spaces are ignored.
format_display("de89 3704 0044 0532 0130 00") # → "DE89 3704 0044 0532 0130 00"
Supported Countries
DE (22), GB (22), FR (27), ES (24), NL (18), BE (16), AT (20), SE (24), NO (15), CH (21), FI (18), DK (18), IT (26).
Limitations
- No BBAN-length validation per country (only full IBAN length is checked at the 15–34 char range)
- No network access or API calls
- Does not verify that an IBAN corresponds to a real bank account
Known Issues (audit-deferred, tracked for cycle_68)
The following findings were identified by the vulnerability audit and confirmed by fuzzing. All are accepted-risk for v0.1.0 and none are blocking.
Medium (3):
compute_check_digitsraisesTypeErroron non-string input (e.g.None,int) — noisinstanceguard- Spec described a 4-argument
validate(iban, normalize, format, check)API; shipped has 3 arguments (nonormalize) - Spec described a 2-argument
compute_check_digits(bban, country); shipped is 1-argument
Low (3):
- Test fixture
DK5000400440116243is a stale/wrong fixture (should beDK5000400440116243per official validation) - README documents
python -m iban_purebut no__main__.pyentry point exists format_displaysilently strips whitespace and ignores garbage characters instead of raising
Non-goals
- Bank account lookup or validation against a live database
- Generating random valid IBANs
- Support for IBANs older than ISO 13616-1:2007
Install
pip install git+https://github.com/prasad-a-abhishek/iban-pure.git
For development:
git clone https://github.com/prasad-a-abhishek/iban-pure.git
cd iban-pure
pip install -e .
Test
pytest tests/ -v
License
MIT — see LICENSE file.
Metadata
Release files for iban-pure 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 | |
|---|---|---|---|
| iban_pure-0.1.0.tar.gz | 7.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| iban_pure-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 12.6 kB
Release files / iban_pure-0.1.0.tar.gz
| Download URL | iban_pure-0.1.0.tar.gz |
|---|---|
| Size | 7.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a47c825de470e5b278be315cd95729ce286510086a1dea1d87dcd0b2b7e9f29e
|
|
BLAKE2b-256 checksum How to use checksums |
fc413591f86e909171df3bea99228b025f14baf445981012e34f210aace42535
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.15
|
Release files / iban_pure-0.1.0-py3-none-any.whl
| Download URL | iban_pure-0.1.0-py3-none-any.whl |
|---|---|
| Size | 4.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
28518c5a7cddb95aaeba4cd39de1f1def23f20983ed495a52cb6ed549e8f0d06
|
|
BLAKE2b-256 checksum How to use checksums |
93003907f223fb5b0a20578c74523d2a7d9d76fc8b4cbb9973e189c4bb77e977
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.15
|