Skip to main content

NetworkXToolkit

_get_nx

Lazily import networkx module when needed.

init

Initializes the NetworkX graph client. Parameters:
  • timeout (Optional[float]): The timeout value for API requests in seconds. If None, no timeout is applied. (default: :obj:None)

add_node

Adds a node to the graph. Parameters:
  • node_id (str): The ID of the node.
  • attributes (dict): Additional node attributes.

add_edge

Adds an edge to the graph. Parameters:
  • source (str): Source node ID.
  • target (str): Target node ID.
  • attributes (dict): Additional edge attributes.

get_nodes

Returns: List[str]: A list of node IDs.

get_edges

Returns: List[Tuple[str, str]]: A list of edges as (source, target).

get_shortest_path

Finds the shortest path between two nodes. Parameters:
  • method (Literal['dijkstra', 'bellman-ford'], optional): Algorithm to compute the path. Ignored if weight is None. (default: :obj:'dijkstra')
Returns: List[str]: A list of nodes in the shortest path.

compute_centrality

Returns: Dict[str, float]: Centrality values for each node.

serialize_graph

Returns: str: The serialized graph in JSON format.

deserialize_graph

Loads a graph from a serialized JSON string. Parameters:
  • data (str): The JSON string representing the graph.

export_to_file

Exports the graph to a file in JSON format. Parameters:
  • file_path (str): The file path to save the graph.

import_from_file

Imports a graph from a JSON file. Parameters:
  • file_path (str): The file path to load the graph from.

clear_graph

Clears the current graph.

get_tools

Returns: List[FunctionTool]: A list of FunctionTool objects for the toolkit methods.