Skip to main content

IBAN field for django with validation and optional postgresql in database constraint checking

Project description

Django iban field with validators and optional postgresql in base constraint checking. This is expected to work with django 1.8 and later.


Install django-iban-field like you would install any other pypi package:

pip install django-iban-field

Configuration and usage

  • add django_iban to the list of INSTALLED_APPS in your

  • use in

    from django_iban.fields import IBANField
    class MyModel(models.Model):
        iban = IBANField(enforce_database_constraint=True, unique=True)

The enable_databse_constraint option will add a function named is_valid_iban to your database and use it the enforce the database type checking. This option will have an effect only if you are using the postgreql backend and have the plpython extension enabled on your database.


Other than the django field, you will find a generator class to use if you want to generate valid IBAN values:

from django_iban.generator import IBANGenerator

generator = IBANGenerator()
# A complete random IBAN
valid_iban = generator.generate()
# But you can specify the country
valid_iban = generator.generate(country_code='DE')
# Or the bank and account
valid_iban = generator.generate(country_code='DE', bank=XXXX, account=XXXX)

You cannot of course just pass the bank and the account without the country, and if you pass one or both of these values will then check for their validity, compute the checksum and return the valid IBAN.

You may also be intereseted in the IBANSpecification class that contains all the format specification and the checksum facility:

from django_iban.specification import IBANSpecification
from django_iban.specification import IBAN_SPECIFICATION_CONFIG

country_specification = IBAN_SPECIFICATION_CONFIG['TN']
# 5


This module take it’s inspiration and some of the ideas from the django-localflavor IBanField and the specification from tom’s cafe


You can find a running example of this field in this demo django application, and if you are super lazy you can just get my vagrant bootstraper script that will setup a full working vm using that project. You just have to have vagrant and openssl installed (tested on Fedora but should work with any other modern linux or mac):

curl | bash

Project details

Release history Release notifications | RSS feed

This version


Download files

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

Source Distributions

No source distribution files available for this release. See tutorial on generating distribution archives.

Built Distribution

django_iban_field-0.8-py2.py3-none-any.whl (12.9 kB view hashes)

Uploaded any

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page