nested_dict_tools


Namenested_dict_tools JSON
Version 0.1.2 PyPI version JSON
download
home_pageNone
SummaryUtilities for Python nested dictionaries.
upload_time2024-11-26 00:04:41
maintainerNone
docs_urlNone
authorNone
requires_python>=3.12
licenseMIT License Copyright (c) 2024, Kajih <itskajih@gmail.com> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords nested dictionary python tools utils
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![Build][github-ci-image]][github-ci-link]
[![Coverage Status][codecov-image]][codecov-link]
[![PyPI Version][pypi-image]][pypi-link]
[![PyPI - Python Version][python-image]][pypi-link]
![License][license-image-mit]

# 🪆 Nested Dict Tools

**Nested Dict Tools** is a Python package that provides utilities for working with nested dictionaries. It includes:

- Recursive types for describing nested mappings and dictionaries.
- Fully typed functions to:
  - Flatten and unflatten nested dictionaries.
  - Get and set deeply nested values.

```python
from nested_dict_tools import flatten_dict, unflatten_dict, get_deep, set_deep

nested = {'a': {'b': {'c': 42}}}

# Get a deeply nested value
value = get_deep(nested, ['a', 'b'])
print(value)  # Output: {'c': 42}

# Set a deeply nested value
set_deep(nested, ['a', 'z'], 'new_value')
print(nested)  # Output: {'a': {'b': {'c': 42}, 'z': 'new_value'}}

# Flatten the nested dictionary
flat = flatten_dict(nested, sep='.')
print(flat)  # Output: {'a.b.c': 42, 'a.z': 'new_value'}

# Unflatten the flattened dictionary
unflattened = unflatten_dict(flat, sep='.')
print(unflattened == nested)  # Output: True

# Recursive types:
type NestedDict[K, V] = dict[K, NestedDictNode[K, V]]
type NestedDictNode[K, V] = V | NestedDict[K, V]
# Similar types for Mapping and MutableMapping
```

## ⬇️ Installation

You can install **Nested Dict Tools** via pip:

```bash
pip install nested-dict-tools
```

## 🧾 License

[MIT](LICENSE)

<!-- Links -->
[github-ci-image]: https://github.com/kajiih/nested_dict_tools/workflows/build/badge.svg?branch=main
[github-ci-link]: https://github.com/kajiih/nested_dict_tools/actions?query=workflow%3Abuild+branch%3Amain

[codecov-image]: https://img.shields.io/codecov/c/github/kajiih/nested-dict-tools/main.svg?logo=codecov&logoColor=aaaaaa&labelColor=333333
[codecov-link]: https://codecov.io/github/kajiih/nested_dict_tools

[pypi-image]: https://img.shields.io/pypi/v/nested-dict-tools.svg?logo=pypi&logoColor=aaaaaa&labelColor=333333
[pypi-link]: https://pypi.python.org/pypi/nested-dict-tools

