Skip to content

Hashing

hashing

Fast cryptographic hash of Python objects, with a special case for fast hashing of numpy arrays.

Pickler = pickle._Pickler module-attribute

T = TypeVar('T') module-attribute

P = ParamSpec('P') module-attribute

Hashable

Bases: Protocol

A class that can be hashed.

Hasher

Bases: Pickler

A subclass of pickler, to do cryptographic hashing, rather than pickling.

stream = io.BytesIO() instance-attribute

dispatch = Pickler.dispatch.copy() class-attribute instance-attribute

__init__()

hash(obj, return_digest=True)

save(obj)

memoize(obj)

save_global(obj, name=None, pack=struct.pack)

save_set(set_items)

NumpyHasher

Bases: Hasher

Special case the hasher for when numpy is loaded.

coerce_mmap = coerce_mmap instance-attribute

np = np instance-attribute

__init__(coerce_mmap=False)

save(obj)

Subclass the save method, to hash ndarray subclass, rather than pickling them. Off course, this is a total abuse of the Pickler class.

Wrapped

Bases: Generic[T]

cls = cls instance-attribute

__init__(cls: Callable[P, T])

__call__(*args: P.args, **kwargs: P.kwargs) -> T

__getattr__(name: str) -> Any

hash(*obj, coerce_mmap=False)

Quick calculation of a hash to identify uniquely Python objects containing numpy arrays.

Parameters:

Name Type Description Default
obj

The objects to hash

()
coerce_mmap

Make no difference between np.memmap and np.ndarray

False

init_based_hash(cls: Type[T]) -> Wrapped[T]