Skip to main content

Credit card BIN validation using bin-cc data

Project description

Credit Card Identifier - Python Library

Python library for credit card BIN validation and identification.

Supported Card Brands

  • American Express (amex)
  • Aura
  • BaneseCard
  • Diners Club
  • Discover
  • Elo
  • Hipercard
  • JCB
  • Maestro
  • Mastercard
  • UnionPay
  • Visa

Installation

pip install creditcard-identifier

Usage

Module Functions

from 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)  # True

Using the Validator Class

from 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)  # True

API

Module Functions

find_brand(card_number, detailed=False)

Identify the credit card brand.

Parameters:

  • card_number (str): The credit card number
  • detailed (bool): If True, returns detailed brand info (default: False)

Returns: (dict) Brand dict or None if not found

is_supported(card_number)

Check if the card number is supported.

Parameters:

  • card_number (str): The credit card number

Returns: (bool) True if supported, False otherwise

CreditCardValidator Class

__init__()

Initialize validator with embedded brand data.

find_brand(card_number, detailed=False)

Identify the credit card brand.

Parameters:

  • card_number (str): The credit card number
  • detailed (bool): If True, returns detailed brand info with matched pattern

Returns: (dict) Brand dict or None if not found

is_supported(card_number)

Check if card number is supported.

Parameters:

  • card_number (str): The credit card number

Returns: (bool) True if supported, False otherwise

validate_cvv(cvv, brand_or_name)

Validate CVV for a specific brand.

Parameters:

  • cvv (str): CVV code
  • brand_or_name (str | dict): Brand name or brand dict from find_brand

Returns: (bool) True if valid, False otherwise

get_brand_info(brand_name)

Get information about a specific brand.

Parameters:

  • brand_name (str): Brand name

Returns: (dict) Brand information or None if not found

get_brand_info_detailed(scheme)

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_brands()

List all supported brands.

Returns: (list) List of brand names

luhn(number)

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

Data Source

This library uses the BIN data from the bin-cc project.

The data is embedded directly in the package for optimal performance.

Development

Install in Development Mode

cd libs/python
pip install -e .

Run Tests

python -m pytest tests/

License

MIT

Project details


Download files

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

Source Distribution

creditcard_identifier-2.2.0.tar.gz (35.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

creditcard_identifier-2.2.0-py3-none-any.whl (34.7 kB view details)

Uploaded Python 3

File details

Details for the file creditcard_identifier-2.2.0.tar.gz.

File metadata

  • Download URL: creditcard_identifier-2.2.0.tar.gz
  • Upload date:
  • Size: 35.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for creditcard_identifier-2.2.0.tar.gz
Algorithm Hash digest
SHA256 fd591e7ef3bcc6f276dbdb55751cf869147e284dd696be4f3562fe087207947e
MD5 5fa53ffd7d3c13a88aadd1e2a19c1f1e
BLAKE2b-256 ab15764b6c0fd4debad414c4cc62b67cb7c1d44ff0756462e78f3843d8a07c6e

See more details on using hashes here.

Provenance

The following attestation bundles were made for creditcard_identifier-2.2.0.tar.gz:

Publisher: release.yml on renatovico/bin-cc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file creditcard_identifier-2.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for creditcard_identifier-2.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f4d9bca653f5fb9b0604ffa7af26babc012d07d042a867633226efc698876a53
MD5 3d3c17be96425c681f14833f7cd5663b
BLAKE2b-256 39774ac2c7d57769f66e0d11150da1c785eb688803c770695a4e7de7807d7537

See more details on using hashes here.

Provenance

The following attestation bundles were made for creditcard_identifier-2.2.0-py3-none-any.whl:

Publisher: release.yml on renatovico/bin-cc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page