[python-image]: https://img.shields.io/pypi/pyversions/nested-dict-tools?logo=python&logoColor=aaaaaa&labelColor=333333
[license-image-mit]: https://img.shields.io/badge/license-MIT-blue.svg?labelColor=333333

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "nested_dict_tools",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.12",
    "maintainer_email": null,
    "keywords": "nested dictionary, python, tools, utils",
    "author": null,
    "author_email": "Kajih <itskajih@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/45/71/9d3773f67c04786f92528777cde9af527459fb1c32aedd63786d353c6de2/nested_dict_tools-0.1.2.tar.gz",
    "platform": null,
    "description": "[![Build][github-ci-image]][github-ci-link]\n[![Coverage Status][codecov-image]][codecov-link]\n[![PyPI Version][pypi-image]][pypi-link]\n[![PyPI - Python Version][python-image]][pypi-link]\n![License][license-image-mit]\n\n# \ud83e\ude86 Nested Dict Tools\n\n**Nested Dict Tools** is a Python package that provides utilities for working with nested dictionaries. It includes:\n\n- Recursive types for describing nested mappings and dictionaries.\n- Fully typed functions to:\n  - Flatten and unflatten nested dictionaries.\n  - Get and set deeply nested values.\n\n```python\nfrom nested_dict_tools import flatten_dict, unflatten_dict, get_deep, set_deep\n\nnested = {'a': {'b': {'c': 42}}}\n\n# Get a deeply nested value\nvalue = get_deep(nested, ['a', 'b'])\nprint(value)  # Output: {'c': 42}\n\n# Set a deeply nested value\nset_deep(nested, ['a', 'z'], 'new_value')\nprint(nested)  # Output: {'a': {'b': {'c': 42}, 'z': 'new_value'}}\n\n# Flatten the nested dictionary\nflat = flatten_dict(nested, sep='.')\nprint(flat)  # Output: {'a.b.c': 42, 'a.z': 'new_value'}\n\n# Unflatten the flattened dictionary\nunflattened = unflatten_dict(flat, sep='.')\nprint(unflattened == nested)  # Output: True\n\n# Recursive types:\ntype NestedDict[K, V] = dict[K, NestedDictNode[K, V]]\ntype NestedDictNode[K, V] = V | NestedDict[K, V]\n# Similar types for Mapping and MutableMapping\n```\n\n## \u2b07\ufe0f Installation\n\nYou can install **Nested Dict Tools** via pip:\n\n```bash\npip install nested-dict-tools\n```\n\n## \ud83e\uddfe License\n\n[MIT](LICENSE)\n\n<!-- Links -->\n[github-ci-image]: https://github.com/kajiih/nested_dict_tools/workflows/build/badge.svg?branch=main\n[github-ci-link]: https://github.com/kajiih/nested_dict_tools/actions?query=workflow%3Abuild+branch%3Amain\n\n[codecov-image]: https://img.shields.io/codecov/c/github/kajiih/nested-dict-tools/main.svg?logo=codecov&logoColor=aaaaaa&labelColor=333333\n[codecov-link]: https://codecov.io/github/kajiih/nested_dict_tools\n\n[pypi-image]: https://img.shields.io/pypi/v/nested-dict-tools.svg?logo=pypi&logoColor=aaaaaa&labelColor=333333\n[pypi-link]: https://pypi.python.org/pypi/nested-dict-tools\n\n[python-image]: https://img.shields.io/pypi/pyversions/nested-dict-tools?logo=python&logoColor=aaaaaa&labelColor=333333\n[license-image-mit]: https://img.shields.io/badge/license-MIT-blue.svg?labelColor=333333\n",
    "bugtrack_url": null,
    "license": "MIT License\n        \n        Copyright (c) 2024, Kajih <itskajih@gmail.com>\n        \n        Permission is hereby granted, free of charge, to any person obtaining a copy\n        of this software and associated documentation files (the \"Software\"), to deal\n        in the Software without restriction, including without limitation the rights\n        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n        copies of the Software, and to permit persons to whom the Software is\n        furnished to do so, subject to the following conditions:\n        \n        The above copyright notice and this permission notice shall be included in all\n        copies or substantial portions of the Software.\n        \n        THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n        SOFTWARE.",
    "summary": "Utilities for Python nested dictionaries.",
    "version": "0.1.2",
    "project_urls": {
        "Issues": "https://github.com/Kajiih/nested_dict_tools/issues",
        "Repository": "https://github.com/Kajiih/nested_dict_tools"
    },
    "split_keywords": [
        "nested dictionary",
        " python",
        " tools",
        " utils"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "c66c9b1d2ed6652883469e9a0cfc9a0b0b238eeaa2d2840c99f08b955ad3fbe8",
                "md5": "616d3ec1df4618804bd415b07c4a967a",
                "sha256": "4c0463932dd9f0b84bbbf02eaaa2915f877b29788b80bba2bda6a081ddaf5a71"
            },
            "downloads": -1,
            "filename": "nested_dict_tools-0.1.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "616d3ec1df4618804bd415b07c4a967a",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.12",
            "size": 6551,
            "upload_time": "2024-11-26T00:04:39",
            "upload_time_iso_8601": "2024-11-26T00:04:39.763108Z",
            "url": "https://files.pythonhosted.org/packages/c6/6c/9b1d2ed6652883469e9a0cfc9a0b0b238eeaa2d2840c99f08b955ad3fbe8/nested_dict_tools-0.1.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "45719d3773f67c04786f92528777cde9af527459fb1c32aedd63786d353c6de2",
                "md5": "304643c85531ffc966027a67d5353b97",
                "sha256": "5135571724b8e1fcd4306cade6a346a566828aa7c292223e9420382ea0557dcd"
            },
            "downloads": -1,
            "filename": "nested_dict_tools-0.1.2.tar.gz",
            "has_sig": false,
            "md5_digest": "304643c85531ffc966027a67d5353b97",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.12",
            "size": 66374,
            "upload_time": "2024-11-26T00:04:41",
            "upload_time_iso_8601": "2024-11-26T00:04:41.600700Z",
            "url": "https://files.pythonhosted.org/packages/45/71/9d3773f67c04786f92528777cde9af527459fb1c32aedd63786d353c6de2/nested_dict_tools-0.1.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-26 00:04:41",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Kajiih",
    "github_project": "nested_dict_tools",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "nested_dict_tools"
}
        
Elapsed time: 0.59874s