Description
Nested dictionary structures emerge every time there is some sort hierarchy in the data. Trees, archives, the chapters and sections in a book, these are all examples where you will likely find nested loops of data.
Python does not have a built-in data type for nested mappings.
Dictionaries can be used, however there many inconveniences and limitations.
Two above all: getting items requires to open and close several square brackets
(eg. d[level1][level2]...[levelN]),
and iterating will only access the first layer,
so nested for loops are needed to iterate through all the values.
The ndicts package aims to tackle the main issues of nested dictionaries,
exposing an interface with minimum differences from dictionaries themselves.
NestedDict is a MutableMapping at its core,
therefore all familiar dictionary methods are available
and the overall behaviour similar.
If you need to perform simple mathematical operations with your nested data,
use DataDict. In addition to allowing arithmetics,
DataDicts borrow some methods that you would expect from a pandas DataFrame.
Finally, this is a simple project for simple needs.
Consider using pandas MultiIndex for more functionalities!
Installation
Install ndicts with pip.
pip install ndicts
Overview
Import NestedDict and DataDict.
>>> from ndicts import DataDict, NestedDict
Create a NestedDict from a dictionary.
>>> book = {
... "Book 1": {
... "Section 1": "The Eve of the War",
... "Section 2": "The Falling Star"
... },
... "Book 2": {
... "Section 1": "Under Foot",
... "Section 2": {"Paragraph 1": "After eating we crept back to the scullery"}
... }
... }
>>> nd = NestedDict(book)
Get items more conveniently than with standard dictionaries.
>>> # NestedDict
>>> nd["Book 1", "Section 1"]
'The Eve of the War'
>>> # dict
>>> book["Book 1"]["Section 2"]
'The Falling Star'
Iterate over a NestedDict.
>>> for key in nd:
... print(key)
('Book 1', 'Section 1')
('Book 1', 'Section 2')
('Book 2', 'Section 1')
('Book 2', 'Section 2', 'Paragraph 1')
Documentation
https://edd313.github.io/ndicts/
Licence
ndicts is licensed under the MIT license.
Metadata
Release files for ndicts 0.3.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 |
|---|---|---|---|---|
| ndicts-0.3.0.tar.gz | 7.7 kB | Without provenance | Details for ndicts-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ndicts-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for ndicts-0.3.0-py3-none-any.whl |
Total release size: 15.4 kB
Release files / ndicts-0.3.0.tar.gz
| Download URL | ndicts-0.3.0.tar.gz |
|---|---|
| Size | 7.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1a1f31cdb770c037c9cc9bc27a8493e43bfe035a606d3630c2e3d14eabe7bfbf
|
|
BLAKE2b-256 checksum How to use checksums |
be6c2d20b98d96a1c87a32014caffb7c873ee01ccc73fc515572affdaba7cf7a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.13 CPython/3.9.10 Windows/10
|
Release files / ndicts-0.3.0-py3-none-any.whl
| Download URL | ndicts-0.3.0-py3-none-any.whl |
|---|---|
| Size | 7.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
010b0c94180fe89e7e0d5fa89909c4bd7784c52d56908d4d776337c9358378e9
|
|
BLAKE2b-256 checksum How to use checksums |
f280caf9ee0e3044be65aa6ff6a0b13ca1867e1aafc1a35df756ea068ae3af8d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.13 CPython/3.9.10 Windows/10
|
Security for ndicts 0.3.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.