A Python package for checking card numbers validation and provider bank
Project description
# irCards
A Python package for validating Iranian bank cards and IBANs.
## Features
- **Card Validation**: Validate bank card numbers using Luhn algorithm
- **Bank Identification**: Identify the bank from card BIN (Bank Identification Number)
- **IBAN Validation**: Validate Iranian IBANs (International Bank Account Numbers)
- **Card Masking**: Securely mask card numbers for display
- **IBAN Masking**: Mask IBANs while preserving bank identifier and last 4 digits
- **CLI Interface**: Command-line interface for quick validation
## Installation
```bash
pip install irCards
Usage
Python API
Card Validation
from irCards import CardValidator
# Validate a card
card = CardValidator("6037991234567890")
info = card.get_info()
print(info)
# Output:
# {
# "card_number": "6037991234567890",
# "is_valid": True,
# "masked_card": "603799******7890",
# "length": 16,
# "bank": "بانک ملی ایران"
# }
IBAN Validation
from irCards import IbanValidator
# Validate an IBAN
iban = IbanValidator("IR820540102680020817909002")
info = iban.get_info()
print(info)
# Output:
# {
# "iban": "IR820540102680020817909002",
# "is_valid": True,
# "masked_iban": "IR**************9002",
# "length": 26
# }
CLI Usage
After installation, you can use the command-line interface:
# Validate a card
python -m irCards.cli card 6037991234567890
# Validate an IBAN
python -m irCards.cli iban IR820540102680020817909002
Example output:
card_number : 6037991234567890
is_valid : True
masked_card : 603799******7890
length : 16
bank : بانک ملی ایران
API Reference
CardValidator
Parameters
card_number(str|int): The card number to validate
Methods
| Method | Description |
|---|---|
get_info() |
Returns a dictionary with card information |
_validate_luhn() |
Internal method implementing Luhn algorithm |
_mask_number() |
Internal method for card number masking |
Return Values from get_info()
| Key | Description |
|---|---|
card_number |
The original card number |
is_valid |
Boolean indicating if card passes Luhn check |
masked_card |
Masked version (first 6, last 4 digits visible) |
length |
Length of the card number |
bank |
Bank name in Persian (or "Unknown") |
IbanValidator
Parameters
iban(str): The IBAN to validate
Methods
| Method | Description |
|---|---|
get_info() |
Returns a dictionary with IBAN information |
Return Values from get_info()
| Key | Description |
|---|---|
iban |
The original IBAN |
is_valid |
Boolean indicating if IBAN is valid |
masked_iban |
Masked version (preserves "IR" and last 4 digits) |
length |
Length of the IBAN |
Validation Rules
Card Validation
- Uses Luhn algorithm (mod 10 algorithm)
- Automatically removes any non-digit characters
- Identifies bank from the first 6 digits (BIN)
- Minimum length: 8 digits (for masking logic)
IBAN Validation
- Country code must be "IR" (Iran)
- Length must be exactly 26 characters
- Implements MOD 97 algorithm (ISO 7064)
- Removes spaces and converts to uppercase automatically
Supported Banks
The package includes BIN (Bank Identification Number) prefixes for all major Iranian banks including:
- بانک ملی ایران (603799)
- بانک ملت (610433)
- بانک صادرات (603769)
- بانک تجارت (585983)
- And more...
See banks_dict.py for the complete list.
Requirements
- Python 3.7+
Development
Setup for Development
# Clone the repository
git clone https://github.com/code-wizaard/irCards.git
cd irCards
# Install in development mode
pip install -e .
# Or with build tools
pip install build
python -m build
License
Licence is in the LICENCE file
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Author
2026 Copy right, Aydin Rahbran
Version History
- 1.0.0 - Initial release
- Card validation with Luhn algorithm
- IBAN validation for Iran
- Bank identification from BIN
- CLI interface
Notes
- Card numbers are validated only syntactically (Luhn algorithm), not against a live database
- Bank identification is based on known BIN prefixes and may not cover all banks
- Always use masked versions when displaying card numbers or IBANs in UI/logs
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ircards-1.4.4.tar.gz.
File metadata
- Download URL: ircards-1.4.4.tar.gz
- Upload date:
- Size: 5.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
820dc9b495e73f27574cf6b5b9f27e1d5464caaa7a14f8c68fab826d787fe757
|
|
| MD5 |
2c0c1ffcfba191b8b024f96dac5f49e7
|
|
| BLAKE2b-256 |
c8840bd34bf6a58437b8e0a3ff59bcde174aa4870f6acfc47079ef76c75713a2
|
File details
Details for the file ircards-1.4.4-py3-none-any.whl.
File metadata
- Download URL: ircards-1.4.4-py3-none-any.whl
- Upload date:
- Size: 6.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4a958f992df7a16af9a4a76045445d167f5e8612bae2db0b4b7f8cc224f0ff01
|
|
| MD5 |
7ccd967071cef834db50c15e77bf48bf
|
|
| BLAKE2b-256 |
be33afaefda009339e633cf8b5926d2a99a93a5951792faeb486c5bbe94a852f
|