Skip to main content

A library for credit card parsing, validation, and formatting

Project description

CCParser

PyPI License Build Status

CCParser is a powerful Python library designed for credit card parsing, validation, and formatting. It provides a comprehensive set of features to handle various credit card operations with ease.

Features

  • Card Number Extraction: Extracts card number, expiry month, expiry year, and CVV from a given string.
  • Standard Formatting: Formats the card number into a standard display format: xxxx xxxx xxxx xxxx.
  • Luhn Algorithm Validation: Uses the Luhn algorithm to check if a card number is valid.
  • Expiry Date and CVV Validation: Validates expiry dates and CVV length based on card type.
  • Card Provider Detection: Detects card providers such as Visa, MasterCard, AMEX, Discover, etc.
  • Masked Format Option: Option to return a masked format: **** **** **** 5379.
  • Multiple Delimiters: Accepts multiple delimiters like |, :, and spaces.
  • Flexible Expiry Year Handling: Handles expiry years in YYYY or YY format.
  • Easy-to-Use API: Provides an easy-to-use Python API.
  • CLI Tool: Can be used as a CLI tool for quick parsing.
  • Unit Tests: Includes pytest unit tests for all functions.
  • Markdown Documentation: Provides comprehensive Markdown documentation (README.md).
  • PyPI Ready: Structured for publishing on PyPI.
  • Easy Installation: Includes setup.py or pyproject.toml for easy installation.
  • CI/CD Testing: Uses GitHub Actions for CI/CD testing.
  • Get Expiry Year: Retrieves the expiry year of the card.
  • Get Expiry Month: Retrieves the expiry month of the card.
  • Get Card Details: Fetches detailed information about the card from an external API.

Supported Card Types

CCParser supports the following card types and formats:

  • 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

Example Usage

Here's a quick example of how to use CCParser in your Python code:

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

CLI Usage

CCParser can also be used as a command-line tool:

ccparser "4111111111111111|12|2030|123"

Running Tests

Run the unit tests using pytest:

pytest

Building Package

Build the package using the following command:

python setup.py sdist bdist_wheel

Publishing to PyPI

Publish the package to PyPI using Twine:

twine upload dist/*

License

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

Contributing

Contributions are welcome! Please read the CONTRIBUTING file for guidelines on how to contribute to this project.

Acknowledgements

Contact

For any inquiries or issues, please contact Vihanga Indusara.

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

CCParser-0.3.0.tar.gz (5.5 kB view details)

Uploaded Source

File details

Details for the file CCParser-0.3.0.tar.gz.

File metadata

  • Download URL: CCParser-0.3.0.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for CCParser-0.3.0.tar.gz
Algorithm Hash digest
SHA256 afb2aaa79b72acafe6a374237c0d092aa2f6fa81925e0933e8af8d892eb452b9
MD5 876ef707aa2c16d2efa76471d17ac923
BLAKE2b-256 dbb6b1cf805dfc21d096f3a051ec2655dc9a33f62d2ae76a753742b75d54e6f5

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