A dictionary-like class that allows keys to have multiple names.
Project description
What is it
A set of dictionary classes that allow an aliasing of keys to other keys consistently, and a follow up implementation that does the same thing without concern for the case of string keys while preserving case for output and iteration.
Neither implementation assumes string keys, so anything Hashable
should remain compatible for all keys in the API.
It's still directly comparable (==
, in
, .get()
, etc) and access compatible with dict()
, and offers a mild framework for implementing key-transforming dictionaries somewhat painlessly with a decent test backing.
Does it work?
Yes, check this out.
from mmdict import MultiDict
data = {"test": "ok"}
alternatives = {"test": ["also", "as well"]}
d = MultiDict(data, aliases=alternatives)
# True
d["also"] == "ok"
# True
d["as well"] == d["test"]
from mmdict import CaselessMultiDict
d = CaselessMultiDict({"Test": "not ok"})
# A super valid write, because we're a regular dict() right?
d["Test"] = "ok"
# Oh wow, `True`, because `"Test"` and `"test"` are caselessly the same
d["test"] == "ok"
# True, because, the case of the initial write is preserved for iteration
list(d.keys()) == ["Test"]
Development Setup
*nix
python -mvenv .venv
. .venv/bin/activate
PowerShell
python -mvenv .venv
.\.venv\Scripts\Activate.ps1
Then, for both platforms
python -m ensurepip --upgrade
python -m pip install --upgrade pip
pip install -e .
Running tests
With the virtual environment activated, use the multi-platform script to run the test suite.
script/test.sh.ps1
It's a very thin thin wrapper around bootstrapping the test run with python.
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 mmdict-0.0.1.tar.gz
.
File metadata
- Download URL: mmdict-0.0.1.tar.gz
- Upload date:
- Size: 4.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8eac6ac449086496cd54f8999aa922a6b48fc517ded3a1e29ffdd3e8192547cb |
|
MD5 | a8f465a194045e05166df22abb2e0afd |
|
BLAKE2b-256 | 0141b42b506f992ec25531e68aabeb9ad3db18a50fd46cfd008f78ad0a3978cf |
File details
Details for the file mmdict-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: mmdict-0.0.1-py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6e3e76eca79b93054ec1aac59e5cc4fabae63e9118ea1c67e017d69b4aa2ae40 |
|
MD5 | 7cc5c1e0c3bb6665dde58c5b3aa14adc |
|
BLAKE2b-256 | 62e150e4bb4928319211027ab619b377f4443350a9483f8640b7bad6db871c88 |