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
To use this package in your program, simply type
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
The 32-bit FarmHash variants benefit tremendously from SSE4.2 optimization, resulting in arguably the fastest non-cryptographic funtions in the 32-bit category. The 64-bit FarmHash version also benefits from SSE4.2 being enabled, but not as much as the 32-bit version does. It is still among the fastest 64-bit hash functions.
The vanilla CityHash fucntions (under cityhash
module) do not take advantage
of SSE4.2. Instead, the cityhashcrc
module (provided with this package for
x86-64 Mac and Linux platforms) exposes 128- and 256-bit CRC functions that
were specifically built take advantage from microprocessor-specific
instructions and which do harness SSE4.2, These functions are very fast, and in
fact beat FarmHash128 on speed (though please verify for yourself whether they
provide sufficient randomness).
For most use cases, I would recommend FarmHash over CityHash as it handles SSE4.2 optimizations more transparently and includes a bunch of other improvements.
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
The Makefiles provided have self-documenting targets. To find out which targets are available, type:
make help
Distribution
The wheels are built using cibuildwheel and are distributed to PyPI using GitHub actions using this workflow. 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.3.5.post3-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 676ffe0a98fb82c4233a4dd55ca7fc7a77251cd4620f83bca7a6843952bf27ae |
|
MD5 | f7a1f5503a211cc10d984bca42d46086 |
|
BLAKE2b-256 | c59cc6726f70271f7ce7800b19df231c02248e1d04092bc00d6f0279388288a4 |
Hashes for cityhash-0.3.5.post3-cp39-cp39-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3faf320c6e0ee82143f021f4690bed563bc3b79871237f4225773ac7fcab6f86 |
|
MD5 | 1b82429c33968dd963f18bd0b2a9c946 |
|
BLAKE2b-256 | 5d15adaf021505576645450fb1a04e5c328a0323cc8b961f30d5aa3c2e0c98b4 |
Hashes for cityhash-0.3.5.post3-cp39-cp39-manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 63cb76aee7bca87c66fa913539231032828f90bb1888c10d877b1040035abb51 |
|
MD5 | 8d73205d55a81b11d5983126ad4f3996 |
|
BLAKE2b-256 | 76e4381c605ca613d3e9f6f915017d61c3526be0aa23844ddfe1b8e189d9aa8e |
Hashes for cityhash-0.3.5.post3-cp39-cp39-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 82c48a745e2f5064eb9a90c8602ace3fe1f6ea7b049bac80a994ab5416c85f91 |
|
MD5 | a58ab5ce333d466008cb97cf4f25daa9 |
|
BLAKE2b-256 | 8c2d45be4980acff14d7d225af7c4bd54d3526985bf6264fd8eab1fda139459a |
Hashes for cityhash-0.3.5.post3-cp39-cp39-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ac7373341b724c5169fc56875f1d8d519866557b0bd6f55a12088ea0f01bd4e8 |
|
MD5 | d93987e9f25f130ce84e5ab6c9739557 |
|
BLAKE2b-256 | 32a7527a918b0aeaacb7e421de820e9cae36ea8b2bc8bb32b2a5cdbfd13cac4d |
Hashes for cityhash-0.3.5.post3-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2064b86897cbddc5cc9941edc8e4bb2080e88c11036b634dd84ad7367aed2c66 |
|
MD5 | 76a66c7a795576ffb8960c48704470bd |
|
BLAKE2b-256 | 2bcf9f0921bcc6188309eb98c638879df1ab41ba7bd6910e131c73161587b1ac |
Hashes for cityhash-0.3.5.post3-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9ed1914137d44e992beb116e4151cd3440124ba67ec7b470332fd9b006b43c0c |
|
MD5 | b591d59d30ba1ede06e512450830f15c |
|
BLAKE2b-256 | b2beb26e4f44f331e192a6ecfad1eb6541faf381b041ff59692c424927367ed5 |
Hashes for cityhash-0.3.5.post3-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b145bcef0731103d8cd169ba5123fa0361f2323eeae4f74b307b6abcaf9d98d3 |
|
MD5 | 6db484474b2cf65493a0aa2b308b3f3d |
|
BLAKE2b-256 | 46c516058ebb7141edeab0faace369de9a8ca71b666e049061a70d107f9fbdb8 |
Hashes for cityhash-0.3.5.post3-cp38-cp38-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8c65c444442e0a4d33a243b09e182726e6478ae3d229c2aed801e27f744f3f92 |
|
MD5 | bf9a74fcefe9d6b6623d451f2fa9396f |
|
BLAKE2b-256 | 2a9ed0bbfed756fa9709484dec1c1b272864b6bba16e5bab402bbf11ac8c90b9 |
Hashes for cityhash-0.3.5.post3-cp38-cp38-manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3c41b78fe4cce0d113300f1ee632cb563e426d5f5bbcbb7f7d627a11d13054e3 |
|
MD5 | 0b24a2a41a2db19fe1ca647c8aebb395 |
|
BLAKE2b-256 | 84286c900abc6ce53316c08d3a9ac2a35fde5a3a49fbf625eb301bf1e94c7638 |
Hashes for cityhash-0.3.5.post3-cp38-cp38-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b57e0510ce803e2e4b51987e45b7c93a801d8ff2b3526eace2188ae41aac10b8 |
|
MD5 | 287ebd5007dbce081d96f4b8ba6ddd2d |
|
BLAKE2b-256 | fdd1a5984c20b6b9c2023b67b7ffeb8c3253cd43d411eef1d67b5a827ffee4f6 |
Hashes for cityhash-0.3.5.post3-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c1c33202a58d194172b9ef1af2d1dd8a12daffc4aff26ba36de2f8d228975095 |
|
MD5 | 3bf8728e820f0d6aa23fe3d304cfca7c |
|
BLAKE2b-256 | a494c19f265b158205551aad21b7620a1d059f45dab93d47f9ef3e16b407eae2 |
Hashes for cityhash-0.3.5.post3-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b10c9c680d55381fdbb0480d2dc1027abaa40a8d6a1176d6013ad1062043d673 |
|
MD5 | 2600bf0e0da86e20a9d2b9afd81ea267 |
|
BLAKE2b-256 | 34d1775ec003574c5401bd0792d76d02ec09ad345e555794dd45cc00866477ef |
Hashes for cityhash-0.3.5.post3-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5aff2525af8c79a27e7e9399d12c051fb40147510f403f6db6a189395b55373c |
|
MD5 | 38f1c6a0171038b65d253a014365b998 |
|
BLAKE2b-256 | 5b5c0d697ed390479d4f922b458e19b8b6352cda7627c28f22f0ffb620c8990a |
Hashes for cityhash-0.3.5.post3-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bfc573606eac4840aa18955497156049bdc2c46960cae0661df066747fed28dc |
|
MD5 | 73dbdf6fc82a1a286574f9449ecf496b |
|
BLAKE2b-256 | e39b51680a66726533cb6af74d21031c671465dab7c0028f640174ea2182cfde |
Hashes for cityhash-0.3.5.post3-cp37-cp37m-manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1b45f98b8b826bb48f437fb9099fcd7d42ee49b72824853c9a6dd3a380e3e86b |
|
MD5 | 923e4f4c2f609480c6aa61a79f6bda1d |
|
BLAKE2b-256 | 738a7fbb896acd2b146c5aac3975d510fd199144723535b9161eaaa725d521e6 |
Hashes for cityhash-0.3.5.post3-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9eb8445ef339210e24876f0076f95b3d4e38f2d7409f6f21490c39d2d248c05b |
|
MD5 | 90dd0a0400302409e5bb8014525d8b11 |
|
BLAKE2b-256 | e48cf5309f548cbb720bb963cc0dad499629dae7285960750abdc8e70cc6e198 |
Hashes for cityhash-0.3.5.post3-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8e97032dddc86a8ed919235054538d95653eb38053c03b50a77041df689144ac |
|
MD5 | c2f0e281506ea02707c3410a7f343f02 |
|
BLAKE2b-256 | 4c81d4e0842d436e484720ba7ded570bd712855720482d420f71352741d705ff |
Hashes for cityhash-0.3.5.post3-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bfe1dedd0d3af8468a6a9a268206d71b3a3b42774a0a8c6cbbd02264ea497114 |
|
MD5 | ff32ab40cb9082e80bf1cb4381d450b9 |
|
BLAKE2b-256 | 837446dc516163e4d47e98b92ee28c96a869716c4f1c22f33d3df5d8ad59cd73 |
Hashes for cityhash-0.3.5.post3-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dcd73f80655f4443507bdff8d6a60645804fa804f5376d2233d5789b3ba46d8c |
|
MD5 | 4a0ad5cab6d545f6ebec9c642680a695 |
|
BLAKE2b-256 | d6e8805be0cdda27fc4ec430a180bd49ecb39d6f13b3441320dafd39ef1e5f78 |
Hashes for cityhash-0.3.5.post3-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1e2c519010677b5f889ae1eb89d3f2b7573ed08fbe420013d6e37616b586216e |
|
MD5 | 96c1f044e16eec8559321c8d503730d1 |
|
BLAKE2b-256 | 4decd3599001af0b75236377928f9088208e3d4f21f31efa4eed9ba871856aff |
Hashes for cityhash-0.3.5.post3-cp36-cp36m-manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d3b61f260ca1feeac547a625cf1eaeff07e0a5b6452fcbf3cfe83da89edbf1b |
|
MD5 | 0ecbe49b562be759d6d083e483308208 |
|
BLAKE2b-256 | 9db0d2568ec1eacecc5ea6a0570469b499e5f8d7484e20364e51e0fc300c55eb |
Hashes for cityhash-0.3.5.post3-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b672472fcc902d91299aafff887b5143441bedeadfbace72ea3989eecc86ddae |
|
MD5 | 62f6258927b2d871256f5423b521d922 |
|
BLAKE2b-256 | 836da162f0764c782c7356cdd90f7de4ae5bddc67b6ac3593a242dc70bedc42a |
Hashes for cityhash-0.3.5.post3-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3b728232a00ccf13a51b07494a3c98a39aeeed9af25802ceb563f6566c85158f |
|
MD5 | 1f96a27954b8e6e535d4fbbbfcf330ae |
|
BLAKE2b-256 | c4b82b515547ace6b25420bc9d637055b813f4159f877210a41ced223a6acc5e |
Hashes for cityhash-0.3.5.post3-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 21ababe501d8a315c9287e373713ac0aa0f0338ccdd73261bcac7e29e4079221 |
|
MD5 | 888950e2a9ba09677f01b159c02bea46 |
|
BLAKE2b-256 | cc9ce88a1c9db2b80799abdbf90b2e644f1737ed5bf2e842e3f670c41c092e2d |