Dictionary that automatically adds children dictionaries as necessary
Project description
AutoDict
Dictionary that automatically adds children dictionaries as necessary. Including a json based serialization and deserialization.
Environment
List of dependencies for package to run.
Required
- None
Optional
- None
Installation / Build / Deployment
Install module
> python -m pip install autodict
For development, install as a link to repository such that code changes are used.
> python -m pip install -e .
Usage
>>> from autodict import AutoDict, JSONAutoDict
>>>
>>> d = AutoDict()
>>> print(d)
{}
>>> d["level0"]["level1"]["level2"]["level3"] = "value"
>>> print(d)
{'level0': {'level1': {'level2': {'level3': 'value'}}}}
>>>
>>> with JSONAutoDict("autodict.json") as j:
... j["level0"]["level1"]["level2"]["level3"] = "value"
...
>>> print(open("autodict.json").read())
{
"__type__": "AutoDict",
"level0": {
"__type__": "AutoDict",
"level1": {
"__type__": "AutoDict",
"level2": {
"__type__": "AutoDict",
"level3": "value"
}
}
}
}
>>> with JSONAutoDict("autodict.json") as j:
... j["level0"]["key"] = "another value"
...
>>> print(open("autodict.json").read())
{
"__type__": "AutoDict",
"level0": {
"__type__": "AutoDict",
"level1": {
"__type__": "AutoDict",
"level2": {
"__type__": "AutoDict",
"level3": "value"
}
},
"key": "another value"
}
}
Running Tests
To run the automated tests, execute unittest discover
:
> python -m unittest discover tests -v
To run the automated tests with coverage, execute coverage run
:
> python -m coverage run
> python -m coverage report
Development
Code development of this project adheres to Google Python Guide
Styling
Use yapf
to format files, based on Google's guide with the exception of indents being 2 spaces.
Versioning
Versioning of this projects adheres to Semantic Versioning and is implemented using git tags.
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
Built Distribution
File details
Details for the file AutoDict-1.1.0.tar.gz
.
File metadata
- Download URL: AutoDict-1.1.0.tar.gz
- Upload date:
- Size: 6.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 45d243ecc35b0896b95cba0b020908fec12726bef2129a6ba59cc5b23478c49d |
|
MD5 | cbf737bc71293fad8d55f2b5742efc7d |
|
BLAKE2b-256 | b1960de8200f1da1125ee266a2d293f722c707510cff597038eec56f70fea980 |
File details
Details for the file AutoDict-1.1.0-py3-none-any.whl
.
File metadata
- Download URL: AutoDict-1.1.0-py3-none-any.whl
- Upload date:
- Size: 6.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dca5589676c88c47ab6cd3843c2cf26c15274054a0827463b52d549595fe78ff |
|
MD5 | 6fec570f29678d70c25a0d78ba0e6f9f |
|
BLAKE2b-256 | aec6135242f539b0057325fc685de18655e84e32a661450b852d7c8909a2eebb |