webgraph

Python bindings for the Rust version of the WebGraph framework.

1from ._webgraph import *
2
3__doc__ = _webgraph.__doc__
4if hasattr(_webgraph, "__all__"):
5    __all__ = _webgraph.__all__
class BvGraph:

A compressed graph in WebGraph format.

Provides forward-only access (successors) and BFS traversal. For backward (predecessor) access, load the transposed graph.

BvGraph(basename: str)
def num_nodes(self) -> int:

Return the number of nodes.

def num_arcs(self) -> int:

Return the number of arcs.

def outdegree(self, node: int) -> int:

Return the number of successors of the given node.

Raises IndexError if node is out of range.

def successors(self, node: int) -> PySuccessorsIterator:

Return an iterator over the successors of the given node.

Raises IndexError if node is out of range.

def outdegrees(self) -> numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[numpy.uint32]]:

Return a numpy uint32 array of outdegrees for all nodes, computed in parallel. The array is indexed by node ID.

def top_k_out( self, k: int) -> numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[numpy.uint64]]:

Return a (k, 2) array: column 0 = node IDs, column 1 = outdegrees.

def bfs(self) -> PyBfsIterator:

BFS over all connected components.

Yields (root, parent, node, distance) tuples where root identifies the BFS tree (starting node of the component), parent is the node from which node was discovered (equal to node for roots), and distance is the hop count from root.

def bfs_from_node(self, node: int) -> PyBfsIterator:

BFS from a single starting node.

Yields (root, parent, node, distance) tuples where root is always the starting node, parent is the node from which node was discovered (equal to node for the root), and distance is the hop count from the starting node.

Raises IndexError if node is out of range.

class PySuccessorsIterator:

Iterator over node IDs (successors or predecessors).

class PyBfsIterator:

Iterator for breadth-first traversal.

Yields (root, parent, node, distance) tuples where root identifies the BFS tree, parent is the node from which node was discovered (equal to node for roots), and distance is the hop count from root.