imas.util.tree_iter

imas.util.tree_iter(node: IDSBase, *, leaf_only: bool = True, visit_empty: bool = False, accept_lazy: bool = False, include_node: bool = False) Iterator[IDSBase]

Tree iterator for IMAS-Python structures.

Iterate (depth-first) through the whole subtree of an IMAS-Python structure.

Parameters:
node: IDSBase

Node to start iterating from.

Keyword Arguments:
leaf_only: bool = True

Iterate over:

  • True: Only leaf nodes, not internal nodes

  • False: All nodes, including internal nodes

visit_empty: bool = False

When set to True, iterate over empty nodes.

accept_lazy: bool = False

See documentation of iter_nonempty_(). Only relevant when visit_empty is False.

include_node: bool = False

When set to True the iterator will include the provided node (if the node is not a leaf node, it is included only when leaf_only is False).

Example

# Iterate over all filled leaf nodes in a given IMAS-Python IDSToplevel
for node in tree_iter(toplevel):
    print(node)

See also

visit_children() for the functional variant of this method.


Last update: 2026-01-28