{"id":14967242,"url":"https://github.com/brianpugh/micropython-fnv1a32","last_synced_at":"2025-08-04T08:33:47.710Z","repository":{"id":244994707,"uuid":"815375123","full_name":"BrianPugh/micropython-fnv1a32","owner":"BrianPugh","description":"Micropython native module for the FNV1a hashing algorithm.","archived":false,"fork":false,"pushed_at":"2024-07-07T21:00:02.000Z","size":29,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-09T16:43:05.578Z","etag":null,"topics":["fnv","hash","hashing","micropython","native","native-module","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BrianPugh.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-06-15T01:41:55.000Z","updated_at":"2024-07-07T22:48:12.000Z","dependencies_parsed_at":"2024-06-18T22:46:37.139Z","dependency_job_id":"00260044-7d98-4bd1-a9e9-9d26865e88ca","html_url":"https://github.com/BrianPugh/micropython-fnv1a32","commit_stats":null,"previous_names":["brianpugh/micropython-fnv1a32"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BrianPugh%2Fmicropython-fnv1a32","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BrianPugh%2Fmicropython-fnv1a32/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BrianPugh%2Fmicropython-fnv1a32/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BrianPugh%2Fmicropython-fnv1a32/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BrianPugh","download_url":"https://codeload.github.com/BrianPugh/micropython-fnv1a32/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238191515,"owners_count":19431439,"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","hash","hashing","micropython","native","native-module","python"],"created_at":"2024-09-24T13:37:41.392Z","updated_at":"2025-08-04T08:33:47.682Z","avatar_url":"https://github.com/BrianPugh.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# micropython-fnv1a32\n\n[FNV1a32](http://www.isthe.com/chongo/tech/comp/fnv) is a simple 32-bit hash function that is optimized for speed while maintaining a low collision rate.\n\nThis repo implements a [micropython native module](https://docs.micropython.org/en/latest/develop/natmod.html) of the fnv1a32 hash function. To use a precompiled micropython native module, download the appropriate architecture/micropython-version [from the release page](https://github.com/BrianPugh/micropython-fnv1a32/releases).\nRequires MicroPython `\u003e1.22.0`.\n\n# Usage\n\nThis library supplies a single function, `fnv1a32`, that can handle a variety of datatypes. The resulting hash is an `integer` object (not `bytes`!).\n\n### Hashing Data In-Memory\n\nTo hash `bytes`/`bytearray`/`str` in-memory:\n\n```python\nfrom fnv1a32 import fnv1a32\n\nfnv1a32_hash = fnv1a32(b\"this is the data to be hashed\")\n```\n\nTo continue hashing, supply the previous hash into the next `fnv1a32` invocation:\n\n```python\nfrom fnv1a32 import fnv1a32\n\nfnv1a32_hash = fnv1a32(b\"this is the data to be hashed\")\nfnv1a32_hash = fnv1a32(b\"more data\", fnv1a32_hash)\n```\n\n### Hashing File\n\nTo hash a file:\n\n```python\nfrom fnv1a32 import fnv1a32\n\nwith open(\"foo.bin\") as f:\n    # Defaults to using 4096-byte chunks\n    fnv1a32_hash = fnv1a32(f)\n```\n\nTo read and hash bigger chunks at a time (uses more memory, may improve speed):\n\n```python\nfrom fnv1a32 import fnv1a32\n\nwith open(\"foo.bin\") as f:\n    fnv1a32_hash = fnv1a32(f, buffer=16384)\n```\n\nA pre-allocated buffer may also be used:\n\n```python\nfrom fnv1a32 import fnv1a32\n\nbuffer = bytearray(16384)\nwith open(\"foo.bin\") as f:\n    fnv1a32_hash = fnv1a32(f, buffer=buffer)\n```\n\n# Unit Testing\n\nTo run the unittests, install [Belay](https://github.com/BrianPugh/belay/tree/main) and run the following commands:\n\n```bash\nmake clean\nmake\n\nbelay run micropython -m unittest tests/test_fnv1a32.py\n```\n\n# Benchmark\n\nThe following were benchmarked on an rp2040 hashing 50KB of data in-memory.\n\n| Implementation             | Bytes/s    | Relative Speed |\n|----------------------------|------------|----------------|\n| vanilla micropython        | 24,912     | 1.00x          |\n| @micropython.native        | 26,619     | 1.07x          |\n| @micropython.viper         | 2,438,786  | 97.90x         |\n| micropython native module  | 25,906,736 | 1040x          |\n\nTo run the benchmark, install [Belay](https://github.com/BrianPugh/belay/tree/main) and run the following commands:\n\n```bash\nexport MPY_DIR=../micropython  # Replace with your micropython directory.\nmake clean\nARCH=armv6m make  # Change the arch if running on different hardware.\n\nbelay install /dev/ttyUSB0 --with=dev\nbelay sync /dev/ttyUSB0 fnv1a32.mpy\nbelay run /dev/ttyUSB0 benchmark/fnv1a32_benchmark.py\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrianpugh%2Fmicropython-fnv1a32","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrianpugh%2Fmicropython-fnv1a32","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrianpugh%2Fmicropython-fnv1a32/lists"}