Python bindings for CityHash and FarmHash
Project description
CityHash/FarmHash
Python wrapper for FarmHash and CityHash, a family of fast non-cryptographic hash functions.
Getting Started
This simplest way to use this package is to install it from PyPI:
pip install cityhash
This package exposes Python APIs for CityHash and FarmHash under cityhash
and
farmhash
namespaces, respectively. Each provides 32-, 64- and 128-bit
implementations.
Usage Examples
Stateless hashing
Usage example for FarmHash:
>>> from farmhash import FarmHash32, FarmHash64, FarmHash128
>>> FarmHash32("abc")
1961358185
>>> FarmHash64("abc")
2640714258260161385
>>> FarmHash128("abc")
76434233956484675513733017140465933893
Hardware-independent fingerprints
Fingerprints are seedless hashes which are guaranteed to be hardware- and platform-independent. This can be useful for networking applications which require persisting hashed values.
>>> from farmhash import Fingerprint128
>>> Fingerprint128("abc")
76434233956484675513733017140465933893
Incremental hashing
CityHash and FarmHash do not support incremental hashing and thus are not ideal for hashing of streams. If you require incremental hashing feature, use MetroHash or xxHash instead, which do support it.
Fast hashing of NumPy arrays
The Python Buffer Protocol allows Python objects to expose their data as raw byte arrays to other objects, for fast access without copying to a separate location in memory. Among others, NumPy is a major framework that supports this protocol.
All hashing functions in this packege will read byte arrays from objects that expose them via the buffer protocol. Here is an example showing hashing of a 4D NumPy array:
>>> import numpy as np
>>> from farmhash import FarmHash64
>>> arr = np.zeros((256, 256, 4))
>>> FarmHash64(arr)
1550282412043536862
The arrays need to be contiguous for this to work. To convert a non-contiguous
array, use NumPy's ascontiguousarray()
function.
SSE4.2 support
For x86-64 platforms, the PyPi repository for this package includes wheels compiled with SSE4.2 support. The 32- and 64-bit FarmHash variants significantly benefit from SSE4.2 instructions. The 128-bit version, unfortunately, does not exhibit speed up after compiling with SSE4.2 support.
The vanilla CityHash fucntions (under cityhash
module) do not take advantage
of SSE4.2. Instead, the cityhashcrc
module provided with this package exposes
128- and 256-bit CRC functions which do harness SSE4.2. These functions are
very fast, and beat FarmHash128
on speed (FarmHash does not include a 256-bit
function). Since FarmHash is the intended successor of CityHash, I would be
careful before using the CityHash-CRC functions, however, and would verify
whether they provide sufficient randomness for your intended application.
Development
Local workflow
For those who want to contribute, here is a quick start using some makefile commands:
git clone https://github.com/escherba/python-cityhash.git
cd python-cityhash
make env # create a Python virtualenv
make test # run Python tests
make cpp-test # run C++ tests
make shell # enter IPython shell
To find out which Make targets are available, type:
make help
Distribution
The wheels are built using cibuildwheel and are distributed to PyPI using GitHub actions. The wheels contain compiled binaries and are available for the following platforms: windows-amd64, ubuntu-x86, linux-x86_64, linux-aarch64, and macosx-x86_64.
See Also
For other fast non-cryptographic hash functions available as Python extensions, see MetroHash, MurmurHash, and xxHash.
Authors
The original CityHash Python bindings are due to Alexander [Amper] Marshalov. These were rewritten in Cython by Eugene Scherba, who also added the FarmHash bindings. The CityHash and FarmHash algorithms and their C++ implementation are by Google.
License
This software is licensed under the MIT License. See the included LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for cityhash-0.4.1-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 28644266189532a52c5d1497618d448f2bacb445b37619a90c3eb27968d3cd79 |
|
MD5 | 342e225a2b5d6cd299264a4b6ee347d4 |
|
BLAKE2b-256 | eddbc184f10bd573bf37fecd3ee7a96a55c5d4b91d566676eecc4814ca3c0ba9 |
Hashes for cityhash-0.4.1-cp39-cp39-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e9c47e25f6378a41537e52ed237c30489b6b287170981b71c35d4b710c4be924 |
|
MD5 | 511ea0494b9319f95f71922a94ed6cf9 |
|
BLAKE2b-256 | 9e6cc02992b307d3761eb3f0308d8f1f6fa446b8e2afc83d64ae67db12691248 |
Hashes for cityhash-0.4.1-cp39-cp39-manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3f5000fec390e71950fec11222cb2deee3d6655b16cf34ced1c48ab777960771 |
|
MD5 | c1c6f9d4e63d34c1d88855d2ef9d9bc9 |
|
BLAKE2b-256 | 30289dff0a4e2749f39852335d6163774c6874d67514cea75e1823d59f7d9698 |
Hashes for cityhash-0.4.1-cp39-cp39-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b7a9f5c85231b0794c098e403739b885dfd6b2fe95afdbca65db873db2ec6fa6 |
|
MD5 | 650932be2b85b1c7e8e98c0d959978b4 |
|
BLAKE2b-256 | d282f911348866120eed966fe8b8ef84f04ab86611c417c1f31d74c1e0620c37 |
Hashes for cityhash-0.4.1-cp39-cp39-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c71ce473c4440d1d2fdbd2d304f4ff7721b8da11a5d5f3f0fbf7ea265f084d55 |
|
MD5 | b8c4a3bf397fb2949b0c8d87a2c7eb0c |
|
BLAKE2b-256 | ad4cb48e6bbc4f2d507614d3df7e1501f7d38663ddd4242b4284858c9ecd6f5c |
Hashes for cityhash-0.4.1-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 90d805f66227e47bc1533144746c82d9525c403a67e0babc4e0b111a11777f5f |
|
MD5 | f45864681a5973351662dd1b9029d7a9 |
|
BLAKE2b-256 | a1978354599e56d12dacc3a4ab99a1e746d26f8eb2807c6c31e2a69dace229e2 |
Hashes for cityhash-0.4.1-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f1bd0e154e933375b8411e18fba48b5d4130d3b461725858fd6a3783325ede45 |
|
MD5 | 02fd7e644d9af9d4ee8fed5f09a02355 |
|
BLAKE2b-256 | 6c874aaec1a4d7f5ce5ad4432ef1812936d0f68c6037e312710734e8e1766490 |
Hashes for cityhash-0.4.1-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4001cf9d6cf3b5139e5a031a262b5434baacbce092945b7612647a4d2e29e78f |
|
MD5 | 9405dee88910c3b5b6d1600551005797 |
|
BLAKE2b-256 | d213e9a94ad713174afc6e1395d89df7f358f1ac0738cd981c839401ff8bbbc0 |
Hashes for cityhash-0.4.1-cp38-cp38-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a89013d3da48b75442a2405b5d6df858442e47883668f9b56da09b3603254766 |
|
MD5 | 3671937413aa2698c66230b5d2367efd |
|
BLAKE2b-256 | 427ab4f18e0b0aad72018d96201eda29179715e709451296d5f9caa2574bdee9 |
Hashes for cityhash-0.4.1-cp38-cp38-manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e3e5c5a3d5e4ced2847b2741639f134d99da2e9b6522a0686f582366500cd0f7 |
|
MD5 | 6621c11cd9367833cc2e9e27b21010c2 |
|
BLAKE2b-256 | 3344f59a0b424f14deb28a4e4329dd762435cf0b96390f242510ffdc68fc7167 |
Hashes for cityhash-0.4.1-cp38-cp38-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a797b008cb1f5b4a7ec582f1320ad169deea855cc899d9968f9c6b694a611343 |
|
MD5 | 025127b79298fb107d66795e0d6d4c44 |
|
BLAKE2b-256 | 37b0092662235c018f47b7e6fde419b04ddea61d4c7429cdde744bce51b479d9 |
Hashes for cityhash-0.4.1-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8974c3290f9c0a0d8c0a0e38ff527a978cfaec12ecfa23aad01d98bcb301d0d9 |
|
MD5 | 43bdbd76ca644983b1701c4df560369c |
|
BLAKE2b-256 | d0f6e2d1dcde7521c138f5ff98aea5ee4a94462d10a8b65eba18fbc3f52723ba |
Hashes for cityhash-0.4.1-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 47ae13c1a09df3dfe4b122f763049b6d5c339cfc1c73159515be7ce80986fa4e |
|
MD5 | 4569025b13ab3d9539bb1dc087c235a3 |
|
BLAKE2b-256 | c29ae2df0c1371f9792c798f3bbfb78ff71dae0869d50ac1417983458ef7568e |
Hashes for cityhash-0.4.1-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 87fb0136fc814da3156cad152d3fdf3b551f974c6555bf4c6a9dfb522eb23b99 |
|
MD5 | 5a68dbb6e2c09678b9a044ae301faace |
|
BLAKE2b-256 | 5e955db4e3bd30caac2cd32a27e7738b41c941099434c2964f66d41b2b76c245 |
Hashes for cityhash-0.4.1-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8dc42735d3cc3150c6d6f091b7715b76f556878d5e05305dada45bdd6f67c478 |
|
MD5 | 5343c35cbd831cf84b6333c4cab9aa45 |
|
BLAKE2b-256 | 60041d2cc17b38ffd1a7b35f96042436390f8f28f351506441accc18eb79ffc0 |
Hashes for cityhash-0.4.1-cp37-cp37m-manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4d47725618c0b70969a3fa091e8ee3f04048acd97f6f7f5fc992f3e627f2485f |
|
MD5 | 42a06286ca4bb68717f5617da1dd1edc |
|
BLAKE2b-256 | c50fba0cdca69573771fdd4d1b5276adc7d6a14373eefb3bafbfa8b05c1314ed |
Hashes for cityhash-0.4.1-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2e56c6a5b063fa311f835db3cca71de9f74d538f9cab5fa12e385af170cb93bf |
|
MD5 | 5e2ed3d9e9757bc34c0dffc4a6011c61 |
|
BLAKE2b-256 | 60048148b440ea2f03e2132a59fd10f6b52728c3602ef69fbd7721e32b5d0457 |
Hashes for cityhash-0.4.1-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 29cdb909b6dc0a82db16719d5953883ac471e47cf44d88144ce364df5f909741 |
|
MD5 | 31a969e7e6644d1f7b42dbd8b664e81d |
|
BLAKE2b-256 | 26e75d4e53e4f0dfc13ceddbcdf6a463da39fa001231b7c287b925af1619188d |
Hashes for cityhash-0.4.1-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8e7a94648b979adf8b00a202bee48f06ba2cc44a2e0885e017021c8b5beccb91 |
|
MD5 | 8d7b6b504d0ec56866cb0f164d4598c4 |
|
BLAKE2b-256 | b77f870596f3f6431946df2adaab5bb9803f713cf3be14770f36fcb70055ea22 |
Hashes for cityhash-0.4.1-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 26464fa40470b267d76d23e6fb611c4e37208ededa2b516c2a8e3a07f9bce168 |
|
MD5 | cce78d0d0253f264c23ce4aef30fb57f |
|
BLAKE2b-256 | 48aaf3eb8aa4c3fd1735b55e4a755b402421105d39a9ea98008ffb07717f9815 |
Hashes for cityhash-0.4.1-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f138be483510bae1c92f92fd3e17040d876b4a556a51c35311fc2ca5458ef65f |
|
MD5 | 22db5284065c26fdf85ff6ca8272df82 |
|
BLAKE2b-256 | 7e716e6d3129aa9b83b03197a3f378f2ccea86423eb78977c0800fc21c3d0471 |
Hashes for cityhash-0.4.1-cp36-cp36m-manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | adbb59bf7f9af8396053955d1d6080740e5d7bbd7a00f3b3dff049f21a96b2bc |
|
MD5 | e45a63480ac37303ed7923cf24474a96 |
|
BLAKE2b-256 | f892a22e497f46901ae771303fa2934728110903fa40136ca481e2c7b1d32cd5 |
Hashes for cityhash-0.4.1-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 67192cbcbf5e18f0ab61b1e67667b5f2d87eea9c9e102d743b1bb100223ff812 |
|
MD5 | 9586a612f651d59b1396abc6e19b4ac3 |
|
BLAKE2b-256 | 04be41b852fde4e64dd5c2d48265c34d69b6ae47c96c2ae3b99cb71e3f973357 |
Hashes for cityhash-0.4.1-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b5569ae4d38a520b009790915079e403c18c4acbcdae309266b5ed6c2eff16ad |
|
MD5 | 270b9f5a2026794c48ce1a7f8e7c3fba |
|
BLAKE2b-256 | 65f330ab3e228e72db9671e489723d5d4e40dd999bcd6a5d24cfc3010589b7a6 |
Hashes for cityhash-0.4.1-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b39eb943799f3180cd874eecd5c884ba2169c600bb325076a334bfa2a0a448a4 |
|
MD5 | bfb33a279d496901a2aaa78981d5c5c0 |
|
BLAKE2b-256 | 498935ae85c223e5294d234b388a245a19cf839b2147cba506b58b142e2107c9 |