Skip to main content

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


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)

Uploaded Source

Built Distribution

super_hash-1.4.0-py3-none-any.whl (20.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page