Schwifty IBAN and BIC Validation
Schwifty is a Python library for easily working with IBANs and BICs as specified by the ISO, enabling validation, parsing, and generation of international bank account numbers and business identifier codes. It is actively maintained with regular monthly or bi-monthly releases, and the current version is 2026.3.0.
Warnings
- breaking Schwifty has periodically removed support for older Python versions. Python 3.9 was dropped in v2026.01.0, and Python 3.8 in v2024.11.0. The library currently requires Python 3.10 or newer.
- gotcha When integrating Schwifty's IBAN/BIC types with Pydantic, strict validation is enabled by default. To allow more lax validation (e.g., ignoring whitespace or formatting differences), the field must be explicitly annotated with `Field(strict=False)`.
- breaking The base exception class for all validation failures changed from `ValueError` to `SchwiftyException` (which subclasses `ValueError`) in version 2021.01.0. While catching `ValueError` will still work, direct catches of `ValueError` might be too broad. `SchwiftyException` offers more specific error subclasses for granular handling.
- gotcha Prior to version 2025.09.0, the Polish IBAN format override could lead to unusual bank code breakdowns when generating IBANs from individual components. This could result in incorrectly structured IBANs if not thoroughly validated.
Install
-
pip install schwifty -
pip install "schwifty[pydantic]"
Imports
- IBAN
from schwifty import IBAN
- BIC
from schwifty import BIC
Quickstart
from schwifty import IBAN, BIC
# Validate and parse an IBAN
try:
iban = IBAN('DE89 3704 0044 0532 0130 00')
print(f"IBAN: {iban.formatted}")
print(f"Country Code: {iban.country_code}")
print(f"Bank Code: {iban.bank_code}")
print(f"Account Code: {iban.account_code}")
print(f"BIC (if available): {iban.bic}")
except ValueError as e:
print(f"Invalid IBAN: {e}")
# Generate an IBAN
generated_iban = IBAN.generate('GB', bank_code='040004', account_code='34340004')
print(f"Generated IBAN: {generated_iban.formatted}")
# Create and validate a BIC
try:
bic = BIC('COBADEFFXXX')
print(f"BIC: {bic.formatted}")
print(f"Country Code: {bic.country_code}")
except ValueError as e:
print(f"Invalid BIC: {e}")