Graph

Overview

class Graph(filename, hash_func=None, max_str_len=15, max_key_len=15, int_format='l', char_format='h', bool_format='?', hash_format='I', cache_len=1000000, table_increment=100000, preload=False, node_class=None, edge_class=None, flag='w')[source]

Methods

Adding and removing nodes and edges

Graph.__init__(filename[, hash_func, …])

Initialize a directed graph.

Graph.add_node(key[, attr])

Add a single node to graph, with optional attributes.

Graph.add_edge(source_key, target_key[, …])

Add a single edge with custom attributes to graph

Graph.remove_node(key)

Remove node and incident edges from graph

Graph.remove_edge(source_key, target_key[, …])

Remove the edge linking source to target, with the given edge_type

Accessing nodes, edges and neighbors

Graph.node(key)

Get node from key

Graph.edge(source, target[, edge_type])

Get edge from source, target and edge type

Graph.__getitem__(item)

Get node or edge

Graph.__setitem__(key, attr)

Create/update node with custom attributes

Graph.nodes

Iterate over all nodes

Graph.edges

Iterate over all edges

Graph.has_node(node)

Returns True if node exists

Graph.has_edge(source, target[, edge_type])

Returns True if (source, target[, edge_type]) exists

Graph.batch_get_nodes([batch_size, cursor])

Get a batch of nodes starting from a given table position

Graph.batch_get_edges([batch_size, cursor])

Get a batch of edges starting from a given table position

Graph.__contains__(item)

Returns True if node or edge exists

Graph.neighbors(u)

Iterate over all nodes v such that (u, v) is an edge

Graph.predecessors(v)

Iterate over all nodes u such that (u, v) is an edge

Graph.set_neighbors(u, new_neighbors)

Strictly assign predecessors to a node

Graph.set_predecessors(v, new_predecessors)

Strictly assign predecessors to a node

Graph.neighbors_from(nodes)

Returns the list of neighbors for all given nodes

Graph.predecessors_from(nodes[, n_jobs])

Returns the list of predecessors for all given nodes

Graph.common_neighbors(u, v)

Returns the set of common neighbors between two nodes

Graph.common_predecessors(u, v)

Returns the set of common predecessors between two nodes

Graph.close()

Closes database file.

Linear Algebra

Graph.adjacency_matrix([weight])

Return adjacency matrix of the graph

Graph.subgraph(nodes[, weight])

Return adjacency matrix of a subgraph