Skip to main content

This github is a clone of https://bitbucket.org/mhallin/py-scrypt. 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.

Installation

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

$ hg clone http://bitbucket.org/mhallin/py-scrypt
$ cd py-scrypt
$ python setup.py build

Become superuser (or use virtualenv):
# python setup.py install

Run tests after install:
$ python setup.py test

Or you can install the latest release from PyPi:

$ pip install 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.

Usage

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\x00\r\x00\x00\x00\x08\x00\x00\x00\x01RX9H'
>>> 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):
    try:
        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.
64
>>> h1[:10]
'\xfe\x87\xf3hS\tUo\xcd\xc8'
>>> h2 = scrypt.hash('password', 'random salt')
>>> h1 == h2 # The hash function is deterministic
True

Acknowledgements

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.

License

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

Badges

https://travis-ci.org/holgern/py-scrypt.svg?branch=master https://ci.appveyor.com/api/projects/status/h644bjbdawke9vf2?svg=true

Release files for scrypt 0.8.3

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

Source distribution (sdist)

Source distribution for scrypt 0.8.3
File Size Uploaded
scrypt-0.8.3.tar.gz 45.8 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for scrypt 0.8.3
File
scrypt-0.8.3.win-amd64-py3.6.exe Details
scrypt-0.8.3.win-amd64-py3.5.exe Details
scrypt-0.8.3.win-amd64-py3.4.exe Details
scrypt-0.8.3.win-amd64-py2.7.exe Details
scrypt-0.8.3.win32-py3.6.exe Details
scrypt-0.8.3.win32-py3.5.exe Details
scrypt-0.8.3.win32-py3.4.exe Details
scrypt-0.8.3.win32-py2.7.exe Details
scrypt-0.8.3-cp36-cp36m-win_amd64.whl CPython 3.6 CPython 3.6 pymalloc Windows x86-64 Details
scrypt-0.8.3-cp36-cp36m-win32.whl CPython 3.6 CPython 3.6 pymalloc Windows x86-32 Details
scrypt-0.8.3-cp36-cp36m-macosx_10_6_intel.whl CPython 3.6 CPython 3.6 pymalloc macOS 10.6+ Intel (x86-64, i386) Details
scrypt-0.8.3-cp35-cp35m-win_amd64.whl CPython 3.5 CPython 3.5 pymalloc Windows x86-64 Details
scrypt-0.8.3-cp35-cp35m-win32.whl CPython 3.5 CPython 3.5 pymalloc Windows x86-32 Details
scrypt-0.8.3-cp35-cp35m-macosx_10_6_intel.whl CPython 3.5 CPython 3.5 pymalloc macOS 10.6+ Intel (x86-64, i386) Details
scrypt-0.8.3-cp34-cp34m-win_amd64.whl CPython 3.4 CPython 3.4 pymalloc Windows x86-64 Details
scrypt-0.8.3-cp34-cp34m-win32.whl CPython 3.4 CPython 3.4 pymalloc Windows x86-32 Details
scrypt-0.8.3-cp27-cp27m-win_amd64.whl CPython 2.7 CPython 2.7 pymalloc Windows x86-64 Details
scrypt-0.8.3-cp27-cp27m-win32.whl CPython 2.7 CPython 2.7 pymalloc Windows x86-32 Details

Total release size: 3.5 MB

Release files / scrypt-0.8.3.tar.gz

Download URL scrypt-0.8.3.tar.gz
Size 45.8 kB
Tags Source
SHA-256 checksum
How to use checksums
24c68246049a955dd8f56d4aba70a66a6b752af228be12e6ae54b77df5a9dec0
BLAKE2b-256 checksum
How to use checksums
c95f64774eb27427710537b49ffc4a515d4ef66d4321c2833335859fe516512e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / scrypt-0.8.3.win-amd64-py3.6.exe

Download URL scrypt-0.8.3.win-amd64-py3.6.exe
Size 619.4 kB
Tags Source
SHA-256 checksum
How to use checksums
fb40189daecebd73eacbc67376991140e27c6e28e03197628fe68ff311856936
BLAKE2b-256 checksum
How to use checksums
1b96fbe58cd2f76ee27486c52f685de7e452520ec1a7a3665e003c3c5727c342
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / scrypt-0.8.3.win-amd64-py3.5.exe

