Python package to hash dictionaries using default hash, md5, sha256 and more.
Low maintenance activity. Last release 13 months ago, commits in 1 of the last 26 weeks. Weaker on commit activity and recent releases.
pip install dict-hashDict Hash
Python package to hash dictionaries using both default hash and sha256. It comes with full support for hashing Pandas & Polars DataFrame/Series objects, Numba objects and Numpy arrays. It supports both objects from Pandas 1.x and 2.x and Numpy 1.x and 2.x.
Furthermore, the library supports objects that can be recursively hashed.
As we saw this library being used in the wild mostly to create caching libraries and wrappers, we'd like to point you to our library, Cache decorator.
Why can't I just use the default hash function?
In Python, dictionaries just aren't hashable. This is because they are mutable objects, and as such, they cannot be hashed.
If you were to try and run hash({}), you would get a TypeError exception.
How do I install this package?
As usual, just download it using pip:
pip install dict_hash
Usage examples
The package offers two functions: sha256 to generate constant sha256 hashes and dict_hash, to generate hashes using the native hash function.
Session hash with dict_hash
Obtain a session hash from the given dictionary.
from dict_hash import dict_hash
from random_dict import random_dict
from random import randint
d = random_dict(randint(1, 10), randint(1, 10))
my_hash = dict_hash(d)
Consistent hashes
Obtain a consistent hash from the given dictionary. Supported methods include md5, sha256, sha1, sha224, sha384, sha512, sha3_512, , , , , , , , as provided from the library.