ndicts


Namendicts JSON
Version 0.3.0 PyPI version JSON
download
home_pagehttps://github.com/edd313/ndicts
SummaryClass to handle nested dictionaries
upload_time2023-01-04 13:00:28
maintainer
docs_urlNone
authorEdoardo Cicirello
requires_python>=3.8,<4.0
license
keywords nested dictionary
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Description
Nested dictionary structures emerge every time there is some sort hierarchy
in the data. Trees, archives, the chapters and sections in a book, 
these are all examples where you will likely find nested loops of data.

Python does not have a built-in data type for nested mappings. 
Dictionaries can be used, however there many inconveniences and limitations.
Two above all: getting items requires to open and close several square brackets 
(eg. `d[level1][level2]...[levelN]`), 
and iterating will only access the first layer, 
so nested for loops are needed to iterate through all the values.

The `ndicts` package aims to tackle the main issues of nested dictionaries, 
exposing an interface with minimum differences from dictionaries themselves.
`NestedDict` is a `MutableMapping` at its core, 
therefore all familiar dictionary methods are available 
and the overall behaviour similar.

If you need to perform simple mathematical operations with your nested data,
use `DataDict`. In addition to allowing arithmetics, 
`DataDicts` borrow some methods that you would expect from a `pandas` `DataFrame`. 

Finally, this is a simple project for simple needs. 
Consider using `pandas` `MultiIndex` for more functionalities!

# Installation

Install `ndicts` with `pip`.

```commandline
pip install ndicts
```

# Overview

Import `NestedDict` and `DataDict`.

```pycon
>>> from ndicts import DataDict, NestedDict
```

Create a `NestedDict` from a dictionary.

```pycon
>>> book = {
...     "Book 1": {
...         "Section 1": "The Eve of the War",
...         "Section 2": "The Falling Star"
...     },
...     "Book 2": {
...         "Section 1": "Under Foot", 
...         "Section 2": {"Paragraph 1": "After eating we crept back to the scullery"}
...     }
... }
>>> nd = NestedDict(book)
```

Get items more conveniently than with standard dictionaries.

```pycon
>>> # NestedDict
>>> nd["Book 1", "Section 1"] 
'The Eve of the War'
>>> # dict
>>> book["Book 1"]["Section 2"]
'The Falling Star'
```

Iterate over a `NestedDict`.

```pycon
>>> for key in nd:
...     print(key)
('Book 1', 'Section 1')
('Book 1', 'Section 2')
('Book 2', 'Section 1')
('Book 2', 'Section 2', 'Paragraph 1')
```

# Documentation

https://edd313.github.io/ndicts/

