Skip to content

BoQ Tree API

Read-only tree adapter for navigating the BoQ hierarchy with parent references, depth tracking, and indexed lookups.

from pygaeb import BoQTree, BoQNode, NodeKind

tree = BoQTree(doc.award.boq)

NodeKind

Bases: str, Enum

Discriminator for the type of model a BoQNode wraps.

BoQNode

BoQNode(kind, model, parent, children, depth, index)

Read-only tree node wrapping a single BoQ model object.

Provides O(1) parent/children/depth access and subtree query helpers. Children are stored as an immutable tuple to signal read-only intent.

model property

model

The underlying Pydantic model object (same identity, not a copy).

index property

index

Position among siblings (0-based).

siblings property

siblings

All siblings excluding self. Empty tuple for root.

ancestors property

ancestors

From root to parent (excludes self). Empty for root.

path property

path

From root to self (includes self).

label_path property

label_path

Labels from root to self (human-readable breadcrumb).

iter_descendants

iter_descendants()

Depth-first iteration over all descendants (excludes self).

iter_items

iter_items()

All ITEM-kind descendants (depth-first).

iter_categories

iter_categories()

All CATEGORY-kind descendants (depth-first).

find

find(predicate)

First descendant matching predicate, or None.

find_all

find_all(predicate)

All descendants matching predicate.

BoQTree

BoQTree(boq)

Read-only tree adapter for a procurement BoQ.

Wraps an existing BoQ instance and builds a navigable node graph with parent references, depth tracking, and indexed lookups. The underlying Pydantic models are not modified.

Construction is O(n) where n is the total number of nodes.

node_count property

node_count

Total nodes in the tree (all kinds including root).

item_count property

item_count

Total ITEM-kind nodes.

find_item

find_item(oz)

O(1) item lookup by OZ. Accepts either the leaf RNoPart (e.g. "0004") or the full OZ (e.g. "01.02.0004"). Returns None if not found.

find_category

find_category(rno)

First category node with this rno (depth-first). None if not found.

find_all_categories

find_all_categories(rno)

All category nodes with this rno (e.g. same rno in different lots).

walk

walk()

Depth-first iteration over all nodes (including root).

walk_bfs

walk_bfs()

Breadth-first iteration over all nodes (including root).