Python library for credit card BIN validation and identification.
- American Express (amex)
- Aura
- BaneseCard
- Diners Club
- Discover
- Elo
- Hipercard
- JCB
- Maestro
- Mastercard
- UnionPay
- Visa
pip install creditcard-identifierfrom creditcard_identifier import find_brand, is_supported
# Identify card brand
brand = find_brand('4012001037141112')
print(brand) # {'name': 'visa', 'regexp_bin': '...', ...}
# Check if card is supported
supported = is_supported('4012001037141112')
print(supported) # Truefrom creditcard_identifier import CreditCardValidator
validator = CreditCardValidator()
# Identify brand
brand = validator.find_brand('4012001037141112')
print(brand['name']) # 'visa'
# Get detailed brand info
detailed = validator.find_brand('4012001037141112', detailed=True)
print(detailed['scheme']) # 'visa'
print(detailed['matched_pattern']) # {'bin': '^4', 'length': [13, 16, 19], ...}
# Check if supported
supported = validator.is_supported('4012001037141112')
print(supported) # True
# Validate CVV
valid = validator.validate_cvv('123', 'visa')
print(valid) # True
# Get brand info
info = validator.get_brand_info('visa')
print(info['regexp_bin'])
# Get detailed brand info
detailed = validator.get_brand_info_detailed('amex')
print(detailed)
# List all brands
brands = validator.list_brands()
print(brands)
# ['amex', 'aura', 'banesecard', 'diners', 'discover', 'elo', 'hipercard', 'jcb', 'maestro', 'mastercard', 'unionpay', 'visa']
# Validate card number using Luhn algorithm
from creditcard_identifier.validator import luhn
is_valid = luhn('4012001037141112')
print(is_valid) # True
# Or using validator instance
is_valid = validator.luhn('4012001037141112')
print(is_valid) # TrueIdentify the credit card brand.
Parameters:
card_number(str): The credit card numberdetailed(bool): If True, returns detailed brand info (default: False)
Returns: (dict) Brand dict or None if not found
Check if the card number is supported.
Parameters:
card_number(str): The credit card number
Returns: (bool) True if supported, False otherwise
Initialize validator with embedded brand data.
Identify the credit card brand.
Parameters:
card_number(str): The credit card numberdetailed(bool): If True, returns detailed brand info with matched pattern
Returns: (dict) Brand dict or None if not found
Check if card number is supported.
Parameters:
card_number(str): The credit card number
Returns: (bool) True if supported, False otherwise
Validate CVV for a specific brand.
Parameters:
cvv(str): CVV codebrand_or_name(str | dict): Brand name or brand dict from find_brand
Returns: (bool) True if valid, False otherwise
Get information about a specific brand.
Parameters:
brand_name(str): Brand name
Returns: (dict) Brand information or None if not found
Get detailed information about a specific brand.
Parameters:
scheme(str): Scheme name (e.g., 'visa', 'mastercard')
Returns: (dict) Detailed brand information or None if not found
List all supported brands.
Returns: (list) List of brand names
Validate a credit card number using the Luhn algorithm.
Parameters:
number(str): Credit card number (digits only)
Returns: (bool) True if valid according to Luhn algorithm
Raises: TypeError if input is not a string
This library uses the BIN data from the bin-cc project.
The data is embedded directly in the package for optimal performance.
cd libs/python
pip install -e .python -m pytest tests/MIT