code: def hash_file(path, digest=None):
    
    digest = digest or hashlib.sha1()
    with open(path, 'rb') as fd:
      s = fd.read(8192)
      while s:
        digest.update(s)
        s = fd.read(8192)
    return digest.hexdigest() if PY3 else digest.hexdigest().decode('utf-8')
docs: Hashes the contents of the file at the given path and returns the hash digest in hex form.
  
    If a hashlib message digest is not supplied a new sha1 message digest is used.