Skip to main content

Validate/generate IBANs and BICs

Project description

Gotta get schwifty with your IBANs

Schwifty is a Python library for working with BICs and IBANs. It allows you to

  • validate check-digits and the country specific format of IBANs
  • validate format and country codes from BICs
  • generate BICs from bank-codes (works for Germany for now)
  • generate IBANs from country-code, bank-code and account-number.
  • access all relevant components as attributes


Since the mapping from BIC to bank_code is updated from time to time, Schwifty uses CalVer with the scheme YY.0M.Micro.



Let’s jump right into it:

>>> from schwifty import IBAN
>>> iban = IBAN('DE89 3704 0044 0532 0130 00')
>>> iban.compact
>>> iban.formatted
'DE89 3704 0044 0532 0130 00'
>>> iban.country_code
>>> iban.bank_code
>>> iban.account_code
>>> iban.length
>>> iban.bic

So far so good. So you are able to create an IBAN-object and to access all relevant components of the IBAN as properties. As you can see on the last line, you can also get hold of the BIC number associated to the bank-code of the IBAN. This currently only works for IBANs of german banks.

Behind the scenes the IBAN has been validated at the moment of instantiation. With respect to ISO 13616 compliance it is checked if the format of the account-code, the bank-code and possibly the branch-code have the correct country-specific format. Whenever you pass an invalid IBAN to the __init__-method, you’ll get a ValueError with an appropriate error message.

>>> IBAN('DX89 3704 0044 0532 0130 00')
ValueError: Unknown country-code DX

>>> IBAN('DE99 3704 0044 0532 0130 00')
ValueError: Invalid checksum digits

But what if you wan’t to generate an IBAN from a bank-code and the account-code? Use the generate-classmethod!

>>> iban = IBAN.generate('DE', bank_code='10010010', account_code='12345')
>>> iban.checksum_digits

Notice that even that the account-code has less digits than required (in Germany accounts should be 10 digits long), zeros have been added at the correct location. Additionally the checksum digits have been calculated, which is good.


Besides the IBAN there is the Business Identifier Code (BIC). It is a unique identification code for both financial and non-financial institutes. Schwifty also has a BIC-object which more or less has the same interface than the IBAN-object.

>>> from schwifty import BIC
>>> bic = BIC('PBNKDEFFXXX')
>>> bic.bank_code
>>> bic.branch_code
>>> bic.country_code
>>> bic.location_code
>>> bic.domestic_bank_codes

The domestic_bank_codes lists the country specific bank codes as you can find it in the IBAN. This mapping is currently only available for German BICs and some Spanish and British banks.

The BIC-object also does some basic validation on instantiation and raises a ValueError if the country-code, the BIC´s length is invalid or if the structure doesn’t match the ISO 9362 specification.

ValueError: Invalid country code DX
ValueError: Invalid length 12
ValueError: Invalid structure PBN1DXFFXXXX

If Schwifty´s internal registry contains the BICs for your country (this again currently only works for Germany), then you can use the exists-property to check that the BIC is registered.


To install Schwifty, simply:

$ pip install schwifty


We use the black as code formatter. This avoids discussions about style preferences in the same way as gofmt does the job for Golang. The conformance to the formatting rules is checked in the CI pipeline, so that it is recommendable to install the configured pre-commit-hook, in order to avoid long feedback-cycles.

$ pre-commit install

You can also use the fmt Makefile-target to format the code or use one of the available editor integrations.


Since swift and swiftly were already taken by the OpenStack-project, but we somehow wanted to point out the connection to SWIFT, Rick and Morty came up with the idea to name the project schwifty.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for schwifty, version 2020.5.3
Filename, size File type Python version Upload date Hashes
Filename, size schwifty-2020.5.3-py2.py3-none-any.whl (177.0 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size schwifty-2020.5.3.tar.gz (554.6 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page