Create Hash for Arbitrary Objects?
<p>I've been using <code>pickle.dumps</code> in order to create a hash for an arbitrary Python object, however, I've found out that dict/set orders aren't canonicalized and the result is therefore unreliable.</p>

<p>There are <a href="http://stackoverflow.com/questions/5417949/computing-an-md5-hash-of-a-data-structure">several</a> <a href="http://stackoverflow.com/questions/9339345/hash-a-python-new-style-class-instance">related</a> <a href="http://stackoverflow.com/questions/12727571/using-pickle-dumps-to-hash-mutable-objects">questions</a> on SO and <a href="http://www.aminus.org/blogs/index.php/2007/11/03/pickle_dumps_not_suitable_for_hashing?blog=2" rel="nofollow">elsewhere</a>, but I can't seem to find a hashing algorithm that uses the same basis for equality (<code>__getstate__</code>/<code>__dict__</code> results). I understand the basic requirements for rolling my own, but obviously I'd much prefer to use something that's been tested.</p>

<p>Does such a library exist? I suppose what I'm actually asking for is a library that serializes objects deterministically (using <code>__getstate__</code> and <code>__dict__</code>) so that I can hash the output.</p>

<p><strong>EDIT</strong></p>

<p>To clarify, I'm looking for something different than the values returned by Python's <a href="http://docs.python.org/2/library/functions.html#hash" rel="nofollow"><code>hash</code></a> (or <a href="http://docs.python.org/2/reference/datamodel.html#object.__hash__" rel="nofollow"><code>__hash__</code></a>). What I want is essentially a checksum for arbitrary objects which may or may not be hashable. This value should vary based on objects' state. (I'm using "state" to refer to the dict retuned by <code>__getstate__</code> or, if that's not present, the object's <code>__dict__</code>.)</p>
