The `luhn` Python library, currently at version 0.2.0, provides a simple and lightweight implementation of the Luhn algorithm. It's designed to generate and verify Luhn check digits for identification numbers, commonly used for credit cards and other IDs to detect accidental errors. This version was released in 2015 and has a stable, albeit minimal, API.
pip install luhnVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to verify a number, generate a check digit, and append a check digit using the `luhn` library's primary functions.
Ensure input strings are stripped of any non-digit characters before passing them to `verify`, `generate`, or `append`. For example, `number_string.replace(' ', '').replace('-', '')`.For applications requiring higher security or more robust error detection, consider alternative or additional checksum algorithms, such as Verhoeff or Damm algorithms, or cryptographic hash functions.
While functional for basic Luhn operations, consider evaluating more recent alternatives like `luhncheck` if your project requires new features, active maintenance, or broader compatibility.
Pre-process the input string to remove any non-digit characters. Example: `cleaned_number = input_string.strip().replace(' ', '').replace('-', '')`.Convert the integer to a string before passing it to the `luhn` functions. Example: `verify(str(12345))`.
Review the specifications of the Luhn algorithm to understand its inherent strengths and weaknesses. If more robust error detection is needed, consider alternative checksums.
No dependency data recorded yet.