skip to navigation
skip to content

scrypt 0.8.6

Bindings for the scrypt key derivation function library

Python scrypt bindings

This github is a clone of Please add issues and Pull-requests there.

This is a set of Python bindings for the scrypt key derivation function.

Scrypt is useful when encrypting password as it is possible to specify a minimum amount of time to use when encrypting and decrypting. If, for example, a password takes 0.05 seconds to verify, a user won’t notice the slight delay when signing in, but doing a brute force search of several billion passwords will take a considerable amount of time. This is in contrast to more traditional hash functions such as MD5 or the SHA family which can be implemented extremely fast on cheap hardware.


For Debian and Ubuntu, please ensure that the following packages are installed:

$ sudo apt-get install build-essential libssl-dev python-dev

For Fedora and RHEL-derivatives, please ensure that the following packages are installed:

$ sudo yum install gcc openssl-devel python-devel

For OSX, please do the following:

$ brew install openssl
$ export CFLAGS="-I$(brew --prefix openssl)/include $CFLAGS"
$ export LDFLAGS="-L$(brew --prefix openssl)/lib $LDFLAGS"

For OSX, you can also use the precompiled wheels. They are installed by:

$ pip install scrypt

For Windows, please use the precompiled wheels. They are installed by:

$ pip install scrypt

You can install py-scrypt from this repository if you want the latest but possibly non-compiling version:

$ hg clone
$ cd py-scrypt
$ python build

Become superuser (or use virtualenv):
# python install

Run tests after install:
$ python test

Or you can install the latest release from PyPi:

$ pip install scrypt

Users of the Anaconda Python distribution can directly obtain pre-built Windows, Intel Linux or macOS / OSX binaries from the conda-forge channel. This can be done via:

$ conda install -c conda-forge scrypt

If you want py-scrypt for your Python 3 environment, just run the above commands with your Python 3 interpreter. Py-scrypt supports both Python 2 and 3.

From version 0.6.0 (not available on PyPi yet), py-scrypt supports PyPy as well.



  • fixed
  • moved into own scrypt directory with
  • openssl library path for osx wheel repaired


  • __version__ added to scrypt
  • missing void in sha256.c fixed


  • scrypt updated to 1.2.1
  • Wheels are created for python 3.6


Fore encryption/decryption, the library exports two functions encrypt and decrypt:

>>> import scrypt
>>> data = scrypt.encrypt('a secret message', 'password', maxtime=0.1) # This will take at least 0.1 seconds
>>> data[:20]
>>> scrypt.decrypt(data, 'password', maxtime=0.1) # This will also take at least 0.1 seconds
'a secret message'
>>> scrypt.decrypt(data, 'password', maxtime=0.05) # scrypt won't be able to decrypt this data fast enough
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
scrypt.error: decrypting file would take too long
>>> scrypt.decrypt(data, 'wrong password', maxtime=0.1) # scrypt will throw an exception if the password is incorrect
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
scrypt.error: password is incorrect

From these, one can make a simple password verifier using the following functions:

def hash_password(password, maxtime=0.5, datalength=64):
    return scrypt.encrypt(os.urandom(datalength), password, maxtime=maxtime)

def verify_password(hashed_password, guessed_password, maxtime=0.5):
        scrypt.decrypt(hashed_password, guessed_password, maxtime)
        return True
    except scrypt.error:
        return False

But, if you want output that is deterministic and constant in size, you can use the hash function:

>>> import scrypt
>>> h1 = scrypt.hash('password', 'random salt')
>>> len(h1)  # The hash will be 64 bytes by default, but is overridable.
>>> h1[:10]
>>> h2 = scrypt.hash('password', 'random salt')
>>> h1 == h2 # The hash function is deterministic


scrypt-python was created by Magnus Hallin and is licensed as 2-clause BSD.

Scrypt was created by Colin Percival and is licensed as 2-clause BSD. Since scrypt does not normally build as a shared library, I have included the source for the currently latest version of the library in this repository. When a new version arrives, I will update these sources.

Kelvin Wong on Bitbucket provided changes to make the library available on Mac OS X 10.6 and earlier, as well as changes to make the library work more like the command-line version of scrypt by default. Kelvin also contributed with the unit tests, lots of cross platform testing and work on the hash function.

Burstaholic on Bitbucket provided the necessary changes to make the library build on Windows.

The python-appveyor-demo repository for setting up automated Windows builds for a multitude of Python versions.


This library is licensed under the same license as scrypt; 2-clause BSD.

File Type Py Version Uploaded on Size
scrypt-0.8.6-cp27-cp27m-macosx_10_11_x86_64.whl (md5) Python Wheel cp27 2018-02-08 34KB
scrypt-0.8.6-cp27-cp27m-win32.whl (md5) Python Wheel cp27 2018-02-08 23KB
scrypt-0.8.6-cp27-cp27m-win_amd64.whl (md5) Python Wheel cp27 2018-02-08 26KB
scrypt-0.8.6-cp34-cp34m-win32.whl (md5) Python Wheel cp34 2018-02-08 23KB
scrypt-0.8.6-cp34-cp34m-win_amd64.whl (md5) Python Wheel cp34 2018-02-08 26KB
scrypt-0.8.6-cp35-cp35m-macosx_10_11_x86_64.whl (md5) Python Wheel cp35 2018-02-08 34KB
scrypt-0.8.6-cp35-cp35m-win32.whl (md5) Python Wheel cp35 2018-02-08 25KB
scrypt-0.8.6-cp35-cp35m-win_amd64.whl (md5) Python Wheel cp35 2018-02-08 29KB
scrypt-0.8.6-cp36-cp36m-macosx_10_12_x86_64.whl (md5) Python Wheel cp36 2018-02-08 34KB
scrypt-0.8.6-cp36-cp36m-win32.whl (md5) Python Wheel cp36 2018-02-08 25KB
scrypt-0.8.6-cp36-cp36m-win_amd64.whl (md5) Python Wheel cp36 2018-02-08 29KB
scrypt-0.8.6.tar.gz (md5) Source 2018-02-08 51KB