A recursive dot-styled defaultdict to read and write deeply-nested trees
Documentation is hosted on read the docs
pip install easytree
>>> import easytree
>>> tree = easytree.dict()
>>> tree.foo.bar.baz = "Hello world!"
>>> tree
{
"foo": {
"bar": {
"baz": "Hello world!"
}
}
}
Creating trees that combine both list and dict nodes is easy
>>> friends = easytree.list()
>>> friends.append({"firstname":"Alice"})
>>> friends[0].address.country = "Netherlands"
>>> friends[0]["interests"].append("science")
>>> friends
[
{
"firstname": "Alice",
"address": {
"country": "Netherlands"
},
"interests": [
"science"
]
}
]
Writing deeply-nested trees with list nodes is easy with a context-manager:
>>> profile = easytree.dict()
>>> with profile.friends.append({"firstname":"Flora"}) as friend:
... friend.birthday = "25/02"
... friend.address.country = "France"
>>> profile
{
"friends": [
{
"firstname": "Flora",
"birthday": "25/02",
"address": {
"country": "France"
}
}
]
}