Skip to content

CCParser is a Python library for credit card parsing, validation, and formatting. It extracts card details, detects providers, validates with Luhn’s algorithm, supports multiple delimiters, and formats numbers as xxxx xxxx xxxx xxxx or masked **** **** **** 1234. πŸš€πŸ’³

License

Notifications You must be signed in to change notification settings

VihangaDev/CCParser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

17 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

CCParser - Powerful Credit Card Parsing & Validation Library

PyPI
License
Build Status

CCParser is a robust and efficient Python library designed for seamless credit card parsing, validation, and formatting. Whether you're extracting card details, validating numbers, or formatting them for display, CCParser makes the process effortless with its powerful features and intuitive API.


πŸš€ Features

  • πŸ” Smart Extraction: Extracts card number, expiry date (month/year), and CVV from a string.
  • πŸ“ Standardized Formatting: Converts card numbers into xxxx xxxx xxxx xxxx format.
  • βœ… Luhn Validation: Ensures card validity using the industry-standard Luhn algorithm.
  • πŸ—“οΈ Expiry & CVV Checks: Validates expiry date and CVV length based on card type.
  • πŸ’³ Card Type Detection: Identifies major card providers (Visa, MasterCard, AMEX, etc.).
  • πŸ”’ Masked Output Option: Returns a masked format (**** **** **** 5379).
  • πŸ”— Multiple Delimiters: Supports delimiters like |, :, and spaces.
  • πŸ“† Flexible Expiry Handling: Accepts expiry years in both YYYY and YY formats.
  • ⚑ Easy-to-Use API: Well-structured API for seamless integration.
  • πŸ–₯️ Command-Line Support: Provides a CLI tool for quick parsing.
  • πŸ“– Well-Documented: Extensive Markdown documentation (README.md).
  • πŸ“¦ PyPI Ready: Structured for easy PyPI distribution.
  • πŸ› οΈ CI/CD Integration: Uses GitHub Actions for automated testing.
  • πŸ†• Card Number Generation: Generate valid card numbers for testing purposes.
  • πŸ†• Additional Card Types: Supports JCB, Diners Club, and UnionPay.

πŸ’³ Supported Card Types

CCParser recognizes and validates multiple card providers:

  • Visa: ^4[0-9]{12}(?:[0-9]{3})?$
  • MasterCard: ^5[1-5][0-9]{14}$
  • American Express (AMEX): ^3[47][0-9]{13}$
  • Discover: ^6(?:011|5[0-9]{2})[0-9]{12}$
  • JCB: ^(?:2131|1800|35\d{3})\d{11}$
  • Diners Club: ^3(?:0[0-5]|[68][0-9])[0-9]{11}$
  • UnionPay: ^62[0-9]{14,17}$

πŸ“₯ Installation

Install CCParser using pip:

pip install ccparser

πŸ“ Usage Examples

Supported Card Formats

CCParser supports various card formats with different delimiters and expiry formats:

4111111111111111|12/30|123
4111111111111111|12|2030|123
4111111111111111|12|30|123
4111111111111111 12 2030 123
4111111111111111 12 30 123
4111111111111111:12:2030:123
4111111111111111:12:30:123

Python API

from ccparser import CCParser

card = CCParser("4111111111111111|12|2030|123")
print(card.get_number())  # 4111111111111111
print(card.get_formatted_number())  # 4111 1111 1111 1111
print(card.get_expiry())  # 12/30
print(card.get_cvv())  # 123
print(card.is_valid())  # True
print(card.get_card_type())  # Visa
print(card.get_masked_number())  # **** **** **** 1111
print(card.get_year())  # 2030
print(card.get_month())  # 12
print(card.get_card_details())  # Detailed card information

Card Number Generation

from ccparser.generator import generate_card_number

print(generate_card_number("Visa"))  # Generates a valid Visa card number
print(generate_card_number("MasterCard"))  # Generates a valid MasterCard number

CLI Tool

CCParser can also be used via the command line:

ccparser "4111111111111111|12|2030|123"

πŸ“œ License

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


🀝 Contributing

Contributions are welcome! Please review our CONTRIBUTING guidelines before submitting a pull request.


πŸ“š Acknowledgements


πŸ“§ Contact

For any inquiries or issues, feel free to reach out:

πŸ“© Vihanga Indusara - vihangadev@gmail.com


CCParser – Simplifying credit card parsing, one line at a time! πŸš€

About

CCParser is a Python library for credit card parsing, validation, and formatting. It extracts card details, detects providers, validates with Luhn’s algorithm, supports multiple delimiters, and formats numbers as xxxx xxxx xxxx xxxx or masked **** **** **** 1234. πŸš€πŸ’³

Topics

Resources

License

Stars

Watchers

Forks

Languages