talira

schwifty

IBAN parsing and validation

open sourceMITfree

schwifty is a Python library for IBANs (ISO 13616), BICs (ISO 9362) and the national account numbers they are built from. It validates IBAN check digits and country formats for the 105 countries of the SWIFT IBAN registry and 22 more, computes and checks national check digits for 24 countries, validates BICs, converts between bank codes and BICs, and looks up the bank behind an IBAN or BIC in registries for 47 countries, updated with each release. It can build an IBAN from a bank code and account number with the national check digits, or generate random valid IBANs for tests, and its IBAN and BIC types work in Pydantic models. It also flags retired bank codes and which SEPA schemes a bank takes part in.

Problems it solves

  • validate the IBAN a customer types into our checkout form in Python
  • check that a bank BIC or SWIFT code is well formed and belongs to the right country
  • show the bank's name next to the account number the user entered
  • fake but valid German and Dutch IBANs for fixtures in pytest
  • build an IBAN from a domestic bank code and account number with the right check digits
  • verify German or French domestic account numbers with their national check digit rules
  • find the BIC for a bank code, or the bank codes for a BIC
  • check whether a customer's bank supports SEPA direct debit before we offer it
  • an old IBAN still uses a bank code that was retired after a merger
  • validate IBAN and BIC fields in my Pydantic models

Features

  • IBAN validation for the 105 SWIFT registry countries and 22 others
  • IBAN generation from country, bank code and account code, with national check digits
  • random valid IBANs for testing
  • national check digit validation and computation for 24 countries
  • BIC validation and conversion between bank codes and BICs
  • bank registries for 47 countries (28 from official sources, 19 maintained by hand)
  • retired bank codes, with whether the bank merged or closed
  • SEPA scheme participation from the Deutsche Bundesbank's SCL directory
  • IBAN and BIC types for Pydantic models
  • CalVer releases so registry updates ship regularly

Limitations

  • Doesn't know the bank for every country: its bank registries cover 47 countries1
  • Doesn't check national account check digits for most countries: it has the algorithms for 2423
  • Doesn't support Python versions before 3.112