A recursive dot-styled defaultdict to read and write deeply-nested trees
Project description
easytree
A recursive dot-styled defaultdict to read and write deeply-nested trees
Documentation
Documentation is hosted on read the docs
Installation
pip install easytree
Quickstart
>>> 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"
}
}
]
}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
easytree-0.2.4.tar.gz
(19.2 kB
view hashes)
Built Distribution
easytree-0.2.4-py3-none-any.whl
(21.6 kB
view hashes)