Skip to main content

Dictionary that automatically adds children dictionaries as necessary

Project description

AutoDict

Unit Test Pylint Coverage Latest Version

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

AutoDict-2.0.0.tar.gz (11.2 kB view hashes)

Uploaded Source

Built Distribution

AutoDict-2.0.0-py3-none-any.whl (19.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page