pydantic_graph.nodes
Bases: Generic[StateT, DepsT]
Context for a graph.
The state of the graph.
Type: StateT
Dependencies for the graph.
Type: DepsT
Bases: ABC, Generic[StateT, DepsT, NodeRunEndT]
Base class for a node.
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.
Type: bool Default: False
@abstractmethod
@async
def 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.
BaseNode[StateT, DepsT, Any] | End[NodeRunEndT] — The next node to run or End to signal the end of the graph.
The graph context.
@cached
@classmethod
def get_node_id(cls) -> str
Get the ID of the node.
@classmethod
def get_note(cls) -> 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.
@classmethod
def get_node_def(
cls,
local_ns: dict[str, Any] | None,
) -> NodeDef[StateT, DepsT, NodeRunEndT]
Get the node definition.
NodeDef[StateT, DepsT, NodeRunEndT]
def deep_copy() -> Self
Returns a deep copy of the node.
Bases: Generic[RunEndT]
Type to return from a node to signal the end of the graph.
Data to return from the graph.
Type: RunEndT
def deep_copy_data() -> End[RunEndT]
Returns a deep copy of the end of the run.
End[RunEndT]
Annotation to apply a label to an edge in a graph.
Label for the edge.
Type variable for the state in a graph.
Default: TypeVar('StateT', default=None)
Type variable for the dependencies of a graph and node.
Default: TypeVar('DepsT', default=None, contravariant=True)
Covariant type variable for the return type of a graph run.
Default: TypeVar('RunEndT', covariant=True, default=None)
Covariant type variable for the return type of a node run.
Default: TypeVar('NodeRunEndT', covariant=True, default=Never)