# 🎈🌵 Deflate Dict
[![pip](https://badge.fury.io/py/deflate-dict.svg)](https://pypi.org/project/deflate-dict/)
[![python](https://img.shields.io/pypi/pyversions/deflate-dict)](https://pypi.org/project/deflate-dict/)
[![license](https://img.shields.io/pypi/l/deflate-dict)](https://pypi.org/project/deflate-dict/)
[![downloads](https://pepy.tech/badge/deflate-dict)](https://pepy.tech/project/deflate-dict)
[![mypy](https://github.com/LucaCappelletti94/deflate_dict/actions/workflows/mypy.yml/badge.svg)](https://github.com/LucaCappelletti94/deflate_dict/actions/)
[![Github Actions](https://github.com/LucaCappelletti94/deflate_dict/actions/workflows/python.yml/badge.svg)](https://github.com/LucaCappelletti94/deflate_dict/actions/)
Python package to deflate 🌵 and re-inflate 🎈 nested dictionaries.
## How do I install this package?
As usual, just download it using pip:
```shell
pip install deflate_dict
```
## Deflating a dictionary
A dictionary will be deflated down to its smallest non-further iterable elements, defined as those not containing lists or dictionaries.
```python
from deflate_dict import deflate
D = {
"a": [
{
"b": (0, 1, 2)
},
{
"c": [1, 2, 3]
}
]
}
result = deflate(D, sep="_")
# {'str(a)_listIndex(0)_str(b)': (0, 1, 2), 'str(a)_listIndex(1)_str(c)': [1, 2, 3]}
```
## Inflate a dictionary
To reinflate a dictionary to its forgotten glory, just go with:
```python
from deflate_dict import inflate
D = {"a_0_b": (0, 1, 2), "a_1_c": [1, 2, 3], "d": 4}
result = inflate(D, sep="_")
# {'a': [{'b': (0, 1, 2)}, {'c': [1, 2, 3]}], 'd': 4}
```
## Handling and restoring mixed types
To deflate and re-inflate mixed types and restore them to the original type you can use the `type_encode_key` keyword:
```python
from deflate_dict import deflate
D = {
"a":[
{
"b":(0,1,2)
},
{
"c": [1,2,3]
}
]
}
print(deflate(D, sep="_", type_encode_key=False))
# {
# 'a_listIndex(0)_b': (0, 1, 2),
# 'a_listIndex(1)_c': [1, 2, 3]
# }
print(deflate(D, sep="_", type_encode_key=True))
# {
# 'str(a)_listIndex(0)_str(b)': (0, 1, 2),
# 'str(a)_listIndex(1)_str(c)': [1, 2, 3]
# }
```
## License
This software is distributed under MIT license.
Raw data
{
"_id": null,
"home_page": "https://github.com/LucaCappelletti94/deflate_dict",
"name": "deflate-dict",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": null,
"author": "Luca Cappelletti",
"author_email": "cappelletti.luca94@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/2f/05/ca5ea149d91d172b9b9d64547b33a87e9613038deb4c8c7bbaf76e26a4be/deflate_dict-1.2.2.tar.gz",
"platform": null,
"description": "# \ud83c\udf88\ud83c\udf35 Deflate Dict\n\n[![pip](https://badge.fury.io/py/deflate-dict.svg)](https://pypi.org/project/deflate-dict/)\n[![python](https://img.shields.io/pypi/pyversions/deflate-dict)](https://pypi.org/project/deflate-dict/)\n[![license](https://img.shields.io/pypi/l/deflate-dict)](https://pypi.org/project/deflate-dict/)\n[![downloads](https://pepy.tech/badge/deflate-dict)](https://pepy.tech/project/deflate-dict)\n[![mypy](https://github.com/LucaCappelletti94/deflate_dict/actions/workflows/mypy.yml/badge.svg)](https://github.com/LucaCappelletti94/deflate_dict/actions/)\n[![Github Actions](https://github.com/LucaCappelletti94/deflate_dict/actions/workflows/python.yml/badge.svg)](https://github.com/LucaCappelletti94/deflate_dict/actions/)\n\nPython package to deflate \ud83c\udf35 and re-inflate \ud83c\udf88 nested dictionaries.\n\n## How do I install this package?\n\nAs usual, just download it using pip:\n\n```shell\npip install deflate_dict\n```\n\n## Deflating a dictionary\n\nA dictionary will be deflated down to its smallest non-further iterable elements, defined as those not containing lists or dictionaries.\n\n```python\nfrom deflate_dict import deflate\nD = {\n \"a\": [\n {\n \"b\": (0, 1, 2)\n },\n {\n \"c\": [1, 2, 3]\n }\n ]\n}\nresult = deflate(D, sep=\"_\")\n\n# {'str(a)_listIndex(0)_str(b)': (0, 1, 2), 'str(a)_listIndex(1)_str(c)': [1, 2, 3]}\n```\n\n## Inflate a dictionary\n\nTo reinflate a dictionary to its forgotten glory, just go with:\n\n```python\nfrom deflate_dict import inflate\nD = {\"a_0_b\": (0, 1, 2), \"a_1_c\": [1, 2, 3], \"d\": 4}\n\nresult = inflate(D, sep=\"_\")\n\n# {'a': [{'b': (0, 1, 2)}, {'c': [1, 2, 3]}], 'd': 4}\n```\n\n## Handling and restoring mixed types\n\nTo deflate and re-inflate mixed types and restore them to the original type you can use the `type_encode_key` keyword:\n\n```python\nfrom deflate_dict import deflate\n\nD = {\n \"a\":[\n {\n \"b\":(0,1,2)\n },\n {\n \"c\": [1,2,3]\n }\n ]\n}\n\nprint(deflate(D, sep=\"_\", type_encode_key=False))\n\n# {\n# 'a_listIndex(0)_b': (0, 1, 2),\n# 'a_listIndex(1)_c': [1, 2, 3]\n# }\n\nprint(deflate(D, sep=\"_\", type_encode_key=True))\n\n# {\n# 'str(a)_listIndex(0)_str(b)': (0, 1, 2),\n# 'str(a)_listIndex(1)_str(c)': [1, 2, 3]\n# }\n```\n\n## License\n\nThis software is distributed under MIT license.\n\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Package to deflate and inflate dictionaries.",
"version": "1.2.2",
"project_urls": {
"Homepage": "https://github.com/LucaCappelletti94/deflate_dict"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "2f05ca5ea149d91d172b9b9d64547b33a87e9613038deb4c8c7bbaf76e26a4be",
"md5": "15d7b8e7602ec37fae33a8fa3a560fbe",
"sha256": "a51f72562a2056118c6b0915b4ac46a483cc329b43d13d759307e4c027ea20ea"
},
"downloads": -1,
"filename": "deflate_dict-1.2.2.tar.gz",
"has_sig": false,
"md5_digest": "15d7b8e7602ec37fae33a8fa3a560fbe",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 6946,
"upload_time": "2024-10-26T16:36:22",
"upload_time_iso_8601": "2024-10-26T16:36:22.057262Z",
"url": "https://files.pythonhosted.org/packages/2f/05/ca5ea149d91d172b9b9d64547b33a87e9613038deb4c8c7bbaf76e26a4be/deflate_dict-1.2.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-10-26 16:36:22",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "LucaCappelletti94",
"github_project": "deflate_dict",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "deflate-dict"
}