Simple python tool to hash dictionaries using both default hash and sha256.
Project description
Simple python tool to hash dictionaries using both default hash and sha256. The library comes with full support for hashing pandas dataframes and numpy arrays.
How do I install this package?
As usual, just download it using pip:
pip install dict_hash
Tests Coverage
Since some software handling coverages sometimes get slightly different results, here’s three of them:
Usage examples
The package offers two functions: sha256 to generate constant sha256 hashes and dict_hash, to generate hashes using the native hash function.
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)
sha256
Obtain a consistent hash from the given dictionary.
from dict_hash import sha256
from random_dict import random_dict
from random import randint
d = random_dict(randint(1, 10), randint(1, 10))
my_hash = sha256(d)
Hashable
When handling complex objects within the dictionaries, you may need to implement the class Hashable in that object.
Here is an example:
from dict_hash import Hashable, sha256
class MyHashable(Hashable):
def __init__(self, a: int):
self._a = a
self._time = time()
def consistent_hash(self) -> str:
return sha256({
"a": self._a
})
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.