> ## Documentation Index
> Fetch the complete documentation index at: https://docs.camel-ai.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Camel.toolkits.networkx toolkit

<a id="camel.toolkits.networkx_toolkit" />

<a id="camel.toolkits.networkx_toolkit.NetworkXToolkit" />

## NetworkXToolkit

```python theme={"system"}
class NetworkXToolkit(BaseToolkit):
```

<a id="camel.toolkits.networkx_toolkit.NetworkXToolkit._get_nx" />

### \_get\_nx

```python theme={"system"}
def _get_nx(cls):
```

Lazily import networkx module when needed.

<a id="camel.toolkits.networkx_toolkit.NetworkXToolkit.__init__" />

### **init**

```python theme={"system"}
def __init__(
    self,
    timeout: Optional[float] = None,
    graph_type: Literal['graph', 'digraph', 'multigraph', 'multidigraph'] = 'graph'
):
```

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`)

<a id="camel.toolkits.networkx_toolkit.NetworkXToolkit.add_node" />

### add\_node

```python theme={"system"}
def add_node(self, node_id: str, **attributes: Any):
```

Adds a node to the graph.

**Parameters:**

* **node\_id** (str): The ID of the node.
* **attributes** (dict): Additional node attributes.

<a id="camel.toolkits.networkx_toolkit.NetworkXToolkit.add_edge" />

### add\_edge

```python theme={"system"}
def add_edge(
    self,
    source: str,
    target: str,
    **attributes: Any
):
```

Adds an edge to the graph.

**Parameters:**

* **source** (str): Source node ID.
* **target** (str): Target node ID.
* **attributes** (dict): Additional edge attributes.

<a id="camel.toolkits.networkx_toolkit.NetworkXToolkit.get_nodes" />

### get\_nodes

```python theme={"system"}
def get_nodes(self):
```

**Returns:**

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

<a id="camel.toolkits.networkx_toolkit.NetworkXToolkit.get_edges" />

### get\_edges

```python theme={"system"}
def get_edges(self):
```

**Returns:**

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

<a id="camel.toolkits.networkx_toolkit.NetworkXToolkit.get_shortest_path" />

### get\_shortest\_path

```python theme={"system"}
def get_shortest_path(
    self,
    source: str,
    target: str,
    weight: Optional[Union[str, Callable]] = None,
    method: Literal['dijkstra', 'bellman-ford'] = 'dijkstra'
):
```

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.

<a id="camel.toolkits.networkx_toolkit.NetworkXToolkit.compute_centrality" />

### compute\_centrality

```python theme={"system"}
def compute_centrality(self):
```

**Returns:**

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

<a id="camel.toolkits.networkx_toolkit.NetworkXToolkit.serialize_graph" />

### serialize\_graph

```python theme={"system"}
def serialize_graph(self):
```

**Returns:**

str: The serialized graph in JSON format.

<a id="camel.toolkits.networkx_toolkit.NetworkXToolkit.deserialize_graph" />

### deserialize\_graph

```python theme={"system"}
def deserialize_graph(self, data: str):
```

Loads a graph from a serialized JSON string.

**Parameters:**

* **data** (str): The JSON string representing the graph.

<a id="camel.toolkits.networkx_toolkit.NetworkXToolkit.export_to_file" />

### export\_to\_file

```python theme={"system"}
def export_to_file(self, file_path: str):
```

Exports the graph to a file in JSON format.

**Parameters:**

* **file\_path** (str): The file path to save the graph.

<a id="camel.toolkits.networkx_toolkit.NetworkXToolkit.import_from_file" />

### import\_from\_file

```python theme={"system"}
def import_from_file(self, file_path: str):
```

Imports a graph from a JSON file.

**Parameters:**

* **file\_path** (str): The file path to load the graph from.

<a id="camel.toolkits.networkx_toolkit.NetworkXToolkit.clear_graph" />

### clear\_graph

```python theme={"system"}
def clear_graph(self):
```

Clears the current graph.

<a id="camel.toolkits.networkx_toolkit.NetworkXToolkit.get_tools" />

### get\_tools

```python theme={"system"}
def get_tools(self):
```

**Returns:**

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