graphi.graph_io.graphml.reader module

class graphi.graph_io.graphml.reader.Namespace(**kwargs)

Bases: object

graphi.graph_io.graphml.reader.graph_reader(source, node_type=<function id_node>, value_type=<function true_namespace_value>)

Read a graph from GraphML source

  • source – a string, file path or file object containing GraphML data
  • node_type (Callable[[GraphMLNode], Any]) – type converter for nodes
  • value_type (Callable[[GraphMLEdge], Any]) – type converter for edges


Since a GraphML file may contain multiple graphs, an iterable over all contained graphs is returned.

# read a single graph
graph, = graph_reader(source_path)
# read several graphs
graphs = list(graph_reader(source_path))
# stream through graphs
for graph in graph_reader(source_path):

The node_type and value_type are used to convert the GraphML-specific GraphMLNode and GraphMLEdge to generic nodes and edge values. As edges are defined by nodes, there is no separate converter.


Create nodes from their id field


All existing edges have either a True value or a Namespace if any attributes are set