A dictionary that can be flattened and re-inflated
Project description
deflatable-dict
A dictionary that can be flattened and re-inflated. Particularly useful if you're interacting with yaml, for example.
Installation
with pip:
pip install deflatable-dict
deflatable-dict
does not have any dependencies beyond standard python libraries.
Instantiation
from deflatabledict import DeflatableDict
dd = DeflatableDict({
"a": {
"1": True,
"2": False,
},
"b": 20,
})
dd["a.1"] # True
dd["a.2"] # False
dd["b"] # 20
dd["a"] # { "1": True, "2": False }
Deflation
A DeflatableDict can be deflated with .deflate()
. This returns a standard dictionary object with flattened keys constructed by concatenating the nested keys with the DeflatableDict's delimiter. A DeflatableDict uses it's deflated form for its string representation.
Delimiter
A DeflatableDict can have it's delimiter specified by passing the desired delimiter as the sep
parameter to the DeflatableDict constructor. By default the delimiter if .
.
Inflation
A DeflatableDict will automatically inflate any values that are inserted into it. For example:
from deflatabledict import DeflatableDict
dd = DeflatableDict()
dd["a.1"] = True
dd["a.2"] = False
dd["a"] # { "1": True, "2": False }
Development
This project uses .devcontainer
to describe the environment to use for development. You may use the environment described in this directory (it integrates automatically with vscode's 'remote containers' extension), or you may create your own environment with the same dependencies.
Dependencies
Install development dependencies with:
pip install .[tests]
Tests
Run tests with:
pytest
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 deflatable_dict-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 315c8f9990192774033f9749c9748ddbda90fec710db0034c9844235b16c2ee5 |
|
MD5 | 8fb441c6a3f7378cb8ce339a3497a03b |
|
BLAKE2b-256 | 4a5f6968e154b93374e49b52e389ad168d32fcea9704a3f2e9d1b2af8fd3aeb1 |