Download URL scrypt-0.8.3.win-amd64-py3.5.exe
Size 619.4 kB
Tags Source
SHA-256 checksum
How to use checksums
bb2c1b8c30a36415a9ded306eb77acd7067045ab63b4cc3b917fedfe1e6c962b
BLAKE2b-256 checksum
How to use checksums
c05bb5b33c97ea90142ae551a530ef1540a526a7daaf50106fcdf8702f987cbd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / scrypt-0.8.3.win-amd64-py3.4.exe

Download URL scrypt-0.8.3.win-amd64-py3.4.exe
Size 251.3 kB
Tags Source
SHA-256 checksum
How to use checksums
df8f87b6afecae9c6559b25819cb11512b5bbb276ee0d413d353cf2e539079c2
BLAKE2b-256 checksum
How to use checksums
78f2946d558093ec8a6c25f73cceab6191ef38b49307a8421133012197283ecf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / scrypt-0.8.3.win-amd64-py2.7.exe

Download URL scrypt-0.8.3.win-amd64-py2.7.exe
Size 252.3 kB
Tags Source
SHA-256 checksum
How to use checksums
211292367e284fba47d591b5c59e88c70c68862b9e049d049aae72a66e635b32
BLAKE2b-256 checksum
How to use checksums
9aff3800784fc87b379498e3586a1b27d90b049dde29c9ee6bdf66ba82d121d7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / scrypt-0.8.3.win32-py3.6.exe

Download URL scrypt-0.8.3.win32-py3.6.exe
Size 485.7 kB
Tags Source
SHA-256 checksum
How to use checksums
7870c52417224051fad40853d108c897ca5dca79ba41a22d23f401eaa812e2eb
BLAKE2b-256 checksum
How to use checksums
68036933ae52cde7966bd8d735cfbc15cdfac5140277ce17fa08299553a6e68c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / scrypt-0.8.3.win32-py3.5.exe

Download URL scrypt-0.8.3.win32-py3.5.exe
Size 485.7 kB
Tags Source
SHA-256 checksum
How to use checksums
206d81607dccf8336930c4d2487009b74f19dbe8519c843b9ce08daf32983469
BLAKE2b-256 checksum
How to use checksums
b6785316e88a3a0c528abbac61bda52b4fd4674113daeee985878ae88cf31036
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / scrypt-0.8.3.win32-py3.4.exe

Download URL scrypt-0.8.3.win32-py3.4.exe
Size 216.8 kB
Tags Source
SHA-256 checksum
How to use checksums
2fd67b752fb408571766eebae8d708e665d94b5d48ff2976b40d559398724fd6
BLAKE2b-256 checksum
How to use checksums
8d3518f12d99ccc9c0dbd68f11a426669d1f529e3a92fa1e431902057b009682
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / scrypt-0.8.3.win32-py2.7.exe

Download URL scrypt-0.8.3.win32-py2.7.exe
Size 221.9 kB
Tags Source
SHA-256 checksum
How to use checksums
c8ea535cd6b15ef583d534efe551b095f47aa2193ca8b93c43b462740d91b5c6
BLAKE2b-256 checksum
How to use checksums
0bf9c75396e42f241356c6cd8f4567a209744604f0c292551c993ba6bee96296
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / scrypt-0.8.3-cp36-cp36m-win_amd64.whl

Download URL scrypt-0.8.3-cp36-cp36m-win_amd64.whl
Size 28.4 kB
Tags CPython 3.6 CPython 3.6 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
cdaff92b279aecdec4a7fb1a8bcb45e3c2276df724069ca644d7229089a90afc
BLAKE2b-256 checksum
How to use checksums
b05f254f518844e541948855ebe75b47b3971214c7d5b0e24d5a14bf32dc54a3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / scrypt-0.8.3-cp36-cp36m-win32.whl

Download URL scrypt-0.8.3-cp36-cp36m-win32.whl
Size 24.3 kB
Tags CPython 3.6 CPython 3.6 pymalloc Windows x86-32
SHA-256 checksum
How to use checksums
bf9e2ae48b0adf80554f8987a83e5b838f9f5bdefd09defbdc09ee23de8a58b6
BLAKE2b-256 checksum
How to use checksums
d5be55c845f1bed9c2882fcb63578165577b460ebe80a71ab7f726f935ad25d4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / scrypt-0.8.3-cp36-cp36m-macosx_10_6_intel.whl

Download URL scrypt-0.8.3-cp36-cp36m-macosx_10_6_intel.whl
Size 45.0 kB
Tags CPython 3.6 CPython 3.6 pymalloc macOS 10.6+ Intel (x86-64, i386)
SHA-256 checksum
How to use checksums
d5d18444f651b5b469d83e8ea1b00e9cc2e58dca0073674c56b8e6a9a9ebd608
BLAKE2b-256 checksum
How to use checksums
fb6444461d420c0368dd77bffddda311664699eedd67a08c21ff7f36d17055de
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / scrypt-0.8.3-cp35-cp35m-win_amd64.whl

