hash the unhashable, hash everything
Project description
What is this?
A simple python tool for hashing objects that python normally treats as unhashable. There are also a few other tools such as ways of deeply hashing functions, and an system for extending this hashability to work with other existing classes, such as dataframes or neural networks.
How do I use this?
pip install super_hash
from super_hash import super_hash, function_hashers, FrozenDict, helpers
normally_unhashable = {
frozenset({
frozenset({
"key-deep-deep": 10
}.items()): "key-deep",
}.items()): "first_value",
"second_value": [
{"a": 10},
]
}
a_hash = super_hash(normally_unhashable)
#
# extend what can be hashed
#
# example1:
import pandas as pd
# tell super_hash that pandas dataframes should be converted to csv, then hashed
super_hash.conversion_table[pd.DataFrame] = lambda data_frame : super_hash(data_frame.to_csv())
# example2:
import torch
# create a custom checker function
is_non_scalar_pytorch_tensor = lambda value: isinstance(value, torch.Tensor) and len(value.shape) > 0
# create a custom converter
super_hash.conversion_table[is_non_scalar_pytorch_tensor] = lambda non_scalar_tensor: super_hash(non_scalar_tensor.tolist())
# example3:
class Thing:
def __super_hash__(self):
return self.file_path
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.
Source Distribution
super_hash-1.4.0.tar.gz
(18.8 kB
view hashes)
Built Distribution
super_hash-1.4.0-py3-none-any.whl
(20.0 kB
view hashes)
Close
Hashes for super_hash-1.4.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8921cd154ef45113d443b06c95b6fd4b93629782564ed51408b8701e42116675 |
|
MD5 | 2f95251036b31b1a5f8b46f84c729db5 |
|
BLAKE2b-256 | 6216de9ac42e3d5cecf98c4f88629cf88a5daf47cb34c8ca71ad95f708931001 |