unflatten - convert flat dict to nested dict/array
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.
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 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:
>>> 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.
Authors
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-scmto 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
lintandcoverageenvironments
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.
Metadata
Release files for unflatten 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| unflatten-0.2.0.tar.gz | 7.0 kB | Without provenance | Details for unflatten-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| unflatten-0.2.0-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details for unflatten-0.2.0-py2.py3-none-any.whl |
Total release size: 12.2 kB
Release files / unflatten-0.2.0.tar.gz
| Download URL | unflatten-0.2.0.tar.gz |
|---|---|
| Size | 7.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9710bc558882f697bc36a95a97614be296f07c8f8df1bc2b4ef96c189ce5cf84
|
|
BLAKE2b-256 checksum How to use checksums |
e4d5d2ee1ab7fdbc5af182e853391003c862cde05001810b11057d336436da35
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.1 CPython/3.12.5
|
Release files / unflatten-0.2.0-py2.py3-none-any.whl
| Download URL | unflatten-0.2.0-py2.py3-none-any.whl |
|---|---|
| Size | 5.2 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
a0afa7ff22313dcc60ff45110b796ed5b4e908614826e8672a9f76d3a20c1f54
|
|
BLAKE2b-256 checksum How to use checksums |
03899030594c356c6327160d0e9d744fa8deb1de5cdd70b94f272eabcce706fa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.1 CPython/3.12.5
|
Security for unflatten 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.