I would like to suggest a minor change to Tree because I feel trees are rendered better using pprint instead of json:
import io
from pprint import pprint
def __str__(self, indent=None):
with io.StringIO() as F:
pprint(self.__dict__(), width = 1, stream = F)
return F.getvalue()
def __repr__(self):
return str(self)