==================================================
unflatten - convert flat dict to nested dict/array
==================================================
|version| |pyversions| |build status|
***********
Description
***********
This package provides a function which can unpack a flat dictionary
into a structured ``dict`` with nested sub-dicts and/or sub-lists.
Development takes place on github_.
The package is installable from PyPI_
.. _github: https://github.com/dairiki/unflatten/
.. _pypi: https://pypi.python.org/pypi/unflatten/
********
Synopsis
********
Nested dicts::
>>> from unflatten import unflatten
>>> unflatten({'foo.bar': 'val'})
{'foo': {'bar': 'val'}}
Nested list::
>>> unflatten({'foo[0]': 'x', 'foo[1]': 'y'})
{'foo': ['x', 'y']}
Nested lists and dicts, intermixed::
>>> unflatten({
... 'foo[0][0]': 'a',
... 'foo[0][1]': 'b',
... 'foo[1].x': 'c',
... })
{'foo': [['a', 'b'], {'x': 'c'}]}
*****
Notes
*****
``Unflatten`` take a single argument which should either be a ``dict``
(or an object with a dict-like ``.items()`` or ``.iteritems()``
method) or a sequence of ``(key, value)`` pairs.
All keys in the dict or sequence must be strings.
(Under python 2, keys must be instances of ``basestring``; under
python 3, keys just be instances of ``str``.)
``Unflatten`` always returns a ``dict``. By way of example::
>>> unflatten([('[0]', 'x')])
{'': ['x']}
For list-valued nodes, all indexes must be present in the input
(flattened) mapping, otherwise a ``ValueError`` will be thrown::
>>> unflatten({'a[0]': 'x', 'a[2]': 'y'})
Traceback (most recent call last):
...
ValueError: missing key 'a[1]'
********
See Also
********
The `morph`_ and `flattery`_ packages purport to implement similar functions.
.. _morph: https://github.com/metagriffin/morph
.. _flattery: https://github.com/acg/python-flattery
*******
Authors
*******
`Jeff Dairiki`_
.. _Jeff Dairiki: mailto:dairiki@dairiki.org
.. |version| image::
https://img.shields.io/pypi/v/unflatten.svg
:target: https://pypi.python.org/pypi/unflatten/
:alt: Latest Version
.. |pyversions| image::
https://img.shields.io/pypi/pyversions/unflatten.svg
:target: https://pypi.python.org/pypi/unflatten/
:alt: Python versions
.. |build status| image::
https://github.com/dairiki/unflatten/actions/workflows/tests.yml/badge.svg
:target: https://github.com/dairiki/unflatten/actions/workflows/tests.yml
*******
History
*******
Release 0.1.1 (2021-08-16)
==========================
Nits
----
- Fix backslashes in docstrings
Packaging
---------
- PEP517-ize the packaging
- Use ``setuptools-scm`` to maintain version numbers
Testing
-------
- Test under Python 3.7, 3.8, 3.9 and PyPy 3.7. Drop testing for Python 3.4 & 3.5.
- Pin pip version for pypy2 (see `pip #8653`_)
- Clean up and modernize the tox ``lint`` and ``coverage`` environments
.. _pip #8653: https://github.com/pypa/pip/issues/8653
Release 0.1 (2018-01-17)
========================
No code changes.
This package is now deemed "production ready" (though your mileage may vary.)
Release 0.1b1 (2018-01-09)
==========================
Initial release.
Raw data
{
"_id": null,
"home_page": "https://github.com/dairiki/unflatten",
"name": "unflatten",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "unflatten nested-dict",
"author": "Jeff Dairiki",
"author_email": "dairiki@dairiki.org",
"download_url": "https://files.pythonhosted.org/packages/f8/75/3e45e6abd08a15829edcd0050075aed065b20676543b7f34ad70d6d4cff2/unflatten-0.1.1.tar.gz",
"platform": "",
"description": "==================================================\nunflatten - convert flat dict to nested dict/array\n==================================================\n\n|version| |pyversions| |build status|\n\n***********\nDescription\n***********\n\nThis package provides a function which can unpack a flat dictionary\ninto a structured ``dict`` with nested sub-dicts and/or sub-lists.\n\nDevelopment takes place on github_.\nThe package is installable from PyPI_\n\n.. _github: https://github.com/dairiki/unflatten/\n.. _pypi: https://pypi.python.org/pypi/unflatten/\n\n********\nSynopsis\n********\n\nNested dicts::\n\n >>> from unflatten import unflatten\n\n >>> unflatten({'foo.bar': 'val'})\n {'foo': {'bar': 'val'}}\n\nNested list::\n\n >>> unflatten({'foo[0]': 'x', 'foo[1]': 'y'})\n {'foo': ['x', 'y']}\n\nNested lists and dicts, intermixed::\n\n >>> unflatten({\n ... 'foo[0][0]': 'a',\n ... 'foo[0][1]': 'b',\n ... 'foo[1].x': 'c',\n ... })\n {'foo': [['a', 'b'], {'x': 'c'}]}\n\n\n*****\nNotes\n*****\n\n``Unflatten`` take a single argument which should either be a ``dict``\n(or an object with a dict-like ``.items()`` or ``.iteritems()``\nmethod) or a sequence of ``(key, value)`` pairs.\nAll keys in the dict or sequence must be strings.\n(Under python 2, keys must be instances of ``basestring``; under\npython 3, keys just be instances of ``str``.)\n\n\n``Unflatten`` always returns a ``dict``. By way of example::\n\n >>> unflatten([('[0]', 'x')])\n {'': ['x']}\n\nFor list-valued nodes, all indexes must be present in the input\n(flattened) mapping, otherwise a ``ValueError`` will be thrown::\n\n >>> unflatten({'a[0]': 'x', 'a[2]': 'y'})\n Traceback (most recent call last):\n ...\n ValueError: missing key 'a[1]'\n\n********\nSee Also\n********\n\nThe `morph`_ and `flattery`_ packages purport to implement similar functions.\n\n.. _morph: https://github.com/metagriffin/morph\n.. _flattery: https://github.com/acg/python-flattery\n\n*******\nAuthors\n*******\n\n`Jeff Dairiki`_\n\n.. _Jeff Dairiki: mailto:dairiki@dairiki.org\n\n.. |version| image::\n https://img.shields.io/pypi/v/unflatten.svg\n :target: https://pypi.python.org/pypi/unflatten/\n :alt: Latest Version\n\n.. |pyversions| image::\n https://img.shields.io/pypi/pyversions/unflatten.svg\n :target: https://pypi.python.org/pypi/unflatten/\n :alt: Python versions\n\n.. |build status| image::\n https://github.com/dairiki/unflatten/actions/workflows/tests.yml/badge.svg\n :target: https://github.com/dairiki/unflatten/actions/workflows/tests.yml\n \n\n*******\nHistory\n*******\n\nRelease 0.1.1 (2021-08-16)\n==========================\n\nNits\n----\n\n- Fix backslashes in docstrings\n\nPackaging\n---------\n\n- PEP517-ize the packaging\n- Use ``setuptools-scm`` to maintain version numbers\n\nTesting\n-------\n\n- Test under Python 3.7, 3.8, 3.9 and PyPy 3.7. Drop testing for Python 3.4 & 3.5.\n- Pin pip version for pypy2 (see `pip #8653`_)\n- Clean up and modernize the tox ``lint`` and ``coverage`` environments\n\n.. _pip #8653: https://github.com/pypa/pip/issues/8653\n\n\nRelease 0.1 (2018-01-17)\n========================\n\nNo code changes.\n\nThis package is now deemed \"production ready\" (though your mileage may vary.)\n\nRelease 0.1b1 (2018-01-09)\n==========================\n\nInitial release.\n\n\n",
"bugtrack_url": null,
"license": "",
"summary": "Unflatten dict to dict with nested dict/arrays",
"version": "0.1.1",
"split_keywords": [
"unflatten",
"nested-dict"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "bc084d3ee9406a954ecea4598639d387f993a73a6ad2712b60838ae2d6e78738",
"md5": "ce3a7a946d8e88d9183714dae7479631",
"sha256": "42de0eae963f34cbb8d80a35cdab962f723b879a3e93c603fac9ca6062e96de3"
},
"downloads": -1,
"filename": "unflatten-0.1.1-py2.py3-none-any.whl",
"has_sig": true,
"md5_digest": "ce3a7a946d8e88d9183714dae7479631",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": null,
"size": 5076,
"upload_time": "2021-08-16T19:52:01",
"upload_time_iso_8601": "2021-08-16T19:52:01.158828Z",
"url": "https://files.pythonhosted.org/packages/bc/08/4d3ee9406a954ecea4598639d387f993a73a6ad2712b60838ae2d6e78738/unflatten-0.1.1-py2.py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "f8753e45e6abd08a15829edcd0050075aed065b20676543b7f34ad70d6d4cff2",
"md5": "43ab8202974159e4147e6207745c45cd",
"sha256": "5d695d6b0a70ff7aca5d63474b79cd397ed5f7d87de0e990aaf0b04db77784a5"
},
"downloads": -1,
"filename": "unflatten-0.1.1.tar.gz",
"has_sig": true,
"md5_digest": "43ab8202974159e4147e6207745c45cd",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 6770,
"upload_time": "2021-08-16T19:52:02",
"upload_time_iso_8601": "2021-08-16T19:52:02.338962Z",
"url": "https://files.pythonhosted.org/packages/f8/75/3e45e6abd08a15829edcd0050075aed065b20676543b7f34ad70d6d4cff2/unflatten-0.1.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2021-08-16 19:52:02",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "dairiki",
"github_project": "unflatten",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"tox": true,
"lcname": "unflatten"
}