title: Persisting hashlib state
body: <p>I'd like to create a <code>hashlib</code> instance, <code>update()</code> it, then persist its state in some way. Later, I'd like to recreate the object using this state data, and continue to <code>update()</code> it. Finally, I'd like to get the <code>hexdigest()</code> of the total cumulative run of data. State persistence has to survive across multiple runs.</p>
  
  <p>Example:</p>
  
  <pre><code>import hashlib
  m = hashlib.sha1()
  m.update('one')
  m.update('two')
  # somehow, persist the state of m here
  
  #later, possibly in another process
  # recreate m from the persisted state
  m.update('three')
  m.update('four')
  print m.hexdigest()
  # at this point, m.hexdigest() should be equal to hashlib.sha1().update('onetwothreefour').hextdigest()
  </code></pre>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I did not find a good way to do this with python in 2010 and ended up writing a small helper app in C to accomplish this. However, there are some great answers below that were not available or known to me at the time.</p>