larzluhn
The Luhn checksum - validate card-shaped numbers.
Checks that a card-number-shaped string is WELL-FORMED (the real Luhn mod-10 algorithm), not that a card is real, active, or authorized - never treat a Luhn pass as proof of a valid payment method. check_digit() computes the digit that makes a partial number valid, the same way a real card issuer generates the last digit.
larzscript pkg install luhn
What you get
- The real Luhn mod-10 algorithm
- check_digit() - generates the valid final digit
- Well-formed ≠ real/active/authorized - checked honestly in the docs
- Strips spaces/dashes before checking
Try it
import "luhn" as luhn
print(luhn.is_valid("4111111111111111"))
print(luhn.is_valid("4111111111111112"))
print(luhn.check_digit("411111111111111"))Output
true false 1
Why it's in the Larz Stack
larzluhn is a real Larzscript package (larzscript pkg install luhn) - money-native, zero dependencies, the same language as the rest of the estate, not a separate Python runtime. It composes with the rest of the Larz Stack and the Larz framework.