Skip to main content

Fast library to validate and generate check digits using the Luhn algorithm

Project description

Cyluhn

A simple, fast library for verifying and calculating Luhn check digits, as well as generating random serial numbers with valid Luhn check digits for testing.

Cyluhn is mostly a Cython port of the pure-Python luhn library, acheiving a boost in speed while still being easy to install with pip. Cyluhn is intended to reduce the amount of time needed to validate a large number of Luhn-validated numbers such as credit card numbers or IMEIs during batch processing.

Compatible with Python 2.7 and Python 3.

Installation

pip install cyluhn

Usage

Cyluhn module

import cyluhn

cyluhn.generate_valid_luhn_str(ndigits=15)
# '136260325312871'

cyluhn.verify('136260325312871')
# True

cyluhn.get_check_digit('13626032531287')
# 1

cyluhn.append_check_digit('13626032531287')
# '136260325312871'

cyluhn-generate Command-Line Utility

cyluhn-generate -h
usage: cyluhn-generate [-h] -d NDIGITS -n NSERIALS

Generate serial numbers with valid Luhn check digit

optional arguments:
  -h, --help            show this help message and exit
  -d NDIGITS, --ndigits NDIGITS
                        Number of digits in each generated serial number
  -n NSERIALS, --nserials NSERIALS
                        Number of serial numbers to generate

Example:
cyluhn-generate -d 16 -n 10
7781801660482648
3204945043783442
6774339190776602
7715248262106681
7482722928054759
0435980693667196
6857863506381286
7743440795032247
8555647107058638
9772875170328167

Runtime comparisons with luhn

%timeit cyluhn.generate_valid_luhn_str(15)
638 ns ± 1.1 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)

%timeit luhn.append(''.join(random.choices('0123456789', k=14)))
6.48 µs ± 15.8 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)
---
%timeit cyluhn.verify('136260325312871')
192 ns ± 0.122 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)

%timeit luhn.verify('136260325312871')
3.26 µs ± 18.2 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)
---
%timeit cyluhn.get_check_digit('13626032531287')
220 ns ± 1.1 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)

%timeit luhn.generate('13626032531287')
3.34 µs ± 13.7 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)
---
%timeit cyluhn.append_check_digit('13626032531287')
367 ns ± 1.01 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)

%timeit luhn.append('13626032531287')
3.62 µs ± 15.6 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cyluhn-0.2.1.tar.gz (4.7 kB view hashes)

Uploaded Source

Built Distributions

cyluhn-0.2.1-cp313-cp313-win_amd64.whl (30.1 kB view hashes)

Uploaded CPython 3.13 Windows x86-64

cyluhn-0.2.1-cp313-cp313-win32.whl (27.1 kB view hashes)

Uploaded CPython 3.13 Windows x86

cyluhn-0.2.1-cp313-cp313-musllinux_1_2_x86_64.whl (183.8 kB view hashes)

Uploaded CPython 3.13 musllinux: musl 1.2+ x86-64

cyluhn-0.2.1-cp313-cp313-musllinux_1_2_i686.whl (183.9 kB view hashes)

Uploaded CPython 3.13 musllinux: musl 1.2+ i686

cyluhn-0.2.1-cp313-cp313-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (185.6 kB view hashes)

Uploaded CPython 3.13 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

cyluhn-0.2.1-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (177.6 kB view hashes)

Uploaded CPython 3.13 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

cyluhn-0.2.1-cp313-cp313-macosx_11_0_arm64.whl (30.4 kB view hashes)

Uploaded CPython 3.13 macOS 11.0+ ARM64

cyluhn-0.2.1-cp313-cp313-macosx_10_13_x86_64.whl (31.0 kB view hashes)

Uploaded CPython 3.13 macOS 10.13+ x86-64

cyluhn-0.2.1-cp312-cp312-win_amd64.whl (30.3 kB view hashes)

Uploaded CPython 3.12 Windows x86-64

cyluhn-0.2.1-cp312-cp312-win32.whl (27.1 kB view hashes)

Uploaded CPython 3.12 Windows x86

cyluhn-0.2.1-cp312-cp312-musllinux_1_1_x86_64.whl (194.2 kB view hashes)

Uploaded CPython 3.12 musllinux: musl 1.1+ x86-64

