topologic package

topologic.connected_components_generator(graph: networkx.classes.graph.Graph) → Generator[networkx.classes.graph.Graph, None, None][source]

Returns a Generator that will provide each component as a networkx.Graph copy


graph (networkx.Graph) – The networkx graph object to create a connected component generator from


A Generator that returns a copy of the subgraph corresponding to a connected component of graph

Return type


exception topologic.DialectException(message)[source]

Bases: BaseException

exception topologic.InvalidGraphError(message)[source]

Bases: BaseException

topologic.largest_connected_component(graph: networkx.classes.graph.Graph, weakly: bool = True) → networkx.classes.graph.Graph[source]

Returns the largest connected component of the graph.

  • graph (networkx.Graph) – The networkx graph object to select the largest connected component from. Can be either directed or undirected.

  • weakly (bool) – Whether to find weakly connected components or strongly connected components for directed graphs.


A copy of the largest connected component as an nx.Graph object

Return type


topologic.number_connected_components(graph: networkx.classes.graph.Graph) → int[source]

Returns the number of connected components in the Graph.

This function calls the appropriate newtorkx connected components function depending on whether it is Undirected or Directed.


graph (networkx.Graph) – The networkx graph object to determine the number of connected components for


number of connected components (and in the case of a directed graph, strongly connected)

Return type


class topologic.PartitionedGraph[source]

Bases: tuple

A PartitionedGraph combines a networkx graph object with a global community partitioning for that graph.

property community_partitions

Alias for field number 1

property graph

Alias for field number 0

topologic.diagonal_augmentation(graph: Union[networkx.classes.graph.Graph, networkx.classes.digraph.DiGraph], weight_column: str = 'weight') → networkx.classes.graph.Graph[source]

Replaces the diagonal of adjacency matrix of the graph with the weighted degree / number of vertices in graph. For directed graphs, the weighted in and out degree is averaged.

Modifies the provided graph in place as well as returning it.


The networkx graph which will get a replaced diagonal


weight_column (str) – The weight column of the edge


The networkx Graph or DiGraph object that was modified in place.

Return type

Union[nx.Graph, nx.DiGraph]

exception topologic.UnweightedGraphError(message)[source]

Bases: BaseException