stablehash


Namestablehash JSON
Version 0.2.2 PyPI version JSON
download
home_pageNone
SummaryStable hashing of Python data structures across separate processes and platforms.
upload_time2025-07-09 15:47:09
maintainerNone
docs_urlNone
authorNone
requires_python>=3.10
licenseMIT
keywords dataclasses hash hashlib python hashing stable hash
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # stablehash

The `stablehash` module provides a "pure" hash function that is stable across Python processes and runs. This is in
contrast to the builtin `hash()` function, which may return a different value for the same input in separate
invokations even with the Python version.

We support most Python built-in types, including mutable types such as `list` and `dict`, as well as dataclasses. The
default internal hash algorithm is Blake2b, but this can be changed by passing a different `hashlib` algorithm to the
`stablehash` function.

## Usage

```python
from stablehash import stablehash

assert stablehash({"key": "value"}, algorithm="md5").hexdigest() == 'd5994850379366e314563ea555532052'
```

## API

### `stablehash(obj=..., *, algorithm="blake2b")`

Returns a `hashlib`-compatible object with the given algorithm and the hash of the given object. The algorithm must be
one of the algorithms supported by `hashlib`.

### `stablehash.update(obj)`

Updates the hash with the given object. If the object is not supported, a `TypeError` is raised.

### `stablehash.digest()`

Returns the digest of the hash as a bytes object.

### `stablehash.hexdigest()`

Returns the digest of the hash as a string object.

## Supported types

The following types are supported:

- `None`
- `bool`
- `int`
- `float`
- `str`
- `bytes`
- `tuple`
- `list`
- `set`
- `frozenset`
- `dict`
- `@dataclass` objects
- `datetime` objects (`datetime`, `date`, `time` and `timedelta`)
- `uuid.UUID`
- Picklable objects (e.g. those that implement `__getstate__()`)
- `type` objects (by their full qualified name)

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "stablehash",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": "dataclasses, hash, hashlib, python hashing, stable hash",
    "author": null,
    "author_email": "Niklas Rosenstein <rosensteinniklas@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/85/70/a389e88d4c45c8f07a35096f5076451d1aac54ef949edcf93a6bb53d8802/stablehash-0.2.2.tar.gz",
    "platform": null,
    "description": "# stablehash\n\nThe `stablehash` module provides a \"pure\" hash function that is stable across Python processes and runs. This is in\ncontrast to the builtin `hash()` function, which may return a different value for the same input in separate\ninvokations even with the Python version.\n\nWe support most Python built-in types, including mutable types such as `list` and `dict`, as well as dataclasses. The\ndefault internal hash algorithm is Blake2b, but this can be changed by passing a different `hashlib` algorithm to the\n`stablehash` function.\n\n## Usage\n\n```python\nfrom stablehash import stablehash\n\nassert stablehash({\"key\": \"value\"}, algorithm=\"md5\").hexdigest() == 'd5994850379366e314563ea555532052'\n```\n\n## API\n\n### `stablehash(obj=..., *, algorithm=\"blake2b\")`\n\nReturns a `hashlib`-compatible object with the given algorithm and the hash of the given object. The algorithm must be\none of the algorithms supported by `hashlib`.\n\n### `stablehash.update(obj)`\n\nUpdates the hash with the given object. If the object is not supported, a `TypeError` is raised.\n\n### `stablehash.digest()`\n\nReturns the digest of the hash as a bytes object.\n\n### `stablehash.hexdigest()`\n\nReturns the digest of the hash as a string object.\n\n## Supported types\n\nThe following types are supported:\n\n- `None`\n- `bool`\n- `int`\n- `float`\n- `str`\n- `bytes`\n- `tuple`\n- `list`\n- `set`\n- `frozenset`\n- `dict`\n- `@dataclass` objects\n- `datetime` objects (`datetime`, `date`, `time` and `timedelta`)\n- `uuid.UUID`\n- Picklable objects (e.g. those that implement `__getstate__()`)\n- `type` objects (by their full qualified name)\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Stable hashing of Python data structures across separate processes and platforms.",
    "version": "0.2.2",
    "project_urls": {
        "Issues": "https://github.com/NiklasRosenstein/python-stablehash/issues",
        "Repository": "https://github.com/NiklasRosenstein/python-stablehash"
    },
    "split_keywords": [
        "dataclasses",
        " hash",
        " hashlib",
        " python hashing",
        " stable hash"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "9ea844b37356ed70f83f8c6337be18fc9fb40495581ce3e7f55c8111948a57eb",
                "md5": "30edbb09e2f05f48c43774fc067ebbc5",
                "sha256": "4dea2fb05a2f3191925d7a9053a5b36b6e4d78a3909548ace1ecf8b85fbbdbbe"
            },
            "downloads": -1,
            "filename": "stablehash-0.2.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "30edbb09e2f05f48c43774fc067ebbc5",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 6042,
            "upload_time": "2025-07-09T15:47:08",
            "upload_time_iso_8601": "2025-07-09T15:47:08.346159Z",
            "url": "https://files.pythonhosted.org/packages/9e/a8/44b37356ed70f83f8c6337be18fc9fb40495581ce3e7f55c8111948a57eb/stablehash-0.2.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "8570a389e88d4c45c8f07a35096f5076451d1aac54ef949edcf93a6bb53d8802",
                "md5": "b2b18e9047a5e82bc7ab1e84504213ad",
                "sha256": "7789e5f41c22b04a00f02f59ef3e1915fbee1e64aca23c782d7d4b07fb54193b"
            },
            "downloads": -1,
            "filename": "stablehash-0.2.2.tar.gz",
            "has_sig": false,
            "md5_digest": "b2b18e9047a5e82bc7ab1e84504213ad",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 15382,
            "upload_time": "2025-07-09T15:47:09",
            "upload_time_iso_8601": "2025-07-09T15:47:09.544814Z",
            "url": "https://files.pythonhosted.org/packages/85/70/a389e88d4c45c8f07a35096f5076451d1aac54ef949edcf93a6bb53d8802/stablehash-0.2.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-07-09 15:47:09",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "NiklasRosenstein",
    "github_project": "python-stablehash",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "stablehash"
}
        
Elapsed time: 1.39317s