title: get murmur hash of a file with Python 3
body: <p>The <a href="https://pypi.org/project/Murmur/0.1.3/" rel="nofollow noreferrer">documentation</a> for the python library Murmur is a bit sparse.</p>
  
  <p>I have been trying to adapt the code from <a href="https://stackoverflow.com/a/7829658/4288043">this</a> answer:</p>
  
  <pre><code>import hashlib
  from functools import partial
  
  def md5sum(filename):
      with open(filename, mode='rb') as f:
          d = hashlib.md5()
          for buf in iter(partial(f.read, 128), b''):
              d.update(buf)
      return d.hexdigest()
  
  print(md5sum('utils.py'))
  </code></pre>
  
  <p>From what I read in the answer, the md5 can't operate on the whole file at once so it needs this looping. Not sure exactly what would happen on the line <code>d.update(buf)</code> however.</p>
  
  <p>The public methods in <code>hashlib.md5()</code> are:</p>
  
  <pre><code> 'block_size',
   'copy',
   'digest',
   'digest_size',
   'hexdigest',
   'name',
   'update'
  </code></pre>
  
  <p>whereas <code>mmh3</code> has</p>
  
  <pre><code>'hash',
  'hash64',
  'hash_bytes'
  </code></pre>
  
  <p>No <code>update</code> or <code>hexdigest</code> methods..</p>
  
  <p>Does anyone know how to achieve a similar result?</p>
  
  <p>The motivation is testing for uniqueness as fast as possible, the results <a href="https://softwareengineering.stackexchange.com/questions/49550/which-hashing-algorithm-is-best-for-uniqueness-and-speed">here</a> suggests murmur is a good candidate. </p>
  
  <p><em>Update -</em> </p>
  
  <p>Following the comment from @Bakuriu I had a look at <a href="https://pypi.org/project/mmh3/" rel="nofollow noreferrer">mmh3</a> which seems to be better documented.</p>
  
  <p>The public methods inside it are:</p>
  
  <pre><code>import mmh3
  print([x for x in dir(mmh3) if x[0]!='_'])
  &gt;&gt;&gt; ['hash', 'hash128', 'hash64', 'hash_bytes', 'hash_from_buffer']
  </code></pre>
  
  <p>..so no "update" method. I had a look at the source code for <code>mmh3.hash_from_buffer</code> but it does not look like it contains a loop and it is also not in Python, can't really follow it. Here is a <a href="https://github.com/alendit/mmh3/blob/master/mmh3module.cpp#L53" rel="nofollow noreferrer">link to the line</a></p>
  
  <p>So for now will just use CRC-32 which is supposed to be almost as good for the purpose, and it is <a href="https://stackoverflow.com/questions/1742866/compute-crc-of-file-in-python">well documented how to do it</a>. If anyone posts a solution will test it out.</p>