Skip to content
Python wrapper of xxhash
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples
pyhashxx
tests
.gitignore Ignore build and test byproducts. Jun 3, 2013
.travis.yml
LICENSE Initial commit with readme and license. May 31, 2013
README.md Add simple example and performance tests. Jun 4, 2013
setup.py

README.md

pyhashxx

Python wrapper of xxhash that supports concurrency and is packaged nicely for installation with pip/distribute.

The existing wrapper I could find used a static global hash context and wasn't packaged nicely for installation with Python package managers. This version fixes both those issues. The naming rearrangement is to avoid conflicts with the existing wrapper in python.

See http://code.google.com/p/xxhash/ for the original xxHash code.

Examples

The easiest way to use the hash function is the convenience function hashxx that returns the hash of the bytes of its parameters, and which will traverse tuples (even recursively).

from pyhashxx import hashxx
hashxx(b'Hello World!')
hashxx(b'Hello', b' ', b'World!')
hashxx((b'Hello', b' ', b'World!'))
hashxx((b'Hello', b' '), (b'World!',))
# All return 198612872
hashxx(b'Hello World!', seed=1)
# Changing the seed changes the result to 2212595744

You can also use the Hashxx class to compute the hash incrementally, and extract intermediate digest values:

from pyhashxx import Hashxx
hasher = Hashxx(seed=0) # seed is optional
hasher.update(b'Hello')
hasher.update(b' ')
print(hasher.digest()) # Prints 1401757748
hasher.update(b'World!')
print(hasher.digest()) # Prints 198612872

See the examples/ directory for more, including a script testing performance.

Buildbot

Build Status

You can’t perform that action at this time.