Python library of hashing and caching
Project description
Memoria
Memoria is a Python library for hashing and caching.
Installation
pip install memoria
Benefits of Memoria
Consistency
Unfortunately the built-in hash method is not consistent.
For example if you hash a string in two different Python sessions,
e.g., hash('hello world!')
, you may get different results, e.g., -69600567246316219
or
-8701498716516122875
. However, Memoria is consistent, e.g.,
memoria.hash('hello world!')
produces PwDVM4wattDXKR1HUtszcPP5BHTUVTYQ5X0cO51yAn4=
.
We should credit the built-in library hashlib of course.
Hashing Unhashable Types
Memoria can hash virtually anything. If you use the built-in
hash method hash(dict())
or hash(list())
you will get an error:
TypeError: unhashable type: 'dict'
but Memoria can even hash
unhashable types by converting them into a hashable type and
hashing the result. To make sure that the hash is still different between
the original type and the hashable representation, Memoria takes some
additional measures.
Usage
import memoria
# hashing a python object
memoria.hash(123)
# >>> 'zi+wk24s9wwA/UiNRKbjeu6JfDi78yCj7yVL87sS0Ko='
# base is 64 by default but 32 can also be used.
# base 64 should not be used in the file-system, e.g., file names, because it has inadmissible characters.
memoria.hash(123, base=32)
# >>> 'PONR14RE5JRGO07T926K99N3FBN8IV1ONFPI18VF4L5V7EOIQ2L0----'
# dictionaries are unhashable but Memoria can hash them
memoria.hash({'name': 'John', 'age': 24})
# >>> 'ioCMz5B8pcdk2CxcbIX/3n3qnQRn/yv9/zvC5Wc0YlU='
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file memoria-2021.6.30.1.tar.gz
.
File metadata
- Download URL: memoria-2021.6.30.1.tar.gz
- Upload date:
- Size: 7.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.9.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2d99def5f06fc904effc12cd001d2af65e709196577d3e0a2e87fd32efa590ae |
|
MD5 | d1946bd022ab6dc48319731b088079be |
|
BLAKE2b-256 | 9340bf482b27bc68c9cbc8ac75ced977e06018aef6cd96e71ccf0995d2ab8e5c |
File details
Details for the file memoria-2021.6.30.1-py3-none-any.whl
.
File metadata
- Download URL: memoria-2021.6.30.1-py3-none-any.whl
- Upload date:
- Size: 7.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.9.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 481b282b5270d71a96645b5b00350c086f9ca198e61e6b79618b41d2a6577cd5 |
|
MD5 | e2bed8dbc5ad4e053a999830a8244b64 |
|
BLAKE2b-256 | ec239cd36fbc0e3db788a848bdbfc2fce9548869421940f5c92061e88953495d |