all Python 3until 3.13Linux · macOSRemoved from the standard libraryterm
crypt
removed modules
Wrapper around the system crypt(3) call for hashing passwords. Unix-only. Removed in Python 3.13 — use hashlib.scrypt or passlib.
Syntax
import crypt # до 3.13
crypt.crypt(password, salt) called the system crypt(3) and returned a string like '$6$salt$hash', as in /etc/shadow; crypt.mksalt() prepared the salt. PEP 594 dropped it: the algorithms depended on the system, macOS had only weak DES, Windows had no module at all. How to port: take the salt from os.urandom(16) or secrets.token_bytes(16), the hash from hashlib.scrypt(password, salt=salt, n=2**14, r=8, p=1) or hashlib.pbkdf2_hmac('sha256', ...), store the salt next to the hash, and on login recompute and compare with hmac.compare_digest(). passlib, bcrypt and argon2-cffi provide ready hash formats. To verify actual crypt(3) hashes use legacycrypt or standard-crypt from PyPI.
Examples
# Python 3.13+
try:
import crypt
except ModuleNotFoundError as e:
print(type(e).__name__) # → ModuleNotFoundError
# Python 3.13+
import hashlib, hmac, os
salt = os.urandom(16)
stored = hashlib.scrypt(b'secret', salt=salt, n=2**14, r=8, p=1)
attempt = hashlib.scrypt(b'secret', salt=salt, n=2**14, r=8, p=1)
print(len(stored), hmac.compare_digest(stored, attempt)) # → 64 True
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy