{"id":18004740,"url":"https://github.com/goodmanwen/py-fnvhash-c","last_synced_at":"2025-07-12T19:38:36.714Z","repository":{"id":57431677,"uuid":"343939007","full_name":"GoodManWEN/py-fnvhash-c","owner":"GoodManWEN","description":"Python FNV hash implementation based on cython, to give you an alternative high speed choice.","archived":false,"fork":false,"pushed_at":"2022-04-15T18:49:51.000Z","size":147,"stargazers_count":9,"open_issues_count":1,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-16T22:03:16.970Z","etag":null,"topics":["fnv","fnvhash"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/GoodManWEN.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-03-02T23:13:03.000Z","updated_at":"2025-01-16T01:30:55.000Z","dependencies_parsed_at":"2022-09-02T11:51:38.794Z","dependency_job_id":null,"html_url":"https://github.com/GoodManWEN/py-fnvhash-c","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GoodManWEN%2Fpy-fnvhash-c","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GoodManWEN%2Fpy-fnvhash-c/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GoodManWEN%2Fpy-fnvhash-c/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GoodManWEN%2Fpy-fnvhash-c/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/GoodManWEN","download_url":"https://codeload.github.com/GoodManWEN/py-fnvhash-c/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245636552,"owners_count":20647990,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fnv","fnvhash"],"created_at":"2024-10-30T00:15:48.487Z","updated_at":"2025-03-26T10:31:36.190Z","avatar_url":"https://github.com/GoodManWEN.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# fnvhash-c\n[![fury](https://img.shields.io/pypi/v/fnvhash-c.svg)](https://pypi.org/project/fnvhash-c/)\n[![licence](https://img.shields.io/github/license/GoodManWEN/py-fnvhash-c)](https://github.com/GoodManWEN/py-fnvhash-c/blob/master/LICENSE)\n[![pyversions](https://img.shields.io/pypi/pyversions/fnvhash-c.svg)](https://pypi.org/project/fnvhash-c/)\n[![Publish](https://github.com/GoodManWEN/py-fnvhash-c/workflows/Publish/badge.svg)](https://github.com/GoodManWEN/py-fnvhash-c/actions?query=workflow:Publish)\n[![Build](https://github.com/GoodManWEN/py-fnvhash-c/workflows/Build/badge.svg)](https://github.com/GoodManWEN/py-fnvhash-c/actions?query=workflow:Build)\n[![Docs](https://readthedocs.org/projects/fnvhash-c/badge/?version=latest)](https://readthedocs.org/projects/fnvhash-c/)\n\nPython 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.\n\nBecause of deprecation, we selectively did not implement FNV-0.\n\nWith code structure referenced to [https://github.com/znerol/py-fnvhash](https://github.com/znerol/py-fnvhash)\n\n## Install\n\n    pip install fnvhash-c\n\n## Feature\n- Implementation in pure C, you can expect a 30x to 50x speedup.\n- Hash latency reduce to under 100ns.\n- 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.\n- CityHash included, since the [original repo](https://github.com/escherba/python-cityhash) is no longer maintained, it is difficult to compile directly on windows.\n\n## Documentation\nhttps://fnvhash-c.readthedocs.io\n\n## Example\n\n```Python3\n# example.py\nimport fnvhash_c\n\nprint(fnvhash_c.fnv1_32(b'Hello world!'))\nprint(fnvhash_c.fnv1a_32(b'Hello world!'))\nprint(fnvhash_c.fnv1_64(b'Hello world!'))\nprint(fnvhash_c.fnv1a_64(b'Hello world!'))\n\ncenter = fnvhash_c.BloomFilter(capability = 4096) \n# To reduce runtime overhead, The default capacity is set to a constant compiled in the program.\n# If you wish to change it, you need to compile the libs yourself to make sure the program work fine.\n# Generally speaking, depending on the conversion time between Python and C, \n# a shorter capability usually helps to make filter run faster.\n\nimport random\nrandom_char_generator = lambda : f\"{random.randint(1000000000,9999999999)}+salt\".encode()\n\ntest_time = 1000000\nhit = 0\nmiss = 0\nfor _ in range(test_time):\n    if center.hit(random_char_generator()):\n        hit += 1\n    else:\n        miss += 1\n\n# Since the filter is total blank ,the hit rate should be very low\nassert (hit * 100 / test_time) \u003c= 0.01\nprint(f\"Empty filter hit rate: {round(hit * 100 / test_time)}%\")\n\n# Now we put something into the filter list.\nblack_list = [random_char_generator() for _ in range(10000)]\nfor char in black_list:\n    center.update(char)\n    \nhit = 0\nfor _ in range(test_time):\n    if center.hit(random_char_generator()):\n        hit += 1\nprint(f\"Filter with 10k elements hit rate: {round(hit * 100 / test_time,2)}%\")\n\nhit = 0\nfor char in black_list:\n    if center.hit(char):\n        hit += 1\nprint(f\"Items in the blacklist hit rate: {round(hit * 100 / len(black_list),2)}%\", ) # should be 100%\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoodmanwen%2Fpy-fnvhash-c","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgoodmanwen%2Fpy-fnvhash-c","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoodmanwen%2Fpy-fnvhash-c/lists"}