stablehash


Namestablehash JSON
Version 0.1.1 PyPI version JSON
download
home_page
SummaryStable hashing of Python data structures spanning invokations and platforms.
upload_time2024-01-29 01:39:03
maintainer
docs_urlNone
authorNiklas Rosenstein
requires_python>=3.10,<4.0
licenseMIT
keywords hash stable hash hashlib dataclasses python hashing
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__()`)


            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "stablehash",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.10,<4.0",
    "maintainer_email": "",
    "keywords": "hash,stable hash,hashlib,dataclasses,python hashing",
    "author": "Niklas Rosenstein",
    "author_email": "niklas.rosenstein@helsing.ai",
    "download_url": "https://files.pythonhosted.org/packages/3e/c4/c6e8cdc8d5f059dace950af5734889a384719671d21f3a07ce21220e471e/stablehash-0.1.1.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 contrast to the builtin `hash()` function, which may return a different value for the same input in separate invokations 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 default internal hash algorithm is Blake2b, but this can be changed by passing a different `hashlib` algorithm to the `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 one 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\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Stable hashing of Python data structures spanning invokations and platforms.",
    "version": "0.1.1",
    "project_urls": {
        "Bug Tracker": "https://github.com/NiklasRosenstein/python-stablehash/issues",
        "Repository": "https://github.com/NiklasRosenstein/python-stablehash"
    },
    "split_keywords": [
        "hash",
        "stable hash",
        "hashlib",
        "dataclasses",
        "python hashing"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5274151efa3a6b14eae811625460f88afa9fcaa28cee3c7ca88898dd18477628",
                "md5": "9aa1186def18b57954b53d5aedaa06b3",
                "sha256": "edf06d8ba3684c5678aa618c3ceef81abbd64a7d1e50a2d55336b543e9758859"
            },
            "downloads": -1,
            "filename": "stablehash-0.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9aa1186def18b57954b53d5aedaa06b3",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10,<4.0",
            "size": 5550,
            "upload_time": "2024-01-29T01:39:01",
            "upload_time_iso_8601": "2024-01-29T01:39:01.886156Z",
            "url": "https://files.pythonhosted.org/packages/52/74/151efa3a6b14eae811625460f88afa9fcaa28cee3c7ca88898dd18477628/stablehash-0.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3ec4c6e8cdc8d5f059dace950af5734889a384719671d21f3a07ce21220e471e",
                "md5": "3f1b860598a164810639392e8ffb3fb5",
                "sha256": "9d2826aa9e3c22f13ae642bce7d73c0de802eb2b925da538f871979d724cd2ed"
            },
            "downloads": -1,
            "filename": "stablehash-0.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "3f1b860598a164810639392e8ffb3fb5",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10,<4.0",
            "size": 4822,
            "upload_time": "2024-01-29T01:39:03",
            "upload_time_iso_8601": "2024-01-29T01:39:03.286100Z",
            "url": "https://files.pythonhosted.org/packages/3e/c4/c6e8cdc8d5f059dace950af5734889a384719671d21f3a07ce21220e471e/stablehash-0.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-01-29 01:39:03",
    "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: 0.17483s