{"id":15093795,"url":"https://github.com/ifduyue/python-xxhash","last_synced_at":"2025-05-14T00:10:57.401Z","repository":{"id":19200513,"uuid":"22434000","full_name":"ifduyue/python-xxhash","owner":"ifduyue","description":"Python Binding for xxHash","archived":false,"fork":false,"pushed_at":"2025-04-28T01:10:38.000Z","size":251,"stargazers_count":397,"open_issues_count":5,"forks_count":34,"subscribers_count":15,"default_branch":"master","last_synced_at":"2025-05-03T02:09:25.359Z","etag":null,"topics":["cpython","hash","python","xxhash"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/xxhash/","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ifduyue.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGELOG.rst","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,"zenodo":null}},"created_at":"2014-07-30T15:38:47.000Z","updated_at":"2025-04-25T04:28:14.000Z","dependencies_parsed_at":"2024-04-29T14:28:16.645Z","dependency_job_id":"e78fa605-6243-4c4b-9afc-da9513a5a4a3","html_url":"https://github.com/ifduyue/python-xxhash","commit_stats":{"total_commits":311,"total_committers":12,"mean_commits":"25.916666666666668","dds":0.1061093247588425,"last_synced_commit":"4fe56577759a2c9ba479517fa54e7e4ff599ab46"},"previous_names":[],"tags_count":40,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ifduyue%2Fpython-xxhash","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ifduyue%2Fpython-xxhash/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ifduyue%2Fpython-xxhash/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ifduyue%2Fpython-xxhash/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ifduyue","download_url":"https://codeload.github.com/ifduyue/python-xxhash/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254043711,"owners_count":22004999,"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":["cpython","hash","python","xxhash"],"created_at":"2024-09-25T12:00:43.297Z","updated_at":"2025-05-14T00:10:52.393Z","avatar_url":"https://github.com/ifduyue.png","language":"C","readme":"python-xxhash\n=============\n\n.. image:: https://github.com/ifduyue/python-xxhash/actions/workflows/test.yml/badge.svg\n    :target: https://github.com/ifduyue/python-xxhash/actions/workflows/test.yml\n    :alt: Github Actions Status\n\n.. image:: https://img.shields.io/pypi/v/xxhash.svg\n    :target: https://pypi.org/project/xxhash/\n    :alt: Latest Version\n\n.. image:: https://img.shields.io/pypi/pyversions/xxhash.svg\n    :target: https://pypi.org/project/xxhash/\n    :alt: Supported Python versions\n\n.. image:: https://img.shields.io/pypi/l/xxhash.svg\n    :target: https://pypi.org/project/xxhash/\n    :alt: License\n\n\n.. _HMAC: http://en.wikipedia.org/wiki/Hash-based_message_authentication_code\n.. _xxHash: https://github.com/Cyan4973/xxHash\n.. _Cyan4973: https://github.com/Cyan4973\n\n\nxxhash is a Python binding for the xxHash_ library by `Yann Collet`__.\n\n__ Cyan4973_\n\nInstallation\n------------\n\n.. code-block:: bash\n\n   $ pip install xxhash\n   \nYou can also install using conda:\n\n.. code-block:: bash\n\n   $ conda install -c conda-forge python-xxhash\n\n\nInstalling From Source\n~~~~~~~~~~~~~~~~~~~~~~~\n\n.. code-block:: bash\n\n   $ pip install --no-binary xxhash xxhash\n\nPrerequisites\n++++++++++++++\n\nOn Debian/Ubuntu:\n\n.. code-block:: bash\n\n   $ apt-get install python-dev gcc\n\nOn CentOS/Fedora:\n\n.. code-block:: bash\n\n   $ yum install python-devel gcc redhat-rpm-config\n\nLinking to libxxhash.so\n~~~~~~~~~~~~~~~~~~~~~~~~\n\nBy default python-xxhash will use bundled xxHash,\nwe can change this by specifying ENV var ``XXHASH_LINK_SO``:\n\n.. code-block:: bash\n\n   $ XXHASH_LINK_SO=1 pip install --no-binary xxhash xxhash\n\nUsage\n--------\n\nModule version and its backend xxHash library version can be retrieved using\nthe module properties ``VERSION`` AND ``XXHASH_VERSION`` respectively.\n\n.. code-block:: python\n\n    \u003e\u003e\u003e import xxhash\n    \u003e\u003e\u003e xxhash.VERSION\n    '2.0.0'\n    \u003e\u003e\u003e xxhash.XXHASH_VERSION\n    '0.8.0'\n\nThis module is hashlib-compliant, which means you can use it in the same way as ``hashlib.md5``.\n\n    | update() -- update the current digest with an additional string\n    | digest() -- return the current digest value\n    | hexdigest() -- return the current digest as a string of hexadecimal digits\n    | intdigest() -- return the current digest as an integer\n    | copy() -- return a copy of the current xxhash object\n    | reset() -- reset state\n\nmd5 digest returns bytes, but the original xxh32 and xxh64 C APIs return integers.\nWhile this module is made hashlib-compliant, ``intdigest()`` is also provided to\nget the integer digest.\n\nConstructors for hash algorithms provided by this module are ``xxh32()`` and ``xxh64()``.\n\nFor example, to obtain the digest of the byte string ``b'Nobody inspects the spammish repetition'``:\n\n.. code-block:: python\n\n    \u003e\u003e\u003e import xxhash\n    \u003e\u003e\u003e x = xxhash.xxh32()\n    \u003e\u003e\u003e x.update(b'Nobody inspects')\n    \u003e\u003e\u003e x.update(b' the spammish repetition')\n    \u003e\u003e\u003e x.digest()\n    b'\\xe2);/'\n    \u003e\u003e\u003e x.digest_size\n    4\n    \u003e\u003e\u003e x.block_size\n    16\n\nMore condensed:\n\n.. code-block:: python\n\n    \u003e\u003e\u003e xxhash.xxh32(b'Nobody inspects the spammish repetition').hexdigest()\n    'e2293b2f'\n    \u003e\u003e\u003e xxhash.xxh32(b'Nobody inspects the spammish repetition').digest() == x.digest()\n    True\n\nAn optional seed (default is 0) can be used to alter the result predictably:\n\n.. code-block:: python\n\n    \u003e\u003e\u003e import xxhash\n    \u003e\u003e\u003e xxhash.xxh64('xxhash').hexdigest()\n    '32dd38952c4bc720'\n    \u003e\u003e\u003e xxhash.xxh64('xxhash', seed=20141025).hexdigest()\n    'b559b98d844e0635'\n    \u003e\u003e\u003e x = xxhash.xxh64(seed=20141025)\n    \u003e\u003e\u003e x.update('xxhash')\n    \u003e\u003e\u003e x.hexdigest()\n    'b559b98d844e0635'\n    \u003e\u003e\u003e x.intdigest()\n    13067679811253438005\n\nBe careful that xxh32 takes an unsigned 32-bit integer as seed, while xxh64\ntakes an unsigned 64-bit integer. Although unsigned integer overflow is\ndefined behavior, it's better not to make it happen:\n\n.. code-block:: python\n\n    \u003e\u003e\u003e xxhash.xxh32('I want an unsigned 32-bit seed!', seed=0).hexdigest()\n    'f7a35af8'\n    \u003e\u003e\u003e xxhash.xxh32('I want an unsigned 32-bit seed!', seed=2**32).hexdigest()\n    'f7a35af8'\n    \u003e\u003e\u003e xxhash.xxh32('I want an unsigned 32-bit seed!', seed=1).hexdigest()\n    'd8d4b4ba'\n    \u003e\u003e\u003e xxhash.xxh32('I want an unsigned 32-bit seed!', seed=2**32+1).hexdigest()\n    'd8d4b4ba'\n    \u003e\u003e\u003e\n    \u003e\u003e\u003e xxhash.xxh64('I want an unsigned 64-bit seed!', seed=0).hexdigest()\n    'd4cb0a70a2b8c7c1'\n    \u003e\u003e\u003e xxhash.xxh64('I want an unsigned 64-bit seed!', seed=2**64).hexdigest()\n    'd4cb0a70a2b8c7c1'\n    \u003e\u003e\u003e xxhash.xxh64('I want an unsigned 64-bit seed!', seed=1).hexdigest()\n    'ce5087f12470d961'\n    \u003e\u003e\u003e xxhash.xxh64('I want an unsigned 64-bit seed!', seed=2**64+1).hexdigest()\n    'ce5087f12470d961'\n\n\n``digest()`` returns bytes of the **big-endian** representation of the integer\ndigest:\n\n.. code-block:: python\n\n    \u003e\u003e\u003e import xxhash\n    \u003e\u003e\u003e h = xxhash.xxh64()\n    \u003e\u003e\u003e h.digest()\n    b'\\xefF\\xdb7Q\\xd8\\xe9\\x99'\n    \u003e\u003e\u003e h.intdigest().to_bytes(8, 'big')\n    b'\\xefF\\xdb7Q\\xd8\\xe9\\x99'\n    \u003e\u003e\u003e h.hexdigest()\n    'ef46db3751d8e999'\n    \u003e\u003e\u003e format(h.intdigest(), '016x')\n    'ef46db3751d8e999'\n    \u003e\u003e\u003e h.intdigest()\n    17241709254077376921\n    \u003e\u003e\u003e int(h.hexdigest(), 16)\n    17241709254077376921\n\nBesides xxh32/xxh64 mentioned above, oneshot functions are also provided,\nso we can avoid allocating XXH32/64 state on heap:\n\n    | xxh32_digest(bytes, seed=0)\n    | xxh32_intdigest(bytes, seed=0)\n    | xxh32_hexdigest(bytes, seed=0)\n    | xxh64_digest(bytes, seed=0)\n    | xxh64_intdigest(bytes, seed=0)\n    | xxh64_hexdigest(bytes, seed=0)\n\n.. code-block:: python\n\n    \u003e\u003e\u003e import xxhash\n    \u003e\u003e\u003e xxhash.xxh64('a').digest() == xxhash.xxh64_digest('a')\n    True\n    \u003e\u003e\u003e xxhash.xxh64('a').intdigest() == xxhash.xxh64_intdigest('a')\n    True\n    \u003e\u003e\u003e xxhash.xxh64('a').hexdigest() == xxhash.xxh64_hexdigest('a')\n    True\n    \u003e\u003e\u003e xxhash.xxh64_hexdigest('xxhash', seed=20141025)\n    'b559b98d844e0635'\n    \u003e\u003e\u003e xxhash.xxh64_intdigest('xxhash', seed=20141025)\n    13067679811253438005L\n    \u003e\u003e\u003e xxhash.xxh64_digest('xxhash', seed=20141025)\n    '\\xb5Y\\xb9\\x8d\\x84N\\x065'\n\n.. code-block:: python\n\n    In [1]: import xxhash\n\n    In [2]: %timeit xxhash.xxh64_hexdigest('xxhash')\n    268 ns ± 24.1 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)\n\n    In [3]: %timeit xxhash.xxh64('xxhash').hexdigest()\n    416 ns ± 17.3 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)\n\n\nXXH3 hashes are available since v2.0.0 (xxHash v0.8.0), they are:\n\nStreaming classes:\n\n    | xxh3_64\n    | xxh3_128\n\nOneshot functions:\n\n    | xxh3_64_digest(bytes, seed=0)\n    | xxh3_64_intdigest(bytes, seed=0)\n    | xxh3_64_hexdigest(bytes, seed=0)\n    | xxh3_128_digest(bytes, seed=0)\n    | xxh3_128_intdigest(bytes, seed=0)\n    | xxh3_128_hexdigest(bytes, seed=0)\n\nAnd aliases:\n\n    | xxh128 = xxh3_128\n    | xxh128_digest = xxh3_128_digest\n    | xxh128_intdigest = xxh3_128_intdigest\n    | xxh128_hexdigest = xxh3_128_hexdigest\n\nCaveats\n-------\n\nSEED OVERFLOW\n~~~~~~~~~~~~~~\n\nxxh32 takes an unsigned 32-bit integer as seed, and xxh64 takes\nan unsigned 64-bit integer as seed. Make sure that the seed is greater than\nor equal to ``0``.\n\nENDIANNESS\n~~~~~~~~~~~\n\nAs of python-xxhash 0.3.0, ``digest()`` returns bytes of the\n**big-endian** representation of the integer digest. It used\nto be little-endian.\n\nDONT USE XXHASH IN HMAC\n~~~~~~~~~~~~~~~~~~~~~~~\nThough you can use xxhash as an HMAC_ hash function, but it's\nhighly recommended not to.\n\nxxhash is **NOT** a cryptographic hash function, it is a\nnon-cryptographic hash algorithm aimed at speed and quality.\nDo not put xxhash in any position where cryptographic hash\nfunctions are required.\n\n\nCopyright and License\n---------------------\n\nCopyright (c) 2014-2024 Yue Du - https://github.com/ifduyue\n\nLicensed under `BSD 2-Clause License \u003chttp://opensource.org/licenses/BSD-2-Clause\u003e`_\n","funding_links":[],"categories":["C"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fifduyue%2Fpython-xxhash","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fifduyue%2Fpython-xxhash","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fifduyue%2Fpython-xxhash/lists"}