import hashlib


def get_file_hash(path, algorithm='md5'):
  """Get hash from a given file and hashing algorithm.

  Args:
    path: str.
      Full path to a file.
    algorithm: str, optional.
      Name of hashing algorithm. See `hashlib.algorithms_available`
      for list of available hashing algorithms in python.

  Returns:
    str. File hash computed from the file using the specified algorithm.

  #### Examples

  ```python
  get_file_hash('train.gz')
  ## '5503d900f6902c61682e6b6f408202cb'
  ```
  """
  hash_alg = hashlib.new(algorithm)
  with open(path, 'rb') as f:
    read_size = 1024 * 1024 * 4
    data = f.read(read_size)
    while data:
      hash_alg.update(data)
      data = f.read(read_size)
  return hash_alg.hexdigest()