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.

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

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.1.0.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

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

ccparser-0.1.0-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file ccparser-0.1.0.tar.gz.

File metadata

  • Download URL: ccparser-0.1.0.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for ccparser-0.1.0.tar.gz
Algorithm Hash digest
SHA256 33a41db421e7384345cd708dfcde9351f9c1d16b687f1e135f7cf8be801c0b10
MD5 1813747604fdef8e559b98f62bfc3794
BLAKE2b-256 5dafb2bdc9265798adcaf611bc47c7e3ab6dfddb5afd466b6bb65261a6e0b5ec

See more details on using hashes here.

File details

Details for the file ccparser-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: ccparser-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for ccparser-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8e7fdb9a0e15112e59a56681b60487b0f0fee5ad45aa6e395f5f75b56a7bfc01
MD5 b716b6d03bb5a4d3864e7b32667f9d2f
BLAKE2b-256 3b8b12131fce0d67abdf0448dba5532ca6672b138b203da5770a4e6ec69fef62

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