DGLGraph.successors(v, etype=None)[source]

Return the successor(s) of a particular node with the specified edge type.

Node u is a successor of node v if there is an edge (v, u) with type etype in the graph.

  • v (int) – The node ID. If the graph has multiple edge types, the ID is for the source type corresponding to the edge type.

  • etype (str or (str, str, str), optional) –

    The type names of the edges. The allowed type name formats are:

    • (str, str, str) for source node type, edge type and destination node type.

    • or one str edge type name if the name can uniquely identify a triplet format in the graph.

    Can be omitted if the graph has only one type of edges.


The successors of v with the specified edge type.

Return type:



The following example uses PyTorch backend.

>>> import dgl
>>> import torch

Create a homogeneous graph.

>>> g = dgl.graph((torch.tensor([0, 0, 1, 1]), torch.tensor([1, 1, 2, 3])))

Query for node 1.

>>> g.successors(1)
tensor([2, 3])

For a graph of multiple edge types, it is required to specify the edge type in query.

>>> hg = dgl.heterograph({
...     ('user', 'follows', 'user'): (torch.tensor([0, 1]), torch.tensor([1, 2])),
...     ('user', 'plays', 'game'): (torch.tensor([3, 4]), torch.tensor([5, 6]))
... })
>>> hg.successors(1, etype='follows')

See also