https://github.com/code-127/luhn-formula-py
Another python package of number validator and check digit generator based on Luhn's formula 😉. Luhn's formula was designed to protect against accidental input errors.
https://github.com/code-127/luhn-formula-py
luhn luhn-algorithm python python3
Last synced: 20 days ago
JSON representation
Another python package of number validator and check digit generator based on Luhn's formula 😉. Luhn's formula was designed to protect against accidental input errors.
- Host: GitHub
- URL: https://github.com/code-127/luhn-formula-py
- Owner: code-127
- License: mit
- Created: 2022-06-04T19:32:19.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2025-12-24T09:57:46.000Z (4 months ago)
- Last Synced: 2025-12-25T23:11:52.401Z (4 months ago)
- Topics: luhn, luhn-algorithm, python, python3
- Language: Python
- Homepage:
- Size: 60.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# luhn-formula
Another python package of number validator and check digit generator based on Luhn's formula 😉. Luhn's formula was designed to protect against accidental input errors.



[](https://github.com/code-127/luhn-formula-py/actions/workflows/python-package.yml)
[](https://github.com/code-127/luhn-formula-py/actions/workflows/python-publish.yml)
[](https://www.python.org/downloads/release/python-3100/)
[](https://www.python.org/downloads/release/python-3110/)
[](https://www.python.org/downloads/release/python-3120/)
[](https://www.python.org/downloads/release/python-3130/)
[](https://www.python.org/downloads/release/python-3140/)
## Usage
### install
pip install luhn-formula
or
git clone git@github.com:code-127/luhn-formula-py.git
### Example
>>> from luhnformula import luhnformula as lf
>>> lf.getcheckdigit("12345")
'5'
>>> lf.addcheckdigit("12345")
'123455'
>>> lf.isvalid("123455")
True
## Function
### checksum(number: str) -> int
Checksum vith the luhn formula
Args:
number : Number to calculate
return:
Result of luhn formula
### isvalid(number: str) -> bool:
Validate number with the Luhn formula.
Args:
number: Number to validate.
Returns:
``True`` when the: number is valid, otherwise ``False``.
### getcheckdigit(number: str) -> str:
Generate check digit with the Luhn formula for a number.
Args:
number: Number used to generate the check digit.
Return:
the check digit for a number.
Raise error:
ValueError : Invalid number.
### addcheckdigit(number: str) -> str:
Generate and add check digit with the luhn formula for a number
Args:
number: Number used to generate the check digit.
Return:
the number with the check digit.
Raise error:
ValueError : Invalid number.