Install & Compatibility
Where this runs
tested against v0.9.4 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.012s · 23MB
glibcpy 3.10–3.920 runs
installs and imports cleanly · install 1.6s · import 0.019s · 22MB
20MB installed
● package 20MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
hash
✓ from scrypt import hash
✗ from scrypt import scrypt_hash
The hashing function is directly named 'hash' within the scrypt module.
verify
✓ from scrypt import verify
This quickstart demonstrates how to hash a password using `scrypt.hash()` and verify it with `scrypt.verify()`. It highlights the importance of `N`, `r`, and `p` parameters and the use of cryptographically secure random salts. Inputs (password and salt) must be `bytes`.
import scrypt
import os
# --- Parameters for scrypt (N, r, p) ---
# N: CPU/Memory cost parameter (must be a power of 2, e.g., 2**14 = 16384)
# Higher N means more work, increasing security against brute-force attacks.
# r: Block size parameter
# p: Parallelization parameter
# Choosing these values appropriately is critical for security and performance.
# For production, recommended values are often N=2**14 to 2**20, r=8, p=1.
# Values too high can cause excessive memory/CPU usage, potentially leading to DoS.
N = 16384 # 2**14
r = 8
p = 1
password = b"my_super_secret_password"
# Generate a cryptographically secure random salt (at least 16 bytes)
salt = os.urandom(16)
try:
# 1. Hash the password
# The hash function returns bytes
hashed_password_bytes = scrypt.hash(password, salt, N, r, p)
print(f"Scrypt hash (hex): {hashed_password_bytes.hex()}")
# 2. Verify the password
# For verification, the original password, salt, and parameters (N, r, p)
# used during hashing must be provided.
is_valid = scrypt.verify(password, hashed_password_bytes, salt, N, r, p)
print(f"Password verification successful: {is_valid}")
# Example of a wrong password
wrong_password = b"wrong_password"
try:
scrypt.verify(wrong_password, hashed_password_bytes, salt, N, r, p)
print("Verification with wrong password succeeded (ERROR!)")
except scrypt.error:
print("Verification with wrong password failed (EXPECTED)")
except scrypt.error as e:
print(f"An scrypt error occurred: {e}")
except Exception as e:
print(f"An unexpected error occurred: {e}")
# In a real application, you would store the salt and N, r, p parameters
# alongside the hash (e.g., as part of a standard scrypt format string like $s0$...)
# The 'scrypt' library does not provide this format string generation directly;
# you need to implement that logic yourself or use a higher-level library.
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'scrypt'
The `scrypt` package is not installed in your Python environment.
fixRun `pip install scrypt` to install the library.
TypeError: Expected bytes, got str
The `scrypt.hash()` or `scrypt.verify()` function received a string (`str`) where it expected bytes (`bytes`) for password or salt.
fixEnsure that both your password and salt are `bytes` objects. Convert strings using `.encode('utf-8')` or by prefixing string literals with `b` (e.g., `b"password"`). error: command 'gcc' failed with exit status 1 (or similar C compiler error during installation)
The `scrypt` library is a C extension and requires a C compiler and development headers to be present on your system for installation.
fixInstall the necessary build tools:
- **Windows**: Install 'Build Tools for Visual Studio 20XX' from Microsoft (e.g., Visual C++ build tools 14.0 or greater).
- **Debian/Ubuntu**: `sudo apt-get install build-essential python3-dev`
- **Fedora/RHEL**: `sudo yum groupinstall 'Development Tools' && sudo yum install python3-devel`
- **macOS**: `xcode-select --install` (Xcode Command Line Tools).
scrypt.error: Invalid scrypt parameters (N, r, p)
The provided `N`, `r`, or `p` parameters are outside the valid range, or `N` is not a power of 2, or the combination leads to an impossible memory/CPU allocation.
fixReview your `N`, `r`, and `p` values. `N` must be a power of 2 (e.g., 2048, 4096, 16384). `r` and `p` typically default to 8 and 1 respectively, and must be positive integers. Ensure they match the values used during hashing if verifying.
Upgrade
Version history
0.9.4latest on PyPI · released Aug 5, 2025
Audit
Dependencies
No dependency data recorded yet.