This is the documentation for the current state of the development branch of rustworkx. The documentation or APIs here can change prior to being released.


PyDiGraph.subgraph(nodes, /, preserve_attrs=False)#

Return a new PyDiGraph object for a subgraph of this graph

  • nodes (list) – A list of node indices to generate the subgraph from. If a node index is included that is not present in the graph it will silently be ignored.

  • preserve_attrs – If set to the True the attributes of the PyDiGraph will be copied by reference to be the attributes of the output subgraph. By default this is set to False and the attrs attribute will be None in the subgraph.


A new PyDiGraph object representing a subgraph of this graph. It is worth noting that node and edge weight/data payloads are passed by reference so if you update (not replace) an object used as the weight in graph or the subgraph it will also be updated in the other.

Return type: