luhnpy

A minimalistic implementation of Luhn algorithm


Keywords
luhn, algorithm
License
MIT
Install
pip install luhnpy==1.0.0

Documentation

Build Status license luhnpy release

Luhnpy

Luhnpy is a Luhn algorithm implementation written in Python.

Installation

pip install luhnpy

Examples

import luhnpy

# Create random valid luhn strings
print(luhnpy.rand()) # 4124796630572739
print(luhnpy.rand(length=5)) # 41285
print(luhnpy.rand(length=10)) # 4380357030

# Calculate luhn check digit
print(luhnpy.digit('412479663057273')) # 9

# Verify string of digits
print(luhnpy.verify('4124796630572739')) # True
print(luhnpy.verify('4039531371114851')) # False

#  Append the check digit to your string of digits
print(luhnpy.complete('412479663057273')) # 4124796630572739