https://github.com/dschenck/easytree
A recursive dot-styled defaultdict to read and write deeply-nested trees
https://github.com/dschenck/easytree
defaultdict json python
Last synced: 4 months ago
JSON representation
A recursive dot-styled defaultdict to read and write deeply-nested trees
- Host: GitHub
- URL: https://github.com/dschenck/easytree
- Owner: dschenck
- License: mit
- Created: 2020-08-01T11:06:28.000Z (almost 6 years ago)
- Default Branch: main
- Last Pushed: 2026-02-05T21:58:54.000Z (5 months ago)
- Last Synced: 2026-02-06T07:44:49.072Z (5 months ago)
- Topics: defaultdict, json, python
- Language: Python
- Homepage: https://easytree.readthedocs.io
- Size: 167 KB
- Stars: 6
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# easytree
[](https://pypi.org/project/easytree)
[](https://github.com/dschenck/easytree/actions/workflows/testing.yml)
[](https://badge.fury.io/py/easytree)
[](https://easytree.readthedocs.io/en/latest/?badge=latest)
[](https://github.com/psf/black)
[](https://codecov.io/gh/dschenck/easytree)
A recursive dot-styled defaultdict to read and write deeply-nested trees
## Documentation
Documentation is hosted on [read the docs](https://easytree.readthedocs.io/en/latest/)
## Installation
```
pip install easytree
```
## Quickstart
```python
>>> 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
```python
>>> 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:
```python
>>> 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"
}
}
]
}
```