# API

nodestack is a Python library to manage Nodes classes. A node is an object which is related to other nodes given a tree chart.

class nodestack.Node(name: str, parent: Node | None = None)

  Should be subclassed only

  add_child(child: Node ) → None

    Add new child node to current instance

    Parameters:

      child – Node object

  static check_lineage(nodes: list[ Node ]) → bool
    check if the list of nodes is a straight lineage:

      node 1 (ancestor) -> node 2 -> node 3 -> … -> node n (grand children)

  classmethod create_random_nodes(type_: str = 'cmd', depth: int = 0) → Node

    Creates random tree of nodes for testing purpose

  get_child(name: str) → Node | None

    find and returns a child with specified name. None if nothing found

  get_sibling(name: str) → Node | None

    find and returns a sibling with specified name. None if nothing found

  has_children() → bool

    check if Node object has one child at least

  has_parent() → bool

    check if Node object has a parent or not

  has_siblings() → bool

    check if Node object has one sibling at least

  is_child(other: str) → bool

    Check if Node object is a child of the other Node object

  is_sibling(other: str) → bool

    Check if Node object is a sibling of the other Node object

    Parameters:

      other – Other Node object to be compared with

  property level: int

    Returns the level of the Node object

  property parents: list[ Node ]

    Returns all the ancestors of the Node object

  property path: str

    Returns a representation of the ancestor lineage of self

  pretty_print(option: str = 'default') → None

    Print children tree from current instance

  classmethod reset_stats() → None

    reset all the ClassVar members

  property siblings: list[ Node ]

    Returns all the siblings of the Node object