Skip to main content
# 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

Metadata

Release files for ircards 1.4.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ircards 1.4.4
File Size Uploaded Provenance
ircards-1.4.4.tar.gz 5.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for ircards 1.4.4
File Interpreter ABI Platform
ircards-1.4.4-py3-none-any.whl Python 3 none any Details

Total release size: 12.1 kB

Release files / ircards-1.4.4.tar.gz

Download URL ircards-1.4.4.tar.gz
Size 5.7 kB
Tags Source
SHA-256 checksum
How to use checksums
820dc9b495e73f27574cf6b5b9f27e1d5464caaa7a14f8c68fab826d787fe757
BLAKE2b-256 checksum
How to use checksums
c8840bd34bf6a58437b8e0a3ff59bcde174aa4870f6acfc47079ef76c75713a2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Release files / ircards-1.4.4-py3-none-any.whl

Download URL ircards-1.4.4-py3-none-any.whl
Size 6.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4a958f992df7a16af9a4a76045445d167f5e8612bae2db0b4b7f8cc224f0ff01
BLAKE2b-256 checksum
How to use checksums
be33afaefda009339e633cf8b5926d2a99a93a5951792faeb486c5bbe94a852f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Security for ircards 1.4.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page