Skip to content

ordeq_networkx

NetworkxGML dataclass

Bases: IO[Graph]

IO to load from and save graph data using NetworkX's GML support. Calls networkx.read_gml and networkx.write_gml under the hood.

Example usage:

>>> from pathlib import Path
>>> import networkx as nx
>>> from ordeq_networkx import NetworkxGML
>>> random_graph = nx.erdos_renyi_graph(10, 0.5)
>>> my_graph = NetworkxGML(
...     path=Path("graph.gml")
... )
>>> my_graph.save(random_graph)  # doctest: +SKIP

load(**load_options)

Load a graph from the GML file at the specified path.

Parameters:

Name Type Description Default
**load_options Any

Additional keyword arguments passed to networkx.read_gml. These can be used to control how the GML file is parsed (e.g., label, destringizer).

{}

Returns:

Type Description
Graph

The loaded NetworkX graph.

save(graph, **save_options)

Save a NetworkX graph to the GML file at the specified path.

Parameters:

Name Type Description Default
graph Graph

The NetworkX graph to save.

required
**save_options Any

Additional keyword arguments passed to networkx.write_gml. These can be used to control how the GML file is written (e.g., stringizer, prettyprint).

{}

NetworkxGraphML dataclass

Bases: IO[Graph]

IO to load from and save graph data using NetworkX's GraphML support. Calls networkx.read_graphml and networkx.write_graphml under the hood.

Example usage:

>>> from pathlib import Path
>>> import networkx as nx
>>> from ordeq_networkx import NetworkxGraphML
>>> random_graph = nx.erdos_renyi_graph(10, 0.5)
>>> my_graph = NetworkxGraphML(
...     path=Path("graph.graphml")
... )
>>> my_graph.save(random_graph)  # doctest: +SKIP

load(**load_options)

Load a graph from the GraphML file at the specified path.

Parameters:

Name Type Description Default
**load_options Any

Additional keyword arguments passed to networkx.read_graphml. These can be used to control how the GraphML file is parsed.

{}

Returns:

Type Description
Graph

The loaded NetworkX graph.

save(graph, **save_options)

Save a NetworkX graph to the GraphML file at the specified path.

Parameters:

Name Type Description Default
graph Graph

The NetworkX graph to save.

required
**save_options Any

Additional keyword arguments passed to networkx.write_graphml. These can be used to control how the GraphML file is written.

{}

NetworkxJSON dataclass

Bases: IO[Graph]

IO to load from and save graph data using NetworkX's JSON support. Calls networkx.node_link_graph and networkx.node_link_data under the hood.

Example usage:

>>> from pathlib import Path
>>> import networkx as nx
>>> from ordeq_networkx import NetworkxJSON
>>> random_graph = nx.erdos_renyi_graph(10, 0.5)
>>> my_graph = NetworkxJSON(
...     path=Path("graph.json")
... )
>>> my_graph.save(random_graph)  # doctest: +SKIP

load(**load_options)

Load a NetworkX graph from a JSON file using node-link format.

Parameters:

Name Type Description Default
**load_options Any

Additional keyword arguments passed to json.load. These can be used to control JSON decoding options.

{}

Returns:

Type Description
Graph

The loaded NetworkX graph.

save(graph, **save_options)

Save a NetworkX graph to a JSON file using node-link format.

Parameters:

Name Type Description Default
graph Graph

The NetworkX graph to save.

required
**save_options Any

Additional keyword arguments passed to json.dump. These can be used to control JSON encoding options.

{}