The problem
Say you have a configuration file, or command line options, or whatever. And you want to have user-specified elements reference deep portions of a structure that you've defined, read in from yaml or json, or whatever. How?
This solution
(because there are likely others)
Users don't understand complex syntax, so this makes it easy to access deep dict or arrays with keys and numbers separated by a "." character.
A working demonstration
import dotnest
data = {
'subdict': {
'arrrr': ["there", "she", "blows",]
},
'list': [
{'name': 'element1'}, {'name': 'element2'}
]
}
dn = dotnest.DotNest(data)
print(dn.get("subdict.arrrr.1")) # she
print(dn.get("list.1.name")) # element1
dn.set("subdict.newentry", "bar")
print(dn.get("subdict.newentry")) # bar
print(dn.get("list.0")) # {'name': 'element1'}
dn.get("does.not.exist") # raises ValueError
dn.get("does.not.exist",
return_none=True) # None
Used by
This class can be best married with tools that read in and need to referenc YAML or JSON as mentioned. As such, the original source of this effort comes from the package that converts from a netbox nestetd structure to ansible: nb2an.
Metadata
Release files for dotnest 1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| dotnest-1.1.tar.gz | 4.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| dotnest-1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 10.3 kB
Release files / dotnest-1.1.tar.gz
| Download URL | dotnest-1.1.tar.gz |
|---|---|
| Size | 4.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
212039d72d22352a0f0cc8cd782883592dc352c4a8adc9069b55e68a6ac83082
|
|
BLAKE2b-256 checksum How to use checksums |
32773b433e90c7b549527a8fb60a982f448d51649fb28ae3f83f5ff20a4d2fc7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-httpx/0.26.0
|
Release files / dotnest-1.1-py3-none-any.whl
| Download URL | dotnest-1.1-py3-none-any.whl |
|---|---|
| Size | 5.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8296b828a6b44d276f5b9e6275844ee6db63259ddcbbb733093449607240c8f8
|
|
BLAKE2b-256 checksum How to use checksums |
06b25a8448d5d311df945b1c7ad4224394ac983148e0fad46d055448a4cd82e1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-httpx/0.26.0
|