Skip to main content

Python bindings for MetroHash, a fast non-cryptographic hash algorithm

Project description

A Python wrapper around MetroHash

Latest Version Downloads Travis-CI Test Status

Installation

To get started, clone this repo and run make env or, alternatively, install it into your environment of choice (below). Note that you will need to have Cython installed before you install this package.

pip install -U cython
pip install metrohash

Example Usage

This package provides Python interfaces to 64- and 128-bit implementations of MetroHash algorithm. For stateless hashing, it exports metrohash64 and metrohash128 functions. Both take a value to be hashed (either string or unicode) and an optional seed parameter:

>>> import metrohash
...
>>> metrohash.metrohash64("abc", seed=0)
17099979927131455419L
>>> metrohash.metrohash128("abc")
182995299641628952910564950850867298725L

For incremental hashing, use MetroHash64 and MetroHash128 classes. Incremental hashing is associative and guarantees that any combination of input slices will result in the same final hash value. This is useful for processing large inputs and stream data. Example with two slices:

>>> mh = metrohash.MetroHash64()
>>> mh.update("Nobody inspects")
>>> mh.update(" the spammish repetition")
>>> mh.intdigest()
7851180100622203313L

Note that the resulting hash value above is the same as in:

>>> mh = metrohash.MetroHash64()
>>> mh.update("Nobody inspects the spammish repetition")
>>> mh.intdigest()
7851180100622203313L

Authors

The original MetroHash algorithm was designed by J. Andrew Rogers. The Python bindings in this package were written by Eugene Scherba.

License

This software is licensed under the MIT License. See the included LICENSE file for more information.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for metrohash, version 0.0.11
Filename, size File type Python version Upload date Hashes
Filename, size metrohash-0.0.11-cp27-none-macosx_10_10_x86_64.whl (22.2 kB) File type Wheel Python version 2.7 Upload date Hashes View
Filename, size metrohash-0.0.11.tar.gz (10.8 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page