Skip to main content

A fork of Python Non-cryptographic Hash Library

Project description

Introduction pypi Travis CI Status codecov

pyhash is a python non-cryptographic hash library.

It provides several common hash algorithms with C/C++ implementation for performance and compatibility.

>>> import pyhash
>>> hasher = pyhash.fnv1_32()

>>> hasher('hello world')
2805756500L

>>> hasher('hello', ' ', 'world')
2805756500L

>>> hasher('world', seed=hasher('hello '))
2805756500L

It also can be used to generate fingerprints without seed.

>>> import pyhash
>>> fp = pyhash.farm_fingerprint_64()

>>> fp('hello')
>>> 13009744463427800296L

>>> fp('hello', 'world')
>>> [13009744463427800296L, 16436542438370751598L]

Notes

hasher('hello', ' ', 'world') is a syntax sugar for hasher('world', seed=hasher(' ', seed=hasher('hello'))), and may not equals to hasher('hello world'), because some hash algorithms use different hash and seed size.

For example, metro hash always use 32bit seed for 64/128 bit hash value.

>>> import pyhash
>>> hasher = pyhash.metro_64()

>>> hasher('hello world')
>>> 5622782129197849471L

>>> hasher('hello', ' ', 'world')
>>> 16402988188088019159L

>>> hasher('world', seed=hasher(' ', seed=hasher('hello')))
>>> 16402988188088019159L

Installation

$ pip install pyhash

Notes

If pip install failed with similar errors, #27

/usr/lib/gcc/x86_64-linux-gnu/6/include/smmintrin.h:846:1: error: inlining failed in call to always_inline 'long long unsigned int _mm_crc32_u64(long long unsigned int, long long unsigned int)': target specific option mismatch
 _mm_crc32_u64 (unsigned long long __C, unsigned long long __V)
 ^~~~~~~~~~~~~
src/smhasher/metrohash64crc.cpp:52:34: note: called from here
             v[0] ^= _mm_crc32_u64(v[0], read_u64(ptr)); ptr += 8;
                     ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~

Please upgrade pip and setuptools to latest version and try again

$ pip install --upgrade pip setuptools

Notes

If pip install failed on MacOS with similar errors #28

   creating build/temp.macosx-10.6-intel-3.6
   ...
   /usr/bin/clang -fno-strict-aliasing -Wsign-compare -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -arch i386 -arch x86_64 -g -c src/smhasher/metrohash64crc.cpp -o build/temp.macosx-10.6-intel-3.6/src/smhasher/metrohash64crc.o -msse4.2 -maes -mavx -mavx2
    src/smhasher/metrohash64crc.cpp:52:21: error: use of undeclared identifier '_mm_crc32_u64'
                v[0] ^= _mm_crc32_u64(v[0], read_u64(ptr)); ptr += 8;
                        ^

You may try to

$ CFLAGS="-mmacosx-version-min=10.13" pip install pyhash

Notes

pyhash only support pypy v6.0 or newer, please download and install the latest pypy.

Algorithms

pyhash supports the following hash algorithms

  • FNV (Fowler-Noll-Vo) hash
    • fnv1_32
    • fnv1a_32
    • fnv1_64
    • fnv1a_64
  • MurmurHash
    • murmur1_32
    • murmur1_aligned_32
    • murmur2_32
    • murmur2a_32
    • murmur2_aligned_32
    • murmur2_neutral_32
    • murmur2_x64_64a
    • murmur2_x86_64b
    • murmur3_32
    • murmur3_x86_128
    • murmur3_x64_128
  • lookup3
    • lookup3
    • lookup3_little
    • lookup3_big
  • SuperFastHash
    • super_fast_hash
  • City Hash _ city_32
    • city_64
    • city_128
    • city_crc_128
    • city_fingerprint_256
  • Spooky Hash
    • spooky_32
    • spooky_64
    • spooky_128
  • FarmHash
    • farm_32
    • farm_64
    • farm_128
    • farm_fingerprint_32
    • farm_fingerprint_64
    • farm_fingerprint_128
  • MetroHash
    • metro_64
    • metro_128
    • metro_crc_64
    • metro_crc_128
  • MumHash
    • mum_64
  • T1Ha
    • t1ha2 (64-bit little-endian)
    • t1ha2_128 (128-bit little-endian)
    • t1ha1 (64-bit native-endian)
    • t1ha1_le (64-bit little-endian)
    • t1ha1_be (64-bit big-endian)
    • t1ha0 (64-bit, choice fastest function in runtime.)
    • t1_32
    • t1_32_be
    • t1_64
    • t1_64_be
  • XXHash
    • xx_32
    • xx_64
    • xxh3_64 NEW
    • xxh3_128 NEW
  • Highway Hash
    • highway_64 NEW
    • highway_128 NEW
    • highway_256 NEW

String and Bytes literals

