Skip to main content

Python implementation for bank account validation.

Project description

Bank Account Validator

Python implementation for bank account validation.

Currently, the biggest Brazilian banks are implemented - and so being validated. There is no other countries’ banks implemented, but the code is modular and it can be done easily.


from bank_account_validator.core import Bank
bank_class = Bank.get('bank_code', 'country_code')
bank_class(branch='branch', branch_digit='branch_digit',
           account='account', account_digit='account_digit').execute()


from bank_account_validator.core import Bank, BrazilianBank

# Account below is correct, so nothing is raised by calling execute()
bank_class = Bank.get('237', 'BR')
bank_class(branch='1769', branch_digit='8', account='200040', account_digit='7').execute()

# Account below has invalid branch so InvalidBranch will be raised
bank_class = BrazilianBank.get('237')
bank_class(branch='1769', branch_digit='0', account='200040', account_digit='7').execute()
# InvalidBranch: Branch "1769-0" is wrong.

# Account below has invalid account so InvalidAccount will be raised
bank_class = BrazilianBank.get('237')
bank_class(branch='1769', branch_digit='8', account='200040', account_digit='0').execute()
# InvalidAccount: Account "0200040-0" is wrong.

# Sometimes there is not an unitary validation for both branch and account
# I mean, the full combination is evaluated at once.
bank_class = BrazilianBank.get('033')
bank_class(branch='2006', branch_digit='', account='01008407', account_digit='1').execute()
# InvalidBranchAndAccountCombination: Combination (branch="2006", account="01008407-1") does not match.

# It also validates wether digits must be supplied or not, as well as branch/account lengths
bank_class = BrazilianBank.get('237')
bank_class(branch='111769', branch_digit='8', account='200040', account_digit='7').execute()
# InvalidBranchlength: For bank code "237", branches length must be 4.

bank_class(branch='1769', branch_digit='8', account='11200040', account_digit='7').execute()
# InvalidAccountlength: For bank code "237", accounts length must be 7.

bank_class(branch='1769', branch_digit='', account='200040', account_digit='7').execute()
# MissingBranchDigit: For bank code "237", branches must have a digit, of length 1.

bank_class(branch='1769', branch_digit='11', account='200040', account_digit='7').execute()
# UnexpectedBranchDigit: For bank code "237", branches must have 1 digits.

bank_class(branch='1769', branch_digit='8', account='200040', account_digit='').execute()
# MissingAccountDigit: For bank code "237", accounts must have a digit, of length 1.

bank_class(branch='1769', branch_digit='8', account='200040', account_digit='11').execute()
# UnexpectedAccountDigit: For bank code "237", accounts must have 1 digits.


Did you think in some interesting feature, or have you found a bug? Please let me know!

Of course you can also download the project and send me some pull requests.

You can send your suggestions by opening issues.

You can contact me directly as well. Take a look at my contact information at (email is preferred rather than mobile phone).

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 bank-account-validator, version 0.2
Filename, size File type Python version Upload date Hashes
Filename, size bank_account_validator-0.2-py2.py3-none-any.whl (6.6 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size bank-account-validator-0.2.tar.gz (18.1 kB) File type Source Python version None Upload date Hashes View

Supported by

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