Skip to main content

A recursive dot-styled defaultdict to read and write deeply-nested trees

Project description

easytree

pythons build PyPI version Documentation Status Code style: black Coverage

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


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)

Uploaded Source

Built Distribution

easytree-0.2.4-py3-none-any.whl (21.6 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page