pydantic_graph.nodes
StateT
module-attribute
StateT = TypeVar('StateT', default=None)
Type variable for the state in a graph.
GraphRunContext
dataclass
Context for a graph.
Source code in pydantic_graph/pydantic_graph/nodes.py
27 28 29 30 31 32 33 34 35 36 |
|
BaseNode
Bases: ABC
, Generic[StateT, DepsT, NodeRunEndT]
Base class for a node.
Source code in pydantic_graph/pydantic_graph/nodes.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
|
docstring_notes
class-attribute
docstring_notes: bool = False
Set to True
to generate mermaid diagram notes from the class's docstring.
While this can add valuable information to the diagram, it can make diagrams harder to view, hence
it is disabled by default. You can also customise notes overriding the
get_note
method.
run
abstractmethod
async
run(
ctx: GraphRunContext[StateT, DepsT],
) -> BaseNode[StateT, DepsT, Any] | End[NodeRunEndT]
Run the node.
This is an abstract method that must be implemented by subclasses.
Return types used at runtime
The return type of this method are read by pydantic_graph
at runtime and used to define which
nodes can be called next in the graph. This is displayed in mermaid diagrams
and enforced when running the graph.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ctx
|
GraphRunContext[StateT, DepsT]
|
The graph context. |
required |
Returns:
Type | Description |
---|---|
BaseNode[StateT, DepsT, Any] | End[NodeRunEndT]
|
The next node to run or |
Source code in pydantic_graph/pydantic_graph/nodes.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
|
get_node_id
cached
classmethod
get_node_id() -> str
Get the ID of the node.
Source code in pydantic_graph/pydantic_graph/nodes.py
79 80 81 82 83 |
|
get_note
classmethod
get_note() -> str | None
Get a note about the node to render on mermaid charts.
By default, this returns a note only if docstring_notes
is True
. You can override this method to customise the node notes.
Source code in pydantic_graph/pydantic_graph/nodes.py
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
|
get_node_def
classmethod
Get the node definition.
Source code in pydantic_graph/pydantic_graph/nodes.py
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
|
deep_copy
deep_copy() -> Self
Returns a deep copy of the node.
Source code in pydantic_graph/pydantic_graph/nodes.py
140 141 142 |
|
End
dataclass
Type to return from a node to signal the end of the graph.
Source code in pydantic_graph/pydantic_graph/nodes.py
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
|
deep_copy_data
Returns a deep copy of the end of the run.
Source code in pydantic_graph/pydantic_graph/nodes.py
152 153 154 155 156 157 158 159 |
|
Edge
dataclass
Annotation to apply a label to an edge in a graph.
Source code in pydantic_graph/pydantic_graph/nodes.py
177 178 179 180 181 182 |
|
DepsT
module-attribute
DepsT = TypeVar('DepsT', default=None, contravariant=True)
Type variable for the dependencies of a graph and node.
RunEndT
module-attribute
RunEndT = TypeVar('RunEndT', covariant=True, default=None)
Covariant type variable for the return type of a graph run
.