Skip to main content

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

Project description

A Python wrapper around MetroHash

https://travis-ci.org/escherba/python-metrohash.svg

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 git+https://github.com/escherba/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. Each has an optional seed parameter.

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

For incremental hashing, use CMetroHash64 and CMetroHash128 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.

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

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

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

Project details


Download files

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

Source Distribution

metrohash-0.0.4.tar.gz (9.9 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page