Skip to main content

A Python library for credit card validation using the Luhn algorithm

Project description

CardValidator

A Python library for credit card validation using the Luhn algorithm. Supports validation for Visa, MasterCard, American Express, Discover, and RuPay cards.

Features

  • Luhn Algorithm Validation: Industry-standard credit card validation.
  • Multiple Card Types: Supports Visa, MasterCard, AmEx, Discover, and RuPay.
  • Input Flexibility: Handles formatted input (spaces, hyphens).
  • Edge Case Handling: Rejects invalid patterns like all-identical digits.
  • Zero Dependencies: No external dependencies required.
  • Type Hints: Full type annotation support.
  • Comprehensive Tests: Well-tested with pytest.

Installation

pip install cardvalidator-lite

Or with UV:

uv add cardvalidator-lite

Quick Start

from cardvalidator import validate_card, is_valid_card, CardValidator

# Quick validation
result = validate_card("4111111111111111")
print(result)
# Output: {'card_number': '4111111111111111', 'valid': True, 'type': 'Visa', 'cleaned_number': '4111111111111111'}

# Simple boolean check
is_valid = is_valid_card("4111111111111111")
print(is_valid)  # Output: True

# Using the class directly
validator = CardValidator()
result = validator.validate("5105-1051-0510-5100")
print(result["type"])  # Output: MasterCard

Supported Card Types

Card Type Length Starts With Example
Visa 13, 16, 19 4 4111111111111111
MasterCard 16 51-55 5105105105105100
American Express 15 34, 37 378282246310005
Discover 16, 19 6011, 65, etc. 6011111111111117
RuPay 16 60, 65, 81 6037997040000000*

*Test numbers for development use only

API Reference

validate_card(card_number: str) -> dict

Validates a card number and returns detailed information.

Returns:

{
    "card_number": "4111111111111111",
    "valid": True,
    "type": "Visa",
    "cleaned_number": "4111111111111111"
}

is_valid_card(card_number: str) -> bool

Simple boolean validation.

CardValidator Class

For advanced usage with custom validation logic.

Development

Setup

# Clone the repository
git clone https://github.com/yourusername/cardvalidator.git
cd cardvalidator

# Install with UV
uv sync

# Install in development mode
uv pip install -e .

Running Tests

uv run pytest tests/ -v

Building

uv build

Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

  • Implements the Luhn Algorithm for credit card validation.
  • Supports Indian domestic payment network RuPay
  • Built with modern Python packaging standards using UV

Disclaimer

This library is for validation purposes only. Never store or transmit real credit card numbers in production applications without proper PCI DSS compliance.

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

cardvalidator_lite-0.1.1.tar.gz (12.2 kB view details)

Uploaded Source

Built Distribution

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

cardvalidator_lite-0.1.1-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file cardvalidator_lite-0.1.1.tar.gz.

File metadata

  • Download URL: cardvalidator_lite-0.1.1.tar.gz
  • Upload date:
  • Size: 12.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.13

File hashes

Hashes for cardvalidator_lite-0.1.1.tar.gz
Algorithm Hash digest
SHA256 0e6f7e8bb0a486691baadf99837bf03a1e3877cb8b6efd1ddacabaa20468b16e
MD5 68121ffe1405ae04bfbf147db5c37d3f
BLAKE2b-256 299283ab59eac22ab354ef77dfba6c8f4512234a8357a30aae7a78bec1f9be55

See more details on using hashes here.

File details

Details for the file cardvalidator_lite-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for cardvalidator_lite-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 abc8a32a14d8473f8d371c2b273e042b9fd6806cd5e94cda23c84ec66db8eda9
MD5 1577b29a244f901826bd8593304a77c8
BLAKE2b-256 3e85e31f633bcc6f5b6638295540713f031dde20aec6945dd461395f29d016a6

See more details on using hashes here.

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