# Licence
`ndicts` is licensed under the MIT license.




            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/edd313/ndicts",
    "name": "ndicts",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8,<4.0",
    "maintainer_email": "",
    "keywords": "nested,dictionary",
    "author": "Edoardo Cicirello",
    "author_email": "e.cicirello@protonmail.com",
    "download_url": "https://files.pythonhosted.org/packages/be/6c/2d20b98d96a1c87a32014caffb7c873ee01ccc73fc515572affdaba7cf7a/ndicts-0.3.0.tar.gz",
    "platform": null,
    "description": "# Description\nNested dictionary structures emerge every time there is some sort hierarchy\nin the data. Trees, archives, the chapters and sections in a book, \nthese are all examples where you will likely find nested loops of data.\n\nPython does not have a built-in data type for nested mappings. \nDictionaries can be used, however there many inconveniences and limitations.\nTwo above all: getting items requires to open and close several square brackets \n(eg. `d[level1][level2]...[levelN]`), \nand iterating will only access the first layer, \nso nested for loops are needed to iterate through all the values.\n\nThe `ndicts` package aims to tackle the main issues of nested dictionaries, \nexposing an interface with minimum differences from dictionaries themselves.\n`NestedDict` is a `MutableMapping` at its core, \ntherefore all familiar dictionary methods are available \nand the overall behaviour similar.\n\nIf you need to perform simple mathematical operations with your nested data,\nuse `DataDict`. In addition to allowing arithmetics, \n`DataDicts` borrow some methods that you would expect from a `pandas` `DataFrame`. \n\nFinally, this is a simple project for simple needs. \nConsider using `pandas` `MultiIndex` for more functionalities!\n\n# Installation\n\nInstall `ndicts` with `pip`.\n\n```commandline\npip install ndicts\n```\n\n# Overview\n\nImport `NestedDict` and `DataDict`.\n\n```pycon\n>>> from ndicts import DataDict, NestedDict\n```\n\nCreate a `NestedDict` from a dictionary.\n\n```pycon\n>>> book = {\n...     \"Book 1\": {\n...         \"Section 1\": \"The Eve of the War\",\n...         \"Section 2\": \"The Falling Star\"\n...     },\n...     \"Book 2\": {\n...         \"Section 1\": \"Under Foot\", \n...         \"Section 2\": {\"Paragraph 1\": \"After eating we crept back to the scullery\"}\n...     }\n... }\n>>> nd = NestedDict(book)\n```\n\nGet items more conveniently than with standard dictionaries.\n\n```pycon\n>>> # NestedDict\n>>> nd[\"Book 1\", \"Section 1\"] \n'The Eve of the War'\n>>> # dict\n>>> book[\"Book 1\"][\"Section 2\"]\n'The Falling Star'\n```\n\nIterate over a `NestedDict`.\n\n```pycon\n>>> for key in nd:\n...     print(key)\n('Book 1', 'Section 1')\n('Book 1', 'Section 2')\n('Book 2', 'Section 1')\n('Book 2', 'Section 2', 'Paragraph 1')\n```\n\n# Documentation\n\nhttps://edd313.github.io/ndicts/\n\n# Licence\n`ndicts` is licensed under the MIT license.\n\n\n\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Class to handle nested dictionaries",
    "version": "0.3.0",
    "split_keywords": [
        "nested",
        "dictionary"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f280caf9ee0e3044be65aa6ff6a0b13ca1867e1aafc1a35df756ea068ae3af8d",
                "md5": "1960c334ed73876c27da041c1d166096",
                "sha256": "010b0c94180fe89e7e0d5fa89909c4bd7784c52d56908d4d776337c9358378e9"
            },
            "downloads": -1,
            "filename": "ndicts-0.3.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "1960c334ed73876c27da041c1d166096",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8,<4.0",
            "size": 7696,
            "upload_time": "2023-01-04T13:00:26",
            "upload_time_iso_8601": "2023-01-04T13:00:26.774064Z",
            "url": "https://files.pythonhosted.org/packages/f2/80/caf9ee0e3044be65aa6ff6a0b13ca1867e1aafc1a35df756ea068ae3af8d/ndicts-0.3.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "be6c2d20b98d96a1c87a32014caffb7c873ee01ccc73fc515572affdaba7cf7a",
                "md5": "4e5916e5c7f0bd09a0b1924dc0ef60fb",
                "sha256": "1a1f31cdb770c037c9cc9bc27a8493e43bfe035a606d3630c2e3d14eabe7bfbf"
            },
            "downloads": -1,
            "filename": "ndicts-0.3.0.tar.gz",
            "has_sig": false,
            "md5_digest": "4e5916e5c7f0bd09a0b1924dc0ef60fb",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8,<4.0",
            "size": 7655,
            "upload_time": "2023-01-04T13:00:28",
            "upload_time_iso_8601": "2023-01-04T13:00:28.631462Z",
            "url": "https://files.pythonhosted.org/packages/be/6c/2d20b98d96a1c87a32014caffb7c873ee01ccc73fc515572affdaba7cf7a/ndicts-0.3.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-01-04 13:00:28",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "edd313",
    "github_project": "ndicts",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "ndicts"
}
        
Elapsed time: 0.03051s