Skip to main content

Simple python tool to hash dictionaries using both default hash and sha256.

Project description

Travis CI build SonarCloud Quality SonarCloud Maintainability Codacy Maintainability Maintainability Pypi project Pypi total project downloads

Simple python tool to hash dictionaries using both default hash and sha256. The library comes with full support for hashing pandas dataframes and numpy arrays.

How do I install this package?

As usual, just download it using pip:

pip install dict_hash

Tests Coverage

Since some software handling coverages sometimes get slightly different results, here’s three of them:

Coveralls Coverage SonarCloud Coverage Code Climate Coverate

Usage examples

The package offers two functions: sha256 to generate constant sha256 hashes and dict_hash, to generate hashes using the native hash function.

Session hash with dict_hash

Obtain a session hash from the given dictionary.

from dict_hash import dict_hash
from random_dict import random_dict
from random import randint

d = random_dict(randint(1, 10), randint(1, 10))
my_hash = dict_hash(d)

Consistent hash with sha256

Obtain a consistent hash from the given dictionary.

from dict_hash import sha256
from random_dict import random_dict
from random import randint

d = random_dict(randint(1, 10), randint(1, 10))
my_hash = sha256(d)

Hashable

When handling complex objects within the dictionaries, you may need to implement the class Hashable in that object.

Here is an example:

from dict_hash import Hashable, sha256


class MyHashable(Hashable):

    def __init__(self, a: int):
        self._a = a
        self._time = time()

    def consistent_hash(self) -> str:
        return sha256({
            "a": self._a
        })

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dict_hash-1.1.11.tar.gz (4.9 kB view details)

Uploaded Source

File details

Details for the file dict_hash-1.1.11.tar.gz.

File metadata

  • Download URL: dict_hash-1.1.11.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0.post20200210 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.6

File hashes

Hashes for dict_hash-1.1.11.tar.gz
Algorithm Hash digest
SHA256 63aa28f650772e2e6420b9c46bd1b66e8a49e1606060d4f3bb746f21b6409765
MD5 c48f6b21c0bb078ed5d7f84f731ca4f1
BLAKE2b-256 b71690c6c3d0c39b61640a1114fda8a182f364482fccd7bd4e233ddd26093265

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page