fnv-c is a Python 3.7+ FNV (fnv0, fnv1, fnv1a) non-cryptographic hash library implemented in C through libffi.
FNV ("Fowler–Noll–Vo") is is a non-cryptographic hash function created by Glenn Fowler, Landon Curt Noll, and Kiem-Phong. FNV is probably not the "best" non-cryptographic hash function but:
- it has a reasonably good distribution
- it's very fast
- it's very easy to implement (even in some exotic stored procedures for example) so you can use it everywhere
More details on this Wikepedia article.
- speed:
- up to 800 MB/s hashing speed (on Macbook Pro M1 (2020) with
fnv0_64) - 6 800% faster than basic Python implementation, 70% faster than
pyhash(when hashing 100 bytes withfnv0_64on a cloud VM)
- up to 800 MB/s hashing speed (on Macbook Pro M1 (2020) with
- portability:
- tested with recent Python versions (3.7+)
- compatible with ARM64
- compatible (and tested) with PyPy
- other hash algorithms (this library is only about FNV algorithm)
- too agressive CPU optimizations (we prefer maximizing binary portability)
You have a benchmark script here to bench fnv-c by yourself and to compare it with:
Differences with fnvhash are huge (from 35% for one byte hashing to 19 000% for 1 000 bytes hashing with fnv0_64)
Differences with pyhash (on fnv0_64) are shown with the following diagram:
pip install fnv-c
import fnv_c
print(fnv_c.fnv0_32(b"foo bar"))
print(fnv_c.fnv0_64(b"foo bar"))
print(fnv_c.fnv1_32(b"foo bar"))
print(fnv_c.fnv1_64(b"foo bar"))
print(fnv_c.fnv1a_32(b"foo bar"))
print(fnv_c.fnv1a_64(b"foo bar"))Full API doc is available at: https://botify-labs.github.io/fnv-c/fnv_c/
See CONTRIBUTING
fnv-c is licensed under the MIT license.

