def hash_file(path, algorithm='md5', bufsize=8192):
    h = hashlib.new(algorithm)
with open(path, 'rb') as f:
    block = f.read(bufsize)
if not block:
    break
h.update(block)
return h.digest()
File Checksums in Python