linkeddeepdict


Namelinkeddeepdict JSON
Version 1.1.0 PyPI version JSON
download
home_pagehttps://github.com/dewloosh/LinkedDeepDict
SummaryLinked Deep Dictionaries in Python.
upload_time2023-05-07 16:42:34
maintainer
docs_urlNone
authorBence Balogh
requires_python>=3.7, <3.11
license
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/dewloosh/LinkedDeepDict/main?labpath=examples%2Fbasics.ipynb?urlpath=lab)
[![CircleCI](https://circleci.com/gh/dewloosh/LinkedDeepDict.svg?style=shield)](https://circleci.com/gh/dewloosh/LinkedDeepDict) 
[![Documentation Status](https://readthedocs.org/projects/LinkedDeepDict/badge/?version=latest)](https://LinkedDeepDict.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/LinkedDeepDict.svg)](https://pypi.org/project/LinkedDeepDict) 
 
# **LinkedDeepDict**

A Lightweight Python library to manage nested dictionaries with parent-child relationships.
On top of being a compatible drop-in replcement of the build in ``dict`` class, the self replicating default factory makes the creation of complex nested layouts effortless.

## **Documentation**

Click [here](https://linkeddeepdict.readthedocs.io/en/latest/) to read the documentation.

## **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 linkeddeepdict
```

## **Usage**

In every case where you'd want to use a `dict`, you can use a `LinkedDeepDict` as a drop-in replacement, but on top of what a simple dictionary provides, a `LinkedDeepDict` is more capable, as it provides a machinery to handle nested layouts. It is basically an ordered `defaultdict` with a self replicating default factory. 

```python
>>> from linkeddeepdict import LinkedDeepDict
>>> data = LinkedDeepDict()
```

A `LinkedDeepDict` is essentially a nested default dictionary. Being nested refers to the fact that you can do this:

```python
>>> data['a']['b']['c']['e'] = 1
>>> data['a']['b']['d'] = 2
```

Notice that the object carves a way up until the last key, without needing to create each level explicitly. What happens is that every time a key is missing in a `data`, the object creates a new instance, which then is also ready to handle missing keys or data. Accessing nested subdictionaries works in a similar fashion:

```python
>>> data['a']['b']['c']['e']
1
```
To allow for a more Pythonic feel, it also supports array-like indexing, so that the following operations are valid: 

```python
>>> data['a', 'b', 'c', 'e'] = 3
>>> data['a', 'b', 'c', 'e']
3
```

Of course, this is something that we can easily replicate using pure Python in one line, without the need for fancy stuff:

```python
>>> data = {'a' : {'b' : {'c' : {'e' : 3}, 'd' : 2}}}    
```

The key point is that we loop over a pure `dict` instance, we get

```python
>>> [k for k in data.keys()]
['a']    
```

But if we use a `LinkedDeepDict` class and the option `deep=True` when accessing
keys, values or items of dictionaries, the following happens: 

```python
>>> [k for k in LinkedDeepDict(data).keys(deep=True)]
['e', 'd']    
```

We can see, that in this case, iteration goes over keys, that actually hold on to some data, and does not return the containers themselves. If we do the same experiment with the values, it shows that the `LinkedDeepDict` only returns the leafs of the data-tree and the behaviour is fundamentally different:

```python
>>> [k for k in data.values()]
[{'b': {'c': {'e': 3}, 'd': 2}}]    
```

```python
>>> [k for k in LinkedDeepDict(data).values(deep=True)]
[3, 2]    
```

It is important, that the call `obj.values(deep=True)` still returns a generator object, which makes it memory efficient when looping over large datasets.

```python
>>> LinkedDeepDict(data).values(deep=True)
<generator object OrderedDefaultDict.values at 0x0000028F209D54A0>    
```

## **Testing**

To run all tests, open up a console in the root directory of the project and type the following

```console
>>> python -m unittest
```

## **Dependencies**

The only dependency is `six`, to provide basic continuity between major Python versions 2 and 3.

## **License**

This package is licensed under the MIT license.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/dewloosh/LinkedDeepDict",
    "name": "linkeddeepdict",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7, <3.11",
    "maintainer_email": "",
    "keywords": "",
    "author": "Bence Balogh",
    "author_email": "benceeok@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/34/8f/21a617a363e2a9011612f64b2117856affcbc57d7e41e6d1411c084a6d7b/linkeddeepdict-1.1.0.tar.gz",
    "platform": null,
    "description": "[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/dewloosh/LinkedDeepDict/main?labpath=examples%2Fbasics.ipynb?urlpath=lab)\n[![CircleCI](https://circleci.com/gh/dewloosh/LinkedDeepDict.svg?style=shield)](https://circleci.com/gh/dewloosh/LinkedDeepDict) \n[![Documentation Status](https://readthedocs.org/projects/LinkedDeepDict/badge/?version=latest)](https://LinkedDeepDict.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/LinkedDeepDict.svg)](https://pypi.org/project/LinkedDeepDict) \n \n# **LinkedDeepDict**\n\nA Lightweight Python library to manage nested dictionaries with parent-child relationships.\nOn top of being a compatible drop-in replcement of the build in ``dict`` class, the self replicating default factory makes the creation of complex nested layouts effortless.\n\n## **Documentation**\n\nClick [here](https://linkeddeepdict.readthedocs.io/en/latest/) to read the documentation.\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 linkeddeepdict\n```\n\n## **Usage**\n\nIn every case where you'd want to use a `dict`, you can use a `LinkedDeepDict` as a drop-in replacement, but on top of what a simple dictionary provides, a `LinkedDeepDict` is more capable, as it provides a machinery to handle nested layouts. It is basically an ordered `defaultdict` with a self replicating default factory. \n\n```python\n>>> from linkeddeepdict import LinkedDeepDict\n>>> data = LinkedDeepDict()\n```\n\nA `LinkedDeepDict` is essentially a nested default dictionary. Being nested refers to the fact that you can do this:\n\n```python\n>>> data['a']['b']['c']['e'] = 1\n>>> data['a']['b']['d'] = 2\n```\n\nNotice that the object carves a way up until the last key, without needing to create each level explicitly. What happens is that every time a key is missing in a `data`, the object creates a new instance, which then is also ready to handle missing keys or data. Accessing nested subdictionaries works in a similar fashion:\n\n```python\n>>> data['a']['b']['c']['e']\n1\n```\nTo allow for a more Pythonic feel, it also supports array-like indexing, so that the following operations are valid: \n\n```python\n>>> data['a', 'b', 'c', 'e'] = 3\n>>> data['a', 'b', 'c', 'e']\n3\n```\n\nOf course, this is something that we can easily replicate using pure Python in one line, without the need for fancy stuff:\n\n```python\n>>> data = {'a' : {'b' : {'c' : {'e' : 3}, 'd' : 2}}}    \n```\n\nThe key point is that we loop over a pure `dict` instance, we get\n\n```python\n>>> [k for k in data.keys()]\n['a']    \n```\n\nBut if we use a `LinkedDeepDict` class and the option `deep=True` when accessing\nkeys, values or items of dictionaries, the following happens: \n\n```python\n>>> [k for k in LinkedDeepDict(data).keys(deep=True)]\n['e', 'd']    \n```\n\nWe can see, that in this case, iteration goes over keys, that actually hold on to some data, and does not return the containers themselves. If we do the same experiment with the values, it shows that the `LinkedDeepDict` only returns the leafs of the data-tree and the behaviour is fundamentally different:\n\n```python\n>>> [k for k in data.values()]\n[{'b': {'c': {'e': 3}, 'd': 2}}]    \n```\n\n```python\n>>> [k for k in LinkedDeepDict(data).values(deep=True)]\n[3, 2]    \n```\n\nIt is important, that the call `obj.values(deep=True)` still returns a generator object, which makes it memory efficient when looping over large datasets.\n\n```python\n>>> LinkedDeepDict(data).values(deep=True)\n<generator object OrderedDefaultDict.values at 0x0000028F209D54A0>    \n```\n\n## **Testing**\n\nTo run all tests, open up a console in the root directory of the project and type the following\n\n```console\n>>> python -m unittest\n```\n\n## **Dependencies**\n\nThe only dependency is `six`, to provide basic continuity between major Python versions 2 and 3.\n\n## **License**\n\nThis package is licensed under the MIT license.\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Linked Deep Dictionaries in Python.",
    "version": "1.1.0",
    "project_urls": {
        "Download": "https://github.com/dewloosh/LinkedDeepDict/archive/refs/tags/1.1.0.zip",
        "Homepage": "https://github.com/dewloosh/LinkedDeepDict"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8f3c202f6aa0d0566d647280ceff9b18b30f49098be7a754c7d24cc3b4231dc8",
                "md5": "62f6cc49b00ebd8e207463731298446c",
                "sha256": "7c076e7feedeea7356276f1dabc07b94f014349b3aba7ee225a56eb8d9011288"
            },
            "downloads": -1,
            "filename": "linkeddeepdict-1.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "62f6cc49b00ebd8e207463731298446c",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7, <3.11",
            "size": 9225,
            "upload_time": "2023-05-07T16:42:33",
            "upload_time_iso_8601": "2023-05-07T16:42:33.082898Z",
            "url": "https://files.pythonhosted.org/packages/8f/3c/202f6aa0d0566d647280ceff9b18b30f49098be7a754c7d24cc3b4231dc8/linkeddeepdict-1.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "348f21a617a363e2a9011612f64b2117856affcbc57d7e41e6d1411c084a6d7b",
                "md5": "e0d31af45ebc5d2c96713b0509615bff",
                "sha256": "9c65bc34c110ea1a2071a411f6481485d4a5da9da029996ead8aca2c39288609"
            },
            "downloads": -1,
            "filename": "linkeddeepdict-1.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "e0d31af45ebc5d2c96713b0509615bff",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7, <3.11",
            "size": 11611,
            "upload_time": "2023-05-07T16:42:34",
            "upload_time_iso_8601": "2023-05-07T16:42:34.913525Z",
            "url": "https://files.pythonhosted.org/packages/34/8f/21a617a363e2a9011612f64b2117856affcbc57d7e41e6d1411c084a6d7b/linkeddeepdict-1.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-05-07 16:42:34",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "dewloosh",
    "github_project": "LinkedDeepDict",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "circle": true,
    "requirements": [],
    "tox": true,
    "lcname": "linkeddeepdict"
}
        
Elapsed time: 0.17848s