Hashlib
Hash Algorithms
import hashlib

# guaranteed algorithms
# 'blake2b,blake2s,md5,sha1,sha224,sha256,sha384,sha3_224,sha3_256,sha3_384,sha3_512,sha512,shake_128,shake_256'
hashlib.algorithms_guaranteed

# available algorithms
# 'blake2b,blake2s,md4,md5,md5-sha1,mdc2,ripemd160,sha1,sha224,sha256,sha384,sha3_224,sha3_256,sha3_384,sha3_512,sha512,sha512_224,sha512_256,shake_128,shake_256,sm3,whirlpool'
hashlib.algorithms_available
            
Hash
# MD5
h = hashlib.md5() # create a hash object
h.update(manifesto.encode('utf-8')) # add data
h.hexdigest() # hash code in hex

h = hashlib.new('md5')
h.update(b"Nobody inspects the spammish repetition")
h.hexdigest()
            
# SHA1
h = hashlib.sha1() # create a hash object
h.update(manifesto.encode('utf-8')) # add data
h.hexdigest() # hash code in hex
            
# SHA3-512
h = hashlib.sha3_512() # create a hash object
h.update(manifesto.encode('utf-8')) # add data
h.hexdigest() # hash code in hex
            
Incremental Updates
h = hashlib.md5()
h.update('Hello'.encode('utf-8'))
h.hexdigest() # '8b1a9953c4611296a827abf8c47804d7'

h.update('World'.encode('utf-8'))
h.hexdigest() # '68e109f0f40ca72a15e05cc22786f8e6'
            
Reference
  • Python 3 Standard Library
  • PyMOTW