from treelib import Node, Tree from treelib.exceptions import DuplicatedNodeIdError from collections.abc import Sized as root tree = Tree() def add_to_tree(node, parent=None): tree.create_node(node.__name__, id(node), parent=parent) subclasses = node.__subclasses__() for sc in subclasses: try: add_to_tree(sc, parent=id(node)) except DuplicatedNodeIdError: pass add_to_tree(root) tree.show()