Dictionary that automatically adds children dictionaries as necessary. Including a json based serialization and deserialization.
List of dependencies for package to run.
- None
- None
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 .
>>> 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"
}
}
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
Code development of this project adheres to Google Python Guide
Use yapf
to format files, based on Google's guide with the exception of indents being 2 spaces.
Versioning of this projects adheres to Semantic Versioning and is implemented using git tags.