Registry / serialization / fnvhash

fnvhash

JSON →
library0.2.1pypypi✓ verified 86d ago

fnvhash is a pure Python implementation of the FNV (Fowler-Noll-Vo) hash function family, including FNV-1 and FNV-1a variants. It is known for its simplicity and speed in non-cryptographic hashing applications. The library is actively maintained, with its current version 0.2.1, and focuses on correctness with 100% test coverage.

pip install fnvhash
INSTALL
IMPORT
SIG · FNVHASH
F
fnvhash
serializationpythonv0.2.1
Install
1.5s avg
Import
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.2.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.9MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 1.5s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

fnv1a_32
from fnvhash import fnv1a_32
Imports the 32-bit FNV-1a hash function.
fnv1_64
from fnvhash import fnv1_64
Imports the 64-bit FNV-1 hash function.

This quickstart demonstrates how to import and use the 32-bit FNV-1a and 64-bit FNV-1 hash functions. It highlights the requirement for input data to be `bytes` objects.

from fnvhash import fnv1a_32, fnv1_64 data_str = "hello world" data_bytes = data_str.encode('utf-8') # FNV hash functions expect bytes # Calculate 32-bit FNV-1a hash hash_32 = fnv1a_32(data_bytes) print(f"FNV-1a 32-bit hash of '{data_str}': {hex(hash_32)}") # Calculate 64-bit FNV-1 hash long_data_str = "this is a slightly longer string for 64-bit hashing" long_data_bytes = long_data_str.encode('utf-8') hash_64 = fnv1_64(long_data_bytes) print(f"FNV-1 64-bit hash of '{long_data_str}': {hex(hash_64)}")
Debug
Known issues
gotchaFNV hashes are NOT cryptographically secure. They are designed for speed and distribution (e.g., hash tables, checksums), not for security-sensitive applications where resistance to malicious attacks or collision engineering is required. Use cryptographic hash functions like SHA-256 for security needs.
fix
Do not use FNV hash functions for security-sensitive applications. Use `hashlib.sha256` or similar.
affects: All versions
gotchaThe FNV hash functions (`fnv1a_32`, `fnv1_64`, etc.) expect `bytes` objects as input, not Python `str` objects. Passing a string directly will result in a TypeError.
fix
Ensure all input data is encoded to `bytes` (e.g., `my_string.encode('utf-8')`) before passing it to the hash function.
affects: All versions
gotchaThis `fnvhash` library is a pure Python implementation. While portable, it may be significantly slower than C-extension based FNV hash libraries (e.g., `pyhash`, `fnvhash-c`) for performance-critical applications or large data sets.
fix
For maximum performance, consider using alternative libraries that provide C implementations of FNV hashing, such as `fnvhash-c` or `fnv-hash-fast` (which can fall back to pure Python `fnvhash`).
affects: All versions
breakingThe library requires Python 3.9 or newer. Attempts to install or run on older Python versions (e.g., Python 3.8 or 2.x) will fail.
fix
Ensure your environment uses Python 3.9 or a newer compatible version.
affects: <=0.2.1
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'fnvhash'
The fnvhash library has not been installed in the current Python environment.
fix
pip install fnvhash
TypeError: a bytes-like object is required, not 'str'
The fnvhash hashing functions expect byte strings as input, but a regular Python string was provided.
fix
Encode the string to bytes before passing it to the hash function, for example: `data.encode('utf-8')`.
NameError: name 'fnv' is not defined
The user attempted to use a module or object named 'fnv' which is not the correct import name for the library, or did not import the specific functions from 'fnvhash'.
fix
Import specific hash functions directly from the fnvhash module, such as: `from fnvhash import fnv1a_32, fnv1_64`.
Upgrade
Version history
0.2.1latest on PyPI · released May 5, 2025
Audit
Dependencies

No dependency data recorded yet.

Agent activity
12 hits · last 30 days
node
8
Amazon
1
Resources
fnvhash — pip install fnvhash · libregistry