hexa
hexa
Hexa: Type-declared dependency injection for Python.
Classes
MethodSpec
dataclass
Specification of a single abstract method.
PortNode
dataclass
A node in the hexa port tree.
Parameters
name : str
Slot name, e.g. "parser", "amount_balance".
kind : str
One of "leaf", "port", or "parent".
- "leaf": no children (e.g. NumberPort)
- "port": has children (e.g. TransactionParserPort)
- "parent": the root of the tree (e.g. ExtractionPipeline)
port_cls : str
ABC class name that gives this port its shape, e.g.
"TransactionParserPort". Every port has a concrete typed shape.
attributes : dict[str, ConfigValue]
Annotated attributes: name -> type_expr for scalars, or a nested
dict of sub-attributes (a struct) for grouped/structured values.
children : list[PortNode]
Nested port slots.
methods : dict[str, MethodSpec]
Abstract methods keyed by method name.
Functions
diff
Return a list of human-readable difference strings.
An empty list means the trees are equal.
Functions
build
Recursively instantiate the port tree from annotations.
Parameters
cls : type
The root class to build (e.g. AxisExtractionPipeline).
instances : dict, optional
{slot_name: object} injected verbatim into every node whose
annotations contain that name (runtime values — repos, handlers,
clients — that must not be re-constructed). Applied to the whole
tree by name.
config : dict, optional
{field_name: value} propagated by name to every node's annotated
config fields (non-port attributes), replacing the default None.
Returns
instance
A fully wired instance of cls and all its nested ports.