checkdigit: Check Digit Library for Data Validation

0.5.0 · active · verified Thu Apr 09

checkdigit is a Python library providing algorithms for various check digit standards, facilitating data validation and error detection. It supports algorithms like Luhn, ISBN, UPC, EAN, ISIN, Modulo 10, Modulo 11, GS1, and CRC. The current version is 0.5.0, with releases occurring periodically to introduce new features, fix bugs, and refine existing algorithms.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to import and use the `luhn` and `isbn` modules to validate and generate check digits. The `isbn` module automatically handles both ISBN-10 and ISBN-13 formats.

from checkdigit import luhn
from checkdigit import isbn

# Validate a number using the Luhn algorithm
is_valid_luhn = luhn.validate("79927398713")
print(f"'79927398713' is valid Luhn: {is_valid_luhn}")

# Generate a check digit for a number
luhn_with_check = luhn.generate("7992739871")
print(f"'7992739871' with Luhn check digit: {luhn_with_check}")

# Validate an ISBN (supports both ISBN-10 and ISBN-13)
is_valid_isbn = isbn.validate("978-3-16-148410-0")
print(f"'978-3-16-148410-0' is valid ISBN: {is_valid_isbn}")

view raw JSON →