Delimited defines classes that allow for accessing and modifying nested data.
pip install delimited
https://chrisantonellis.github.io/delimited/
Nested data can be easily expressed in python but not easily accessed or modified. Using builtin methods, accessing nested data requires chaining dict.get() calls.
mydict = {
"key1": {
"key2": {
"key3": "value"
}
}
}
mydict.get("key1", {}).get("key2", {}).get("key3", {})This is overly verbose and lacks the functionality needed to effectively interact with the data. Delimited provides classes that emulate native types and make accessing and modifying nested data easier.
from delimited import DelimitedDict as ddict
mydict = ddict({
"key1": {
"key2": {
"key3": "value"
}
}
})
mydict.get("key1.key2.key3")
# returns "value"
mydict.collapse()
# returns {"key1.key2.key3": "value"}Delimited provides Path classes to represent paths to nested data using tuples or strings, and NestedContainer classes that emulate the native dict type. Check out the documentation to learn more.