unflatten


Nameunflatten JSON
Version 0.2.0 PyPI version JSON
download
home_pagehttps://github.com/dairiki/unflatten
SummaryUnflatten dict to dict with nested dict/arrays
upload_time2024-09-05 03:41:24
maintainerNone
docs_urlNone
authorJeff Dairiki
requires_pythonNone
licenseNone
keywords unflatten nested-dict
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # unflatten - convert flat dict to nested dict/array

[![Latest Version](https://img.shields.io/pypi/v/unflatten.svg)](https://pypi.python.org/pypi/unflatten/)
[![Python versions](https://img.shields.io/pypi/pyversions/unflatten.svg)]( https://pypi.python.org/pypi/unflatten/)
[![CI test status](https://github.com/dairiki/unflatten/actions/workflows/tests.yml/badge.svg)](https://github.com/dairiki/unflatten/actions/workflows/tests.yml)
[![Trackgit Views](https://us-central1-trackgit-analytics.cloudfunctions.net/token/ping/lhasvnk7wy5gn9qxjmlh)](https://trackgit.com)

## 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](https://github.com/dairiki/unflatten/).
The package is installable from [PyPI](https://pypi.python.org/pypi/unflatten/).

## Synopsis

Nested dicts:

```pycon
>>> from unflatten import unflatten

>>> unflatten({'foo.bar': 'val'})
{'foo': {'bar': 'val'}}

```

Nested list:

```pycon
>>> unflatten({'foo[0]': 'x', 'foo[1]': 'y'})
{'foo': ['x', 'y']}

```

Nested lists and dicts, intermixed:

```pycon
>>> unflatten({
...     'foo[0][0]': 'a',
...     'foo[0][1]': 'b',
...     'foo[1].x': 'c',
...      })
{'foo': [['a', 'b'], {'x': 'c'}]}

```

## Notes

`Unflatten` takes 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:

```pycon
>>> unflatten([('[0]', 'x')])
{'': ['x']}

```

For list-valued nodes, all indexes must be present in the input
(flattened) mapping, otherwise a `ValueError` will be thrown:

```pycon
>>> 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](mailto:dairiki@dairiki.org)


## History

### Release 0.2.0 (2024-09-04)

No substantive code changes from 0.1.1.

#### Features

- Added type annotations.

#### Testing

- Test under python 3.10, 3.11, and 3.12.

- Fix tox config to cope with the fact that recent tox/virtualenv does
  not support EOLed versions of python.

### 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": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "unflatten nested-dict",
    "author": "Jeff Dairiki",
    "author_email": "dairiki@dairiki.org",
    "download_url": "https://files.pythonhosted.org/packages/e4/d5/d2ee1ab7fdbc5af182e853391003c862cde05001810b11057d336436da35/unflatten-0.2.0.tar.gz",
    "platform": null,
    "description": "# unflatten - convert flat dict to nested dict/array\n\n[![Latest Version](https://img.shields.io/pypi/v/unflatten.svg)](https://pypi.python.org/pypi/unflatten/)\n[![Python versions](https://img.shields.io/pypi/pyversions/unflatten.svg)]( https://pypi.python.org/pypi/unflatten/)\n[![CI test status](https://github.com/dairiki/unflatten/actions/workflows/tests.yml/badge.svg)](https://github.com/dairiki/unflatten/actions/workflows/tests.yml)\n[![Trackgit Views](https://us-central1-trackgit-analytics.cloudfunctions.net/token/ping/lhasvnk7wy5gn9qxjmlh)](https://trackgit.com)\n\n## Description\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](https://github.com/dairiki/unflatten/).\nThe package is installable from [PyPI](https://pypi.python.org/pypi/unflatten/).\n\n## Synopsis\n\nNested dicts:\n\n```pycon\n>>> from unflatten import unflatten\n\n>>> unflatten({'foo.bar': 'val'})\n{'foo': {'bar': 'val'}}\n\n```\n\nNested list:\n\n```pycon\n>>> unflatten({'foo[0]': 'x', 'foo[1]': 'y'})\n{'foo': ['x', 'y']}\n\n```\n\nNested lists and dicts, intermixed:\n\n```pycon\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\n## Notes\n\n`Unflatten` takes 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```pycon\n>>> unflatten([('[0]', 'x')])\n{'': ['x']}\n\n```\n\nFor list-valued nodes, all indexes must be present in the input\n(flattened) mapping, otherwise a `ValueError` will be thrown:\n\n```pycon\n>>> unflatten({'a[0]': 'x', 'a[2]': 'y'})\nTraceback (most recent call last):\n...\nValueError: missing key 'a[1]'\n\n```\n\n## See Also\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## Authors\n\n[Jeff Dairiki](mailto:dairiki@dairiki.org)\n\n\n## History\n\n### Release 0.2.0 (2024-09-04)\n\nNo substantive code changes from 0.1.1.\n\n#### Features\n\n- Added type annotations.\n\n#### Testing\n\n- Test under python 3.10, 3.11, and 3.12.\n\n- Fix tox config to cope with the fact that recent tox/virtualenv does\n  not support EOLed versions of python.\n\n### Release 0.1.1 (2021-08-16)\n\n#### Nits\n\n- Fix backslashes in docstrings\n\n#### Packaging\n\n- PEP517-ize the packaging\n- Use `setuptools-scm` to maintain version numbers\n\n#### Testing\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\n### Release 0.1 (2018-01-17)\n\nNo code changes.\n\nThis package is now deemed \"production ready\" (though your mileage may vary.)\n\n### Release 0.1b1 (2018-01-09)\n\nInitial release.\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Unflatten dict to dict with nested dict/arrays",
    "version": "0.2.0",
    "project_urls": {
        "Homepage": "https://github.com/dairiki/unflatten"
    },
    "split_keywords": [
        "unflatten",
        "nested-dict"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "03899030594c356c6327160d0e9d744fa8deb1de5cdd70b94f272eabcce706fa",
                "md5": "6add18af899e5f5ce1b60379b5f79d5d",
                "sha256": "a0afa7ff22313dcc60ff45110b796ed5b4e908614826e8672a9f76d3a20c1f54"
            },
            "downloads": -1,
            "filename": "unflatten-0.2.0-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "6add18af899e5f5ce1b60379b5f79d5d",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 5194,
            "upload_time": "2024-09-05T03:41:23",
            "upload_time_iso_8601": "2024-09-05T03:41:23.373346Z",
            "url": "https://files.pythonhosted.org/packages/03/89/9030594c356c6327160d0e9d744fa8deb1de5cdd70b94f272eabcce706fa/unflatten-0.2.0-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e4d5d2ee1ab7fdbc5af182e853391003c862cde05001810b11057d336436da35",
                "md5": "4f9bd0d18ec8ca95155f33f8ebf3e087",
                "sha256": "9710bc558882f697bc36a95a97614be296f07c8f8df1bc2b4ef96c189ce5cf84"
            },
            "downloads": -1,
            "filename": "unflatten-0.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "4f9bd0d18ec8ca95155f33f8ebf3e087",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 6978,
            "upload_time": "2024-09-05T03:41:24",
            "upload_time_iso_8601": "2024-09-05T03:41:24.862373Z",
            "url": "https://files.pythonhosted.org/packages/e4/d5/d2ee1ab7fdbc5af182e853391003c862cde05001810b11057d336436da35/unflatten-0.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-09-05 03:41:24",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "dairiki",
    "github_project": "unflatten",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "unflatten"
}
        
Elapsed time: 0.31980s