My goal is to feed an object that supports the buffer protocol into hashlib's sha2 generator such that sha2 hashes generated from the same underlying data in different execution environments are consistent, and so can be used for equality tests.
I would like this to work for arbitrary data types without having to write a bunch of boilerplate wrappers around bytes()
or bytearray()
, ie, one function I can pass strings (with encoding), numerics, and bools. Extra points if I can get the memory layout for a complex type like a dict or list.
I am looking at struct
, as well as doing something like loading the data into a pandas
DataFrame and then using Apache Arrow to access the memory layout directly.
Looking for guidance as to the most "pythonic" way to accomplish this.