Skip to content

Dobatymo/metrohash-python

This branch is 1 commit ahead of master.

Folders and files

NameName
Last commit message
Last commit date
Sep 3, 2024
May 27, 2019
Apr 15, 2024
Oct 21, 2020
May 27, 2019
Apr 15, 2024
May 27, 2019
Oct 21, 2020
Dec 6, 2021
Apr 15, 2024
Apr 15, 2024
Apr 15, 2024
Apr 15, 2024

Repository files navigation

metrohash-python

Python bindings for the fast non-cryptograpical hash function MetroHash. MetroHash C++ library by J. Andrew Rogers, Python bindings by Dobatymo.

Requirements

The library has been tested on Linux Python 3.6, and on Windows Python 3.6, 3.7.

Install

pip install metrohash-python

Compilation requires a C++ compiler and optionally Cython.

Examples

The usage is similar to Python's hashlib.

>>> import metrohash
>>> h = metrohash.MetroHash128()
>>> h.update(b'asd')
>>> h.update(b'qwe')
>>> h.digest()
b'K\xfb\x17\xeb>\xb2W\xbd\x93\xad\xf6\x17\xceg\x14\xda'
>>> h.hexdigest()
'4bfb17eb3eb257bd93adf617ce6714da'

Or as simple non-incremental function:

>>> import metrohash
>>> metrohash.metrohash128(b'asdqwe')
b'K\xfb\x17\xeb>\xb2W\xbd\x93\xad\xf6\x17\xceg\x14\xda'

The interface for MetroHash64 and metrohash64 is the same.