idmtools.utils.hashing module¶
Fast hash of Python objects.
Copyright 2021, Bill & Melinda Gates Foundation. All rights reserved.
- class idmtools.utils.hashing.Hasher(hash_name='md5')¶
Bases:
pickle._Pickler
A subclass of pickler to do hashing, rather than pickling.
- __init__(hash_name='md5')¶
Initialize our hasher.
- Parameters:
hash_name – Hash type to use. Defaults to md5
- hash(obj, return_digest=True)¶
Hash an object.
- Parameters:
obj – Object to hash
return_digest – Should the digest be returned?
- Returns:
None if return_digest is False, otherwise the hash digest is returned
- save(obj)¶
Save an object to hash.
- Parameters:
obj – Obj to save.
- Returns:
None
- memoize(obj)¶
Disable memoization for strings so hashing happens on value and not reference.
- save_set(set_items)¶
Save set hashing.
- Parameters:
set_items – Set items
- Returns:
None
- idmtools.utils.hashing.hash_obj(obj, hash_name='md5')¶
Quick calculation of a hash to identify uniquely Python objects.
- Parameters:
obj – Object to hash
hash_name – The hashing algorithm to use. ‘md5’ is faster; ‘sha1’ is considered safer.
- idmtools.utils.hashing.ignore_fields_in_dataclass_on_pickle(item)¶
Ignore certain fields for pickling on dataclasses.
- Parameters:
item – Item to pickle
- Returns:
State of item to pickle