sigmaepsilon.deepdict


Namesigmaepsilon.deepdict JSON
Version 1.2.4 PyPI version JSON
download
home_pagehttps://github.com/sigma-epsilon/sigmaepsilon.deepdict
SummaryCommon developer utilities for Python projects.
upload_time2024-02-20 06:48:16
maintainerBence Balogh
docs_urlNone
authorBence Balogh
requires_python>=3.10,<4.0
licenseMIT
keywords data structures dictionary python tree
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            # **SigmaEpsilon.DeepDict** - A lightweight Python library to handle nested dictionaries

[![CircleCI](https://dl.circleci.com/status-badge/img/gh/sigma-epsilon/sigmaepsilon.deepdict/tree/main.svg?style=shield)](https://dl.circleci.com/status-badge/redirect/gh/sigma-epsilon/sigmaepsilon.deepdict/tree/main)
[![codecov](https://codecov.io/gh/sigma-epsilon/sigmaepsilon.deepdict/graph/badge.svg?token=7JKJ3HHSX3)](https://codecov.io/gh/sigma-epsilon/sigmaepsilon.deepdict)
[![Documentation Status](https://readthedocs.org/projects/sigmaepsilondeepdict/badge/?version=latest)](https://sigmaepsilondeepdict.readthedocs.io/en/latest/?badge=latest)
[![License](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![PyPI](https://badge.fury.io/py/sigmaepsilon.deepdict.svg)](https://pypi.org/project/sigmaepsilon.deepdict)
[![Python 3.7‒3.10](https://img.shields.io/badge/python-3.7%E2%80%923.10-blue)](https://www.python.org)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![Requirements Status](https://dependency-dash.repo-helper.uk/github/sigma-epsilon/sigmaepsilon.deepdict/badge.svg)](https://dependency-dash.repo-helper.uk/github/sigma-epsilon/sigmaepsilon.deepdict)

The `DeepDict` class works very similarly to a regular `dict`, but makes life easier in sutiations where there are nested levels, especially when such dictionary is to be created dynamically.

## Motivating examples

Consider the following simple dictionary

```python
>>> d = {
...   "a" : {"aa" : 1},
...   "b" : 2,
...   "c" : {"cc" : {"ccc" : 3}}, 
... }
```

This is what happens when you iterate through the values of it:

```python
>>> list(d.values())
[{'aa': 1}, 2, {'cc': {'ccc': 3}}]
```

If you wrap it as a `DeepDict`:

```python
>>> from sigmaepsilon.deepdict import DeepDict
>>> dd = DeepDict.wrap(d)
>>> list(dd.values(deep=True))
[1, 2, 3]
```

The class supports array-like indexing, which combined with the default factory creates the possibility to create deep levels without having to create all the parents:

```python
>>> data = DeepDict()
>>> data["a", 0, "b", 1, 5] = 10
```

Each subdirectory is aware about it's parent container

```python
>>> data["a", 0, "b"].key
"b"
```

```python
>>> data["a", 0, "b"].address
['a', 0, 'b']
```

```python
>>> data["a", 0, "b"].parent.key
0
```

Given that the `asciitree` library is installed, it is also possible to print dictionaries (any kind) as a tree:

```python
>>> from sigmaepsilon.deepdict import asciiprint
>>> d = {
...     "a" : {"aa" : 1},
...     "b" : 2,
...     "c" : {"cc" : {"ccc" : 3}},
... }
>>> data = DeepDict.wrap(d)
>>> data.name = "Data"
>>> asciiprint(data)
Data
    +-- a
    +-- c
        +-- cc
```

See the documentation for more examples and explanation on behaviour.

## **Documentation**

The [documentation](https://sigmaepsilondeepdict.readthedocs.io/en/latest/) is built with [Sphinx](https://www.sphinx-doc.org/en/master/) using the [PyData Sphinx Theme](https://pydata-sphinx-theme.readthedocs.io/en/stable/index.html) and hosted on [ReadTheDocs](https://readthedocs.org/).

## **Installation**

This is optional, but we suggest you to create a dedicated virtual enviroment at all times to avoid conflicts with your other projects. Create a folder, open a command shell in that folder and use the following command

```console
>>> python -m venv venv_name
```

Once the enviroment is created, activate it via typing

```console
>>> .\venv_name\Scripts\activate
```

The library can be installed (either in a virtual enviroment or globally) from PyPI using `pip` on Python >= 3.7:

```console
>>> pip install sigmaepsilon.deepdict
```

## **License**

This package is licensed under the [MIT license](LICENSE.txt).

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/sigma-epsilon/sigmaepsilon.deepdict",
    "name": "sigmaepsilon.deepdict",
    "maintainer": "Bence Balogh",
    "docs_url": null,
    "requires_python": ">=3.10,<4.0",
    "maintainer_email": "bencebalogh@sigmaepsilon.com",
    "keywords": "data structures,dictionary,Python,tree",
    "author": "Bence Balogh",
    "author_email": "bencebalogh@sigmaepsilon.com",
    "download_url": "https://files.pythonhosted.org/packages/38/29/8bbf7a868def1d017064488d44a6b1f32fe84ad6d2adecc90068059a3a21/sigmaepsilon_deepdict-1.2.4.tar.gz",
    "platform": null,
    "description": "# **SigmaEpsilon.DeepDict** - A lightweight Python library to handle nested dictionaries\n\n[![CircleCI](https://dl.circleci.com/status-badge/img/gh/sigma-epsilon/sigmaepsilon.deepdict/tree/main.svg?style=shield)](https://dl.circleci.com/status-badge/redirect/gh/sigma-epsilon/sigmaepsilon.deepdict/tree/main)\n[![codecov](https://codecov.io/gh/sigma-epsilon/sigmaepsilon.deepdict/graph/badge.svg?token=7JKJ3HHSX3)](https://codecov.io/gh/sigma-epsilon/sigmaepsilon.deepdict)\n[![Documentation Status](https://readthedocs.org/projects/sigmaepsilondeepdict/badge/?version=latest)](https://sigmaepsilondeepdict.readthedocs.io/en/latest/?badge=latest)\n[![License](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![PyPI](https://badge.fury.io/py/sigmaepsilon.deepdict.svg)](https://pypi.org/project/sigmaepsilon.deepdict)\n[![Python 3.7\u20123.10](https://img.shields.io/badge/python-3.7%E2%80%923.10-blue)](https://www.python.org)\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n[![Requirements Status](https://dependency-dash.repo-helper.uk/github/sigma-epsilon/sigmaepsilon.deepdict/badge.svg)](https://dependency-dash.repo-helper.uk/github/sigma-epsilon/sigmaepsilon.deepdict)\n\nThe `DeepDict` class works very similarly to a regular `dict`, but makes life easier in sutiations where there are nested levels, especially when such dictionary is to be created dynamically.\n\n## Motivating examples\n\nConsider the following simple dictionary\n\n```python\n>>> d = {\n...   \"a\" : {\"aa\" : 1},\n...   \"b\" : 2,\n...   \"c\" : {\"cc\" : {\"ccc\" : 3}}, \n... }\n```\n\nThis is what happens when you iterate through the values of it:\n\n```python\n>>> list(d.values())\n[{'aa': 1}, 2, {'cc': {'ccc': 3}}]\n```\n\nIf you wrap it as a `DeepDict`:\n\n```python\n>>> from sigmaepsilon.deepdict import DeepDict\n>>> dd = DeepDict.wrap(d)\n>>> list(dd.values(deep=True))\n[1, 2, 3]\n```\n\nThe class supports array-like indexing, which combined with the default factory creates the possibility to create deep levels without having to create all the parents:\n\n```python\n>>> data = DeepDict()\n>>> data[\"a\", 0, \"b\", 1, 5] = 10\n```\n\nEach subdirectory is aware about it's parent container\n\n```python\n>>> data[\"a\", 0, \"b\"].key\n\"b\"\n```\n\n```python\n>>> data[\"a\", 0, \"b\"].address\n['a', 0, 'b']\n```\n\n```python\n>>> data[\"a\", 0, \"b\"].parent.key\n0\n```\n\nGiven that the `asciitree` library is installed, it is also possible to print dictionaries (any kind) as a tree:\n\n```python\n>>> from sigmaepsilon.deepdict import asciiprint\n>>> d = {\n...     \"a\" : {\"aa\" : 1},\n...     \"b\" : 2,\n...     \"c\" : {\"cc\" : {\"ccc\" : 3}},\n... }\n>>> data = DeepDict.wrap(d)\n>>> data.name = \"Data\"\n>>> asciiprint(data)\nData\n    +-- a\n    +-- c\n        +-- cc\n```\n\nSee the documentation for more examples and explanation on behaviour.\n\n## **Documentation**\n\nThe [documentation](https://sigmaepsilondeepdict.readthedocs.io/en/latest/) is built with [Sphinx](https://www.sphinx-doc.org/en/master/) using the [PyData Sphinx Theme](https://pydata-sphinx-theme.readthedocs.io/en/stable/index.html) and hosted on [ReadTheDocs](https://readthedocs.org/).\n\n## **Installation**\n\nThis is optional, but we suggest you to create a dedicated virtual enviroment at all times to avoid conflicts with your other projects. Create a folder, open a command shell in that folder and use the following command\n\n```console\n>>> python -m venv venv_name\n```\n\nOnce the enviroment is created, activate it via typing\n\n```console\n>>> .\\venv_name\\Scripts\\activate\n```\n\nThe library can be installed (either in a virtual enviroment or globally) from PyPI using `pip` on Python >= 3.7:\n\n```console\n>>> pip install sigmaepsilon.deepdict\n```\n\n## **License**\n\nThis package is licensed under the [MIT license](LICENSE.txt).\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Common developer utilities for Python projects.",
    "version": "1.2.4",
    "project_urls": {
        "Documentation": "https://sigmaepsilondeepdict.readthedocs.io/en/latest/?badge=latest",
        "Homepage": "https://github.com/sigma-epsilon/sigmaepsilon.deepdict",
        "Repository": "https://github.com/sigma-epsilon/sigmaepsilon.deepdict"
    },
    "split_keywords": [
        "data structures",
        "dictionary",
        "python",
        "tree"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "55a94c1e516d50e0db6c6505fa3aed685402cc688a308aaee0884c55349e5644",
                "md5": "a6a1e03f83e1472cd3a0b438d933b89a",
                "sha256": "85061c7ba21b7723431da6b47a486116647936b3775b942c09d848a36991b54b"
            },
            "downloads": -1,
            "filename": "sigmaepsilon_deepdict-1.2.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a6a1e03f83e1472cd3a0b438d933b89a",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10,<4.0",
            "size": 10097,
            "upload_time": "2024-02-20T06:48:15",
            "upload_time_iso_8601": "2024-02-20T06:48:15.353546Z",
            "url": "https://files.pythonhosted.org/packages/55/a9/4c1e516d50e0db6c6505fa3aed685402cc688a308aaee0884c55349e5644/sigmaepsilon_deepdict-1.2.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "38298bbf7a868def1d017064488d44a6b1f32fe84ad6d2adecc90068059a3a21",
                "md5": "4f1c474c329f8946486ea4cb54d4b6b2",
                "sha256": "a3f7b26d6ee258796bda7b33bd39a296ab18e7f7ea10b8053e5f5a05e0814ec0"
            },
            "downloads": -1,
            "filename": "sigmaepsilon_deepdict-1.2.4.tar.gz",
            "has_sig": false,
            "md5_digest": "4f1c474c329f8946486ea4cb54d4b6b2",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10,<4.0",
            "size": 10347,
            "upload_time": "2024-02-20T06:48:16",
            "upload_time_iso_8601": "2024-02-20T06:48:16.335634Z",
            "url": "https://files.pythonhosted.org/packages/38/29/8bbf7a868def1d017064488d44a6b1f32fe84ad6d2adecc90068059a3a21/sigmaepsilon_deepdict-1.2.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-20 06:48:16",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "sigma-epsilon",
    "github_project": "sigmaepsilon.deepdict",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": false,
    "circle": true,
    "requirements": [],
    "tox": true,
    "lcname": "sigmaepsilon.deepdict"
}
        
Elapsed time: 0.18598s