Python has two types can be used to present string literals, the hash values of the two types are definitely different.

  • For Python 2.x String literals, str will be used by default, unicode can be used with the u prefix.
  • For Python 3.x String and Bytes literals, unicode will be used by default, bytes can be used with the b prefix.

For example,

$ python2
Python 2.7.15 (default, Jun 17 2018, 12:46:58)
[GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyhash
>>> hasher = pyhash.murmur3_32()
>>> hasher('foo')
4138058784L
>>> hasher(u'foo')
2085578581L
>>> hasher(b'foo')
4138058784L
$ python3
Python 3.7.0 (default, Jun 29 2018, 20:13:13)
[Clang 9.1.0 (clang-902.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyhash
>>> hasher = pyhash.murmur3_32()
>>> hasher('foo')
2085578581
>>> hasher(u'foo')
2085578581
>>> hasher(b'foo')
4138058784

You can also import unicode_literals to use unicode literals in Python 2.x

from __future__ import unicode_literals

In general, it is more compelling to use unicode_literals when back-porting new or existing Python 3 code to Python 2/3 than when porting existing Python 2 code to 2/3. In the latter case, explicitly marking up all unicode string literals with u'' prefixes would help to avoid unintentionally changing the existing Python 2 API. However, if changing the existing Python 2 API is not a concern, using unicode_literals may speed up the porting process.

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

pyhash2-0.9.4.tar.gz (1.4 MB view details)

Uploaded Source

Built Distributions

pyhash2-0.9.4-cp313-cp313-win_amd64.whl (235.8 kB view details)

Uploaded CPython 3.13 Windows x86-64

pyhash2-0.9.4-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (262.2 kB view details)

Uploaded CPython 3.13 manylinux: glibc 2.17+ x86-64

pyhash2-0.9.4-cp312-cp312-win_amd64.whl (235.8 kB view details)

Uploaded CPython 3.12 Windows x86-64

pyhash2-0.9.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (261.1 kB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

pyhash2-0.9.4-cp311-cp311-win_amd64.whl (236.1 kB view details)

Uploaded CPython 3.11 Windows x86-64

pyhash2-0.9.4-cp311-cp311-manylinux_2_34_aarch64.manylinux_2_38_aarch64.whl (221.6 kB view details)

Uploaded CPython 3.11 manylinux: glibc 2.34+ ARM64 manylinux: glibc 2.38+ ARM64

pyhash2-0.9.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (262.7 kB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

pyhash2-0.9.4-cp310-cp310-win_amd64.whl (234.8 kB view details)

Uploaded CPython 3.10 Windows x86-64

pyhash2-0.9.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (260.8 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

pyhash2-0.9.4-cp39-cp39-win_amd64.whl (235.0 kB view details)

Uploaded CPython 3.9 Windows x86-64

pyhash2-0.9.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (261.2 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

pyhash2-0.9.4-cp38-cp38-win_amd64.whl (234.9 kB view details)

Uploaded CPython 3.8 Windows x86-64

pyhash2-0.9.4-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (260.5 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

File details

Details for the file pyhash2-0.9.4.tar.gz.

File metadata

  • Download URL: pyhash2-0.9.4.tar.gz
  • Upload date:
  • Size: 1.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.20

File hashes

Hashes for pyhash2-0.9.4.tar.gz
Algorithm Hash digest
SHA256 39d037c4fdf94ed737736ab2e77b4f28afe47345016cf9a128f9cdefdee42296
MD5 21f73a38d89f35d170f3e820f4842f04
BLAKE2b-256 434f9af03248cfe0a979fdd8282678968636a133cd06f5916a2073c2b7b027dc

See more details on using hashes here.

File details

Details for the file pyhash2-0.9.4-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: pyhash2-0.9.4-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 235.8 kB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.13.0

File hashes

Hashes for pyhash2-0.9.4-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 ad5286d4d53158c786cf6eb469ef7161a8d69523007b391f918573e0841f3471
MD5 2dd36c3d1f37b907b69b4097c61aab17
BLAKE2b-256 88f294f40a6aaa8c210a0909ac1479df40b4e516056358e196ab4e65c319b25b

See more details on using hashes here.

File details

Details for the file pyhash2-0.9.4-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyhash2-0.9.4-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a8db1f3b3e03bd2a5b8872aab42c0af0272f7c5f5e898dbc0f9fed3b563debbd
MD5 4bc2eec63cacac8edb38ef22ba507920
BLAKE2b-256 cbfcbacdf75c627fcdf20cad4f3e0e66c9f8707b9c4b906938117ba6b63f7381

See more details on using hashes here.

File details

Details for the file pyhash2-0.9.4-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: pyhash2-0.9.4-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 235.8 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for pyhash2-0.9.4-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 ee8d1805a85517dea017924a3c1639b160d2d4ee257c4297570aeaa5bd0a08ec
MD5 c77cd0b2478a5c0d14614079d44b5813
BLAKE2b-256 30b9b0461d80ee789c54b772a3ac207f3a5a4bc5267952893789f18b90f98562

See more details on using hashes here.

File details

Details for the file pyhash2-0.9.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyhash2-0.9.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5ef58766ff4a542f9ede627aa62f42e16f5c7be9b7ded857898925c121f03c0e
MD5 f7140c99967670eccc445d95b5e14e8e
BLAKE2b-256 6350ec3bdd6fb35edef301bc30e23b5bdaab46b05e1f2e84d7d6304fd7373e10

See more details on using hashes here.

File details

Details for the file pyhash2-0.9.4-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: pyhash2-0.9.4-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 236.1 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.9

File hashes

Hashes for pyhash2-0.9.4-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 ae89b5bfeddd1fd6c6d21b32f7a1e346829c179163c5c111f4fa610e85319877
MD5 6f7016c55c5308a667f2e7b332b34b02
BLAKE2b-256 24907bf5f7dcec97253bce0a881115a9a0524d38701412ec7764a1ea30a0f601

See more details on using hashes here.

File details

Details for the file pyhash2-0.9.4-cp311-cp311-manylinux_2_34_aarch64.manylinux_2_38_aarch64.whl.

File metadata

File hashes

Hashes for pyhash2-0.9.4-cp311-cp311-manylinux_2_34_aarch64.manylinux_2_38_aarch64.whl
Algorithm Hash digest
SHA256 6ede768bf65fd57ce84582e08c09d3bcaa4d297c1e0db958c1a5fd1b09a26d96
MD5 50a586d439bb776633695b9d2f742701
BLAKE2b-256 b6ec13dd035ef4544e90d519116fb426dca025559fe29f5eb42239a89fb39c9e

See more details on using hashes here.

File details

Details for the file pyhash2-0.9.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyhash2-0.9.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 33ef84cefdaf2f0591bf2c82154d7b1c30300a4d432a247247cf71768f582c5a
MD5 6e2ab00b579532f361ee575707dca140
BLAKE2b-256 74c9fa6fa87ab34abcf43c4bbf69298a5c3961d27aac36cd6cc30b4d6f3fa191

See more details on using hashes here.

File details

Details for the file pyhash2-0.9.4-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: pyhash2-0.9.4-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 234.8 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.11

File hashes

Hashes for pyhash2-0.9.4-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 9baed6c86723b1b94b8689d8f0b071a5ff3d2b80987095b993e4c046166c7d00
MD5 c36fcb5deb31fc6bd6dd69ee3f27335e
BLAKE2b-256 6108633b528cfd1b7764844998915e8cf408854b46096b1c97535e0415f36324

See more details on using hashes here.

File details

Details for the file pyhash2-0.9.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyhash2-0.9.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b24d90d2e2114a7349a5aa2b8ac0ffeee73617ea18a976c049aea6c9970ecef9
MD5 69f73da49162ed4f7d486119dd6350bb
BLAKE2b-256 a0bbb357e987eb8686912f048e3d9f51aad1c354ec6d9c0852ad11b0c25ed805

See more details on using hashes here.

File details

Details for the file pyhash2-0.9.4-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: pyhash2-0.9.4-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 235.0 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.13

File hashes

Hashes for pyhash2-0.9.4-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 1357dfd023f69fb29acdb2f42b9dacbe7d13632046b34b45200d66e3695894fd
MD5 9b0b2547d23164ff5597adb284303de6
BLAKE2b-256 f75c63baea827a9eacd1c45bf4a29b16ddd2c9dc7e58126c6ace2340e792e2a1

See more details on using hashes here.

File details

Details for the file pyhash2-0.9.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyhash2-0.9.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 37db697cdb21d187441b633195bf5338b32bda6068e17aa08301ad956ee8c0ee
MD5 7837e2ff99f8aa4ce9565d91a17f1ad9
BLAKE2b-256 523370f0e20a77f234c71989ece2e5d856fa068cf8ea4bbd8a5d5e1a13a08462

See more details on using hashes here.

File details

Details for the file pyhash2-0.9.4-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: pyhash2-0.9.4-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 234.9 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.8.10

File hashes

Hashes for pyhash2-0.9.4-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 b2de5fb2c153e90201ea09d3a38ab3ca881c98e8c2ee0cdfbd46c0940813ab81
MD5 bb05f0c0f2a5fa024ea187784c63d98f
BLAKE2b-256 6521c254704aa3b29e6deea75b622c7095ffb001d6075f5ee7396df02aa381de

See more details on using hashes here.

File details

Details for the file pyhash2-0.9.4-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyhash2-0.9.4-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9f2ea26106ee5a58e066977b0aa5bbe6f2be3f1d1c5cb997984418e25dff132b
MD5 9722142f6744a10c9354b06fe32bd1f9
BLAKE2b-256 df322a49dbbafa7476adfeec2082535376095bc40b7ae3aa2a4078a37808621b

See more details on using hashes here.

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