easytree#
easytree is a lightweight Python library designed to easily read and write deeply-nested tree configurations.
Quickstart#
Installing easytree
is simple with pip:
pip install easytree
Using easytree
is also easy
>>> import easytree
>>> tree = easytree.Tree()
>>> tree.foo.bar.baz = "Hello world!"
>>> tree
Tree({
"foo":{
"bar":{
"baz":"Hello world!"
}
}
})
Writing configurations that combine both list and dict nodes is easy - here’s an example of an Highcharts chart configuration
>>> import easytree
>>> chart = easytree.Tree()
>>> chart.chart.type = "bar"
>>> chart.title.text = "France Olympic Medals"
>>> chart.xAxis.categories = ["Gold", "Silver", "Bronze"]
>>> chart.yAxis.title.text = "Count"
>>> chart.series.append(name="2016", data=[10, 18, 14])
>>> chart.series.append({"name":"2012"})
>>> chart.series[1].data = [11, 11, 13] #list items recursively become nodes
>>> chart.serialize() #convert back to Python native objects
{
"chart": {
"type": "bar"
},
"title": {
"text": "France Olympic Medals"
},
"xAxis": {
"categories": [
"Gold",
"Silver",
"Bronze"
]
},
"yAxis": {
"title": {
"text": "Count"
}
},
"series": [
{
"name": "2016",
"data": [
10,
18,
14
]
},
{
"name": "2012",
"data": [
11,
11,
13
]
}
]
}
Writing deeply-nested trees with list nodes is easy with a context-manager:
>>> chart = easytree.Tree()
>>> with chart.axes.append({}) as axis:
... axis.title.text = "primary axis"
... axis.min = 0
>>> chart.serialize()
{
"axes": [
{
"title": {
"text": "primary axis"
}
"min":0
}
]
}
- Installation
- Getting started
- Sealing and freezing
- How does
easytree
compare withjsontree
- API
- Changelog
- Version 0.1.0 (2020-08-01)
- Version 0.1.1 (2020-08-02)
- Version 0.1.2 (2020-08-03)
- Version 0.1.3 (2020-08-04)
- Version 0.1.4 (2020-08-05)
- Version 0.1.5 (2020-08-08)
- Version 0.1.6 (2020-08-16)
- Version 0.1.7 (2021-05-01)
- Version 0.1.8 (2021-06-13)
- Version 0.1.9 (2021-06-21)
- Version 0.1.10 (2021-07-03)
- Version 0.1.11 (2021-09-30)