pyhf.utils.digest#

pyhf.utils.digest(obj, algorithm='sha256')[source]#

Get the digest for the provided object. Note: object must be JSON-serializable.

The hashing algorithms supported are in hashlib, part of Python’s Standard Libraries.

Example

>>> import pyhf
>>> obj = {'a': 2.0, 'b': 3.0, 'c': 1.0}
>>> pyhf.utils.digest(obj)
'a38f6093800189b79bc22ef677baf90c75705af2cfc7ff594159eca54eaa7928'
>>> pyhf.utils.digest(obj, algorithm='md5')
'2c0633f242928eb55c3672fed5ba8612'
>>> pyhf.utils.digest(obj, algorithm='sha1')
'49a27f499e763766c9545b294880df277be6f545'
Raises:

ValueError – If the object is not JSON-serializable or if the algorithm is not supported.

Parameters:
  • obj (jsonable) – A JSON-serializable object to compute the digest of. Usually a Workspace object.

  • algorithm (str) – The hashing algorithm to use.

Returns:

The digest for the JSON-serialized object provided and hash algorithm specified.

Return type:

digest (str)