Giter VIP home page Giter VIP logo

fast-luhn's Introduction

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

fast-luhn's People

Contributors

cybermatt avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.