Download URL scrypt-0.8.3-cp35-cp35m-win_amd64.whl
Size 28.4 kB
Tags CPython 3.5 CPython 3.5 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
06cfa7baab3158c1349671768288e682f4f31f810d37ad01edb4d570f69fbbd5
BLAKE2b-256 checksum
How to use checksums
ba984e0044f7085597cf89683d53ca63a6db3f34ab471758359b05ed24b7a8fa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / scrypt-0.8.3-cp35-cp35m-win32.whl

Download URL scrypt-0.8.3-cp35-cp35m-win32.whl
Size 24.3 kB
Tags CPython 3.5 CPython 3.5 pymalloc Windows x86-32
SHA-256 checksum
How to use checksums
eeee74d56fb7b11fed6f0badf3c02327df80c9c11b684d8974073d3371ab15c4
BLAKE2b-256 checksum
How to use checksums
78725bb17cf9a4e2719fa7d80709179e7e33e474ef39ae8d53d45685d7fbc5a7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / scrypt-0.8.3-cp35-cp35m-macosx_10_6_intel.whl

Download URL scrypt-0.8.3-cp35-cp35m-macosx_10_6_intel.whl
Size 44.9 kB
Tags CPython 3.5 CPython 3.5 pymalloc macOS 10.6+ Intel (x86-64, i386)
SHA-256 checksum
How to use checksums
25f726feedca5ab9056ae840ba6b9975adf891611926e7c9e95cb05c444995b6
BLAKE2b-256 checksum
How to use checksums
b686a95d5da6ab56c5c063585e5b6bdb2b5c3e2ee4cfeb267c80e9fed1e6ac6b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / scrypt-0.8.3-cp34-cp34m-win_amd64.whl

Download URL scrypt-0.8.3-cp34-cp34m-win_amd64.whl
Size 25.8 kB
Tags CPython 3.4 CPython 3.4 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
1e4d44dcef6d92b389f51c9258cf934db911da0adf6e073fa13209259ec8252a
BLAKE2b-256 checksum
How to use checksums
93b57cdf21fd71778d787c2899ea2b79159343324bff0eb4ed7f277824a6ef5f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / scrypt-0.8.3-cp34-cp34m-win32.whl

Download URL scrypt-0.8.3-cp34-cp34m-win32.whl
Size 22.6 kB
Tags CPython 3.4 CPython 3.4 pymalloc Windows x86-32
SHA-256 checksum
How to use checksums
c97f3564f376d56a9b84596787a61f2ba28fca8ecdfc71c477796b281268b508
BLAKE2b-256 checksum
How to use checksums
6a25a0a49b9762dca71fce91229154e1170f9549cbc44c9991655e983c810533
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / scrypt-0.8.3-cp27-cp27m-win_amd64.whl

Download URL scrypt-0.8.3-cp27-cp27m-win_amd64.whl
Size 25.4 kB
Tags CPython 2.7 CPython 2.7 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
0ac4cd21f5e467cb64a0c85d8c93b884e25e3f59b0fee6b034da232063fec35d
BLAKE2b-256 checksum
How to use checksums
82a6e612a3a933c1e605b065e215750427550bff5ecd07f2827517d711f645d9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / scrypt-0.8.3-cp27-cp27m-win32.whl

Download URL scrypt-0.8.3-cp27-cp27m-win32.whl
Size 22.6 kB
Tags CPython 2.7 CPython 2.7 pymalloc Windows x86-32
SHA-256 checksum
How to use checksums
b7848a9572106b178d47ff247fdd2c49e7e69662125bed4fa69b831adf0a0320
BLAKE2b-256 checksum
How to use checksums
a3c48180f5a125583f54c8cb6f486127e57fe23a8bb4fd4c94e97539877b1300
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

0.8.13

9 release files

0.8.12

9 release files

0.8.9

11 release files

0.8.8

11 release files

This release

0.8.3 This release

19 release files

0.8.0

18 release files

0.7.1

7 release files

0.7.0

5 release files

0.6.1

1 release file

0.6.0

1 release file

0.5.5

1 release file

0.5.4

1 release file

0.5.3

1 release file

0.5.2

1 release file

0.5.1

2 release files

0.5.0

1 release file

0.4.0

0.3.0

0.1.0

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