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-1.0.0.tar.gz
(13.5 kB
view details)
Built Distribution
easytree-1.0.0-py3-none-any.whl
(13.9 kB
view details)
File details
Details for the file easytree-1.0.0.tar.gz
.
File metadata
- Download URL: easytree-1.0.0.tar.gz
- Upload date:
- Size: 13.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6fddc6fde77dd44caafb2e7bec1c0186e7be45143a2330ccd254ee0c719ebc8f |
|
MD5 | 82b8f14546936214f51f70e91348e46e |
|
BLAKE2b-256 | 8c4770fa30880a62d1c66aec0bbce8be23f774e551168039279efa929a39d93d |
File details
Details for the file easytree-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: easytree-1.0.0-py3-none-any.whl
- Upload date:
- Size: 13.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bb6d177f975cf409d6817cf910dbd7fc4255e9cca142f14d0ca78db5fff4d1ed |
|
MD5 | 33316c4b02b6195234950af19419689b |
|
BLAKE2b-256 | 404d59e0ea7a7e23b7f8f25b195cccda46cb1baa761d7aeaf34dbd4f9a4f8e1b |