Lazy dict with universaly unique identified values
Project description
ldict
Uniquely identified lazy dict.
Installation
as a standalone lib.
# Set up a virtualenv.
python3 -m venv venv
source venv/bin/activate
# Install from PyPI...
pip install --upgrade pip
pip install -U ldict
# ...or, install from updated source code.
pip install git+https://github.com/davips/ldict
from source
git clone https://github.com/davips/ldict
cd ldict
poetry install
Examples
Merging two ldicts
from ldict import ldict
a = ldict(x=3)
print(a)
"""
{
"id": "000000000000000000000dCguKC6bS.95Bqe35gNJir04CxRv6dY1dPRO7R3PTKa",
"ids": "<1 hidden id>",
"x": 3
}
"""
b = ldict(y=5)
print(b)
"""
{
"id": "000000000000000000000dlrfIktAZFYqwNrmOdFDZKV966TGLM7hu0fllFfC8Kt",
"ids": "<1 hidden id>",
"y": 5
}
"""
print(a + b)
"""
{
"id": "000000000000000000000aXHKqWzMQIMw6bFpTur11RVdIEJ9SLzyXQ57tuiIAfV",
"ids": "<1 hidden ids>",
"x": 3,
"y": 5
}
"""
Features (current or planned)
How to use [outdated]
Two main entities are identifiable: processing functions and bags of values. A processing function is any callable the follows the rules below. A bag of values is a ldict object. It is a mapping between string keys, called fields, and any serializable object. The bag id (identifier) and the field ids are also part of the mapping.
The user should provide a unique identifier for each function object. It should be put as a 43 digits long base-62 string under the key "_id", or, alternatively, a Hosh object inside the returned dict, under the key "_id". The only exception is when using the assignment syntax, because the return value is the proper result of the calculation. When using the assignment syntax, it is assumed the 'id' should be automatically calculated by the bytecode obtained through source code parsing. For this reason, such functions should be simple, i.e., with minimal external dependencies, to avoid the unfortunate situation where two functions with identical local code actually perform different calculations through calls to external code that implement different algorithms with the same name.
One way to emulate such behavior for the function application syntax (a >> f) is to
explicitly refuse to provide a hash/id.
This can be done by setting "_id": None
inside the returned dictionary.
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
Hashes for ldict-2.210815.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 95d82f79c881445afb20ada0ad5fe9639f65e8efd0aacf7fed087151b612133d |
|
MD5 | 302afafda903056a402b63f83a34d367 |
|
BLAKE2b-256 | f8ae6cd7027645d9c9e4e6cac470d25f9a9eaf4ad76460eca782b57513b5a1e6 |