Skip to main content

fnvhash-c

fury licence pyversions Publish Build Docs

Python FNV hash implementation based on cython, to give you an alternative choice when you need a high speed hash in python, could reduce the latency of a single call to tens of nanoseconds.

Because of deprecation, we selectively did not implement FNV-0.

With code structure referenced to https://github.com/znerol/py-fnvhash

Install

pip install fnvhash-c

Feature

  • Implementation in pure C, you can expect a 30x to 50x speedup.
  • Hash latency reduce to under 100ns.
  • A simple bloom filter built inside , which uses a slightly different parameter than the default value to keep result diverse. Ultra fast to use for distributed blacklist scenarios.
  • CityHash included, since the original repo is no longer maintained, it is difficult to compile directly on windows.

Documentation

https://fnvhash-c.readthedocs.io

Example

# example.py
import fnvhash_c

print(fnvhash_c.fnv1_32(b'Hello world!'))
print(fnvhash_c.fnv1a_32(b'Hello world!'))
print(fnvhash_c.fnv1_64(b'Hello world!'))
print(fnvhash_c.fnv1a_64(b'Hello world!'))

center = fnvhash_c.BloomFilter(capability = 4096) 
# To reduce runtime overhead, The default capacity is set to a constant compiled in the program.
# If you wish to change it, you need to compile the libs yourself to make sure the program work fine.
# Generally speaking, depending on the conversion time between Python and C, 
# a shorter capability usually helps to make filter run faster.

import random
random_char_generator = lambda : f"{random.randint(1000000000,9999999999)}+salt".encode()

test_time = 1000000
hit = 0
miss = 0
for _ in range(test_time):
    if center.hit(random_char_generator()):
        hit += 1
    else:
        miss += 1

# Since the filter is total blank ,the hit rate should be very low
assert (hit * 100 / test_time) <= 0.01
print(f"Empty filter hit rate: {round(hit * 100 / test_time)}%")

# Now we put something into the filter list.
black_list = [random_char_generator() for _ in range(10000)]
for char in black_list:
    center.update(char)

hit = 0
for _ in range(test_time):
    if center.hit(random_char_generator()):
        hit += 1
print(f"Filter with 10k elements hit rate: {round(hit * 100 / test_time,2)}%")

hit = 0
for char in black_list:
    if center.hit(char):
        hit += 1
print(f"Items in the blacklist hit rate: {round(hit * 100 / len(black_list),2)}%", ) # should be 100%

Metadata

Release files for fnvhash-c 0.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for fnvhash-c 0.1.4
File Actions
fnvhash_c-0.1.4-cp39-cp39-win_amd64.whl CPython 3.9 CPython 3.9 Windows x86-64 Details for fnvhash_c-0.1.4-cp39-cp39-win_amd64.whl
fnvhash_c-0.1.4-cp38-cp38-win_amd64.whl CPython 3.8 CPython 3.8 Windows x86-64 Details for fnvhash_c-0.1.4-cp38-cp38-win_amd64.whl
fnvhash_c-0.1.4-cp37-cp37m-win_amd64.whl CPython 3.7 CPython 3.7 pymalloc Windows x86-64 Details for fnvhash_c-0.1.4-cp37-cp37m-win_amd64.whl
fnvhash_c-0.1.4-cp36-cp36m-win_amd64.whl CPython 3.6 CPython 3.6 pymalloc Windows x86-64 Details for fnvhash_c-0.1.4-cp36-cp36m-win_amd64.whl

Total release size: 180.1 kB

Release files / fnvhash_c-0.1.4-cp39-cp39-win_amd64.whl

Download URL fnvhash_c-0.1.4-cp39-cp39-win_amd64.whl
Size 45.0 kB
Tags CPython 3.9 Windows x86-64
SHA-256 checksum
How to use checksums
eb2e795443b520dbc48fe98a9b18cda8a01abee11e1bc725926de1920c1ba80b
BLAKE2b-256 checksum
How to use checksums
73dd8ba1114a3a529dd4fd40d3e1cc2749210062721459900da01e02565576a8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

Release files / fnvhash_c-0.1.4-cp38-cp38-win_amd64.whl

Download URL fnvhash_c-0.1.4-cp38-cp38-win_amd64.whl
Size 45.4 kB
Tags CPython 3.8 Windows x86-64
SHA-256 checksum
How to use checksums
f9dc34c50f09ae4cdd240e92def1235f01cc2e23dcbd43a4575317899ba868fb
BLAKE2b-256 checksum
How to use checksums
73c547c30e1654425e5330af9746f487a8ae2de05986c8bd33219a2f30f2d649
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.8

Release files / fnvhash_c-0.1.4-cp37-cp37m-win_amd64.whl

Download URL fnvhash_c-0.1.4-cp37-cp37m-win_amd64.whl
Size 44.9 kB
Tags CPython 3.7 CPython 3.7 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
45f53a5ffbf3776a50fd42f01f9172fca111f3dea15aa435be9298f762a67550
BLAKE2b-256 checksum
How to use checksums
fda3fd3371d72cc2e24ab683eac235ce6401aca9f850d8e0e73b2d6e88807b08
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.7.9

Release files / fnvhash_c-0.1.4-cp36-cp36m-win_amd64.whl

Download URL fnvhash_c-0.1.4-cp36-cp36m-win_amd64.whl
Size 44.8 kB
Tags CPython 3.6 CPython 3.6 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
6dd8a4acbfc6012e39aab806caa81bf1b2004cfdf890ebf221edfaa3641e545f
BLAKE2b-256 checksum
How to use checksums
be87474e12a66186a4707e943c176c7bfa0fc1e321d786f7b14815f10282c0e4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.6.8

Security for fnvhash-c 0.1.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.4 This release

4 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page