all Python 3hashlibterm
hashlib
module
Cryptographic hash functions: SHA-256, SHA-3, BLAKE2, MD5 and keys derived from passwords via pbkdf2_hmac and scrypt.
Syntax
import hashlib
hashlib computes a fingerprint of data: a file checksum, a cache key, an integrity check. Signing with a secret key is hmac, and random tokens are secrets. Bytes are hashed, so a string is encoded first. Passwords are not stored as sha256: there are the slow, salted pbkdf2_hmac and scrypt for that, and MD5 and SHA-1 are no longer fit for security.
Examples
import hashlib
print(hashlib.sha256(b'hello').hexdigest()[:16]) # → 2cf24dba5fb0a30e
print(hashlib.sha256('привет'.encode('utf-8')).digest_size) # → 32
See also
Open in the full glossarydocs.python.orgReport an inaccuracy