cyluhn-0.2.1-cp312-cp312-musllinux_1_1_i686.whl (186.3 kB view hashes)

Uploaded CPython 3.12 musllinux: musl 1.1+ i686

cyluhn-0.2.1-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (194.0 kB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

cyluhn-0.2.1-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (186.1 kB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

cyluhn-0.2.1-cp312-cp312-macosx_10_9_x86_64.whl (31.0 kB view hashes)

Uploaded CPython 3.12 macOS 10.9+ x86-64

cyluhn-0.2.1-cp311-cp311-win_amd64.whl (21.7 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

cyluhn-0.2.1-cp311-cp311-win32.whl (20.1 kB view hashes)

Uploaded CPython 3.11 Windows x86

cyluhn-0.2.1-cp311-cp311-musllinux_1_1_x86_64.whl (114.5 kB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.1+ x86-64

cyluhn-0.2.1-cp311-cp311-musllinux_1_1_i686.whl (112.0 kB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.1+ i686

cyluhn-0.2.1-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (111.1 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

cyluhn-0.2.1-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (106.6 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

cyluhn-0.2.1-cp311-cp311-macosx_10_9_x86_64.whl (23.6 kB view hashes)

Uploaded CPython 3.11 macOS 10.9+ x86-64

cyluhn-0.2.1-cp310-cp310-win_amd64.whl (22.5 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

cyluhn-0.2.1-cp310-cp310-win32.whl (20.9 kB view hashes)

Uploaded CPython 3.10 Windows x86

cyluhn-0.2.1-cp310-cp310-musllinux_1_1_x86_64.whl (112.6 kB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

cyluhn-0.2.1-cp310-cp310-musllinux_1_1_i686.whl (111.1 kB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ i686

cyluhn-0.2.1-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (108.3 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

cyluhn-0.2.1-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (106.5 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

cyluhn-0.2.1-cp310-cp310-macosx_10_9_x86_64.whl (24.5 kB view hashes)

Uploaded CPython 3.10 macOS 10.9+ x86-64

cyluhn-0.2.1-cp39-cp39-win_amd64.whl (23.3 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

cyluhn-0.2.1-cp39-cp39-win32.whl (21.3 kB view hashes)

Uploaded CPython 3.9 Windows x86

cyluhn-0.2.1-cp39-cp39-musllinux_1_1_x86_64.whl (117.9 kB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

cyluhn-0.2.1-cp39-cp39-musllinux_1_1_i686.whl (115.9 kB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ i686

cyluhn-0.2.1-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (114.7 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

cyluhn-0.2.1-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (112.3 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

cyluhn-0.2.1-cp39-cp39-macosx_10_9_x86_64.whl (24.7 kB view hashes)

Uploaded CPython 3.9 macOS 10.9+ x86-64

cyluhn-0.2.1-cp38-cp38-win_amd64.whl (23.3 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

cyluhn-0.2.1-cp38-cp38-win32.whl (21.4 kB view hashes)

Uploaded CPython 3.8 Windows x86

cyluhn-0.2.1-cp38-cp38-musllinux_1_1_x86_64.whl (125.5 kB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ x86-64

cyluhn-0.2.1-cp38-cp38-musllinux_1_1_i686.whl (124.4 kB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ i686

cyluhn-0.2.1-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (118.9 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

cyluhn-0.2.1-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (116.6 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

cyluhn-0.2.1-cp38-cp38-macosx_10_9_x86_64.whl (24.0 kB view hashes)

Uploaded CPython 3.8 macOS 10.9+ x86-64

cyluhn-0.2.1-cp37-cp37m-win_amd64.whl (23.0 kB view hashes)

Uploaded CPython 3.7m Windows x86-64

cyluhn-0.2.1-cp37-cp37m-win32.whl (21.0 kB view hashes)

Uploaded CPython 3.7m Windows x86

cyluhn-0.2.1-cp37-cp37m-musllinux_1_1_x86_64.whl (111.6 kB view hashes)

Uploaded CPython 3.7m musllinux: musl 1.1+ x86-64

cyluhn-0.2.1-cp37-cp37m-musllinux_1_1_i686.whl (111.7 kB view hashes)

Uploaded CPython 3.7m musllinux: musl 1.1+ i686

cyluhn-0.2.1-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (108.6 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

cyluhn-0.2.1-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (107.8 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

cyluhn-0.2.1-cp37-cp37m-macosx_10_9_x86_64.whl (23.7 kB view hashes)

Uploaded CPython 3.7m macOS 10.9+ x86-64

cyluhn-0.2.1-cp36-cp36m-win_amd64.whl (25.6 kB view hashes)

Uploaded CPython 3.6m Windows x86-64

cyluhn-0.2.1-cp36-cp36m-win32.whl (22.5 kB view hashes)

Uploaded CPython 3.6m Windows x86

cyluhn-0.2.1-cp36-cp36m-musllinux_1_1_x86_64.whl (108.8 kB view hashes)

Uploaded CPython 3.6m musllinux: musl 1.1+ x86-64

cyluhn-0.2.1-cp36-cp36m-musllinux_1_1_i686.whl (108.9 kB view hashes)

Uploaded CPython 3.6m musllinux: musl 1.1+ i686

cyluhn-0.2.1-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (106.2 kB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

cyluhn-0.2.1-cp36-cp36m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (105.2 kB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

cyluhn-0.2.1-cp36-cp36m-macosx_10_9_x86_64.whl (23.6 kB view hashes)

Uploaded CPython 3.6m macOS 10.9+ x86-64

cyluhn-0.2.1-cp35-cp35m-win_amd64.whl (25.1 kB view hashes)

Uploaded CPython 3.5m Windows x86-64

cyluhn-0.2.1-cp35-cp35m-win32.whl (21.9 kB view hashes)

Uploaded CPython 3.5m Windows x86

cyluhn-0.2.1-cp35-cp35m-manylinux2010_x86_64.whl (108.3 kB view hashes)

Uploaded CPython 3.5m manylinux: glibc 2.12+ x86-64

cyluhn-0.2.1-cp35-cp35m-manylinux2010_i686.whl (107.4 kB view hashes)

Uploaded CPython 3.5m manylinux: glibc 2.12+ i686

cyluhn-0.2.1-cp35-cp35m-manylinux1_x86_64.whl (108.3 kB view hashes)

Uploaded CPython 3.5m

cyluhn-0.2.1-cp35-cp35m-manylinux1_i686.whl (107.4 kB view hashes)

Uploaded CPython 3.5m

cyluhn-0.2.1-cp35-cp35m-macosx_10_9_x86_64.whl (22.8 kB view hashes)

Uploaded CPython 3.5m macOS 10.9+ x86-64

cyluhn-0.2.1-cp27-cp27mu-manylinux2010_x86_64.whl (91.1 kB view hashes)

Uploaded CPython 2.7mu manylinux: glibc 2.12+ x86-64

cyluhn-0.2.1-cp27-cp27mu-manylinux2010_i686.whl (90.5 kB view hashes)

Uploaded CPython 2.7mu manylinux: glibc 2.12+ i686

cyluhn-0.2.1-cp27-cp27mu-manylinux1_x86_64.whl (91.1 kB view hashes)

Uploaded CPython 2.7mu

cyluhn-0.2.1-cp27-cp27mu-manylinux1_i686.whl (90.5 kB view hashes)

Uploaded CPython 2.7mu

cyluhn-0.2.1-cp27-cp27m-win_amd64.whl (24.2 kB view hashes)

Uploaded CPython 2.7m Windows x86-64

cyluhn-0.2.1-cp27-cp27m-win32.whl (21.5 kB view hashes)

Uploaded CPython 2.7m Windows x86

cyluhn-0.2.1-cp27-cp27m-manylinux2010_x86_64.whl (91.1 kB view hashes)

Uploaded CPython 2.7m manylinux: glibc 2.12+ x86-64

cyluhn-0.2.1-cp27-cp27m-manylinux2010_i686.whl (90.5 kB view hashes)

Uploaded CPython 2.7m manylinux: glibc 2.12+ i686

cyluhn-0.2.1-cp27-cp27m-manylinux1_x86_64.whl (91.1 kB view hashes)

Uploaded CPython 2.7m

cyluhn-0.2.1-cp27-cp27m-manylinux1_i686.whl (90.5 kB view hashes)

Uploaded CPython 2.7m

cyluhn-0.2.1-cp27-cp27m-macosx_10_9_x86_64.whl (21.9 kB view hashes)

Uploaded CPython 2.7m macOS 10.9+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page