Skip to main content

fast-luhn

Luhn-algorithm. Generate and validate strings of numbers. It is used for account number validation, credit card validation, data verification, cryptography, decoding, etcetera. Rust realization for speed-up python code. Thread-safe. See benchmark for details.

Author:

Matt Stroganov

Version:

0.1.5

Installation

Install with pip:

$ pip install fast-luhn

Usage

Import package:

>>> import fast_luhn as fl

Validate

Check if string is valid by luhn algorithm. Return bool.

>>> fl.validate("471629309440")
False

Digit

Calculate next digit for string of numbers. Return int.

>>> fl.digit("47162930944")
7

Complete

Add luhn-check digit to string of numbers. Return string.

>>> fl.complete("2398560146")
'23985601469'

Generate

Generate luhn-valid string of numbers with length. Return string.

>>> fl.generate(50)
'58126333877729238938910323395262199130041545367401'

Build

Install from sources:

$ git clone https://github.com/cybermatt/fast-luhn
$ cd fast-luhn
$ pip install -r requirements-dev.txt
$ python ./setup.py develop

Benchmark

Pure python realization (from here) was very slow.

Comparison with popular python Luhn modules:

method lib

luhn

LAP

fast-luhn

validate

4.65 µs

13.3 µs

0.2 µs

generate

48.1 µs

94.4 µs

3.17 µs

Environment:

  • CPU i5-6500 3.20GHz, 16gb RAM

  • Linux 4.19

  • Python 3.7.3

Tests

$ pytest -v tests.py

License

This project is licensed under the MIT License - see the LICENSE.txt file for details

Metadata

Release files for fast-luhn 0.1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for fast-luhn 0.1.5
File
fast_luhn-0.1.5-cp39-cp39-manylinux2014_x86_64.whl CPython 3.9 CPython 3.9 Linux glibc 2.17+ x86-64 Details
fast_luhn-0.1.5-cp38-cp38-manylinux2014_x86_64.whl CPython 3.8 CPython 3.8 Linux glibc 2.17+ x86-64 Details
fast_luhn-0.1.5-cp37-cp37m-manylinux2014_x86_64.whl CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.17+ x86-64 Details
fast_luhn-0.1.5-cp36-cp36m-manylinux2014_x86_64.whl CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.17+ x86-64 Details
fast_luhn-0.1.5-cp35-cp35m-manylinux2014_x86_64.whl CPython 3.5 CPython 3.5 pymalloc Linux glibc 2.17+ x86-64 Details

Total release size: 3.2 MB

Release files / fast_luhn-0.1.5-cp39-cp39-manylinux2014_x86_64.whl

Download URL fast_luhn-0.1.5-cp39-cp39-manylinux2014_x86_64.whl
Size 1.1 MB
Tags CPython 3.9 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
b58be3816ee851b3845535caa2af51071a381cb02d099c24f83d52218105f179
BLAKE2b-256 checksum
How to use checksums
bac29baf17a042bdeada3224129e67ee3fdf48790eab41092f9d97fbf6b6212f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.8.6

Release files / fast_luhn-0.1.5-cp38-cp38-manylinux2014_x86_64.whl

Download URL fast_luhn-0.1.5-cp38-cp38-manylinux2014_x86_64.whl
Size 848.5 kB
Tags CPython 3.8 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
1008ebac277babb4fdf0b4fe38946f58caa754453759c235ee96aaf77b320ea4
BLAKE2b-256 checksum
How to use checksums
315313d7345077276f46b485a4724083c568086504d7f39dac456521f9101ef8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.8.6

Release files / fast_luhn-0.1.5-cp37-cp37m-manylinux2014_x86_64.whl

Download URL fast_luhn-0.1.5-cp37-cp37m-manylinux2014_x86_64.whl
Size 637.5 kB
Tags CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
de54483db117743b74901ea06229cbf4e47c853e940add9fcc7d241ad7f8bd8c
BLAKE2b-256 checksum
How to use checksums
4d770bab6d3ef11d89300a4ec3c9cf854f3a45535cf5caaaabde10cea704c317
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.8.6

Release files / fast_luhn-0.1.5-cp36-cp36m-manylinux2014_x86_64.whl

Download URL fast_luhn-0.1.5-cp36-cp36m-manylinux2014_x86_64.whl
Size 426.5 kB
Tags CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
f0a8cfda573b01bd1fee21c4828861af03e21b1dc71cb6dda9e11cda1d1d8da0
BLAKE2b-256 checksum
How to use checksums
ef2b338040c64fbdc892b2b9ec90c0059c168d66e8f3a2b410b5dc3ba2241b63
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.8.6

Release files / fast_luhn-0.1.5-cp35-cp35m-manylinux2014_x86_64.whl

Download URL fast_luhn-0.1.5-cp35-cp35m-manylinux2014_x86_64.whl
Size 215.2 kB
Tags CPython 3.5 CPython 3.5 pymalloc Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
c2029459ac42149767d42e14ec96979259be62976e82889b8e14e5b6f14be43d
BLAKE2b-256 checksum
How to use checksums
dfd80354494db5cf34b1078aa8535dcaa1b860eba5ec27a92fdca645cf04368f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.8.6

Release history Release notifications | RSS feed

This release

0.1.5 This release

5 release files

0.1.3

5 release files

0.1.2

5 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page