Files and interoperability#

Readers, writers and converters (ag.io); ag.read and ag.write pick the format from the extension.

By extension#

read

Read a graph, choosing the reader from the extension (or format); kwargs go to the reader.

write

Write g, choosing the writer from the extension (or format); kwargs go to the writer.

JSON#

to_dict

Node-link dictionary of g (see the module docstring for the layout).

from_dict

Graph from a node-link dictionary (AryaGraph, networkx or d3 flavour).

to_json

Node-link JSON text of g (UTF-8 friendly: non-ASCII characters are kept as is).

from_json

Graph from node-link JSON text; see from_dict().

write_json

Write g as node-link JSON (UTF-8).

read_json

Read a node-link JSON file written by AryaGraph, networkx or d3.

Edge and adjacency lists#

read_edgelist

Read an edge list: one edge per line, extra columns become edge attributes.

write_edgelist

Write g as a delimited edge list (CSV by default).

read_adjacency_list

Read an adjacency list: each line is a node followed by its neighbors (successors if directed).

write_adjacency_list

Write g as an adjacency list (networkx's adjlist layout, with quoting).

GraphML#

write_graphml

Write g as a UTF-8 GraphML file.

read_graphml

Read the first graph of a GraphML file.

to_graphml

GraphML document for g as a string (see the module docstring).

from_graphml

Graph from a GraphML document string; see read_graphml().

GEXF#

write_gexf

Write g as a GEXF 1.3 file (UTF-8) for Gephi; see the module docstring for the mapping.

read_gexf

Read a static GEXF graph (versions 1.1–1.3).

DOT#

to_dot

DOT text for g.

write_dot

Write to_dot() output to path (UTF-8); keyword arguments are passed through.

from_dot

Parse DOT text into a Graph (graph) or DiGraph (digraph).

read_dot

Read a DOT file; see from_dot().

DotSyntaxError

Malformed DOT text; line and column (1-based) locate the problem.

Mermaid#

to_mermaid

Mermaid flowchart text for g.

from_mermaid

Parse a Mermaid flowchart (the subset described in the module docstring).

write_mermaid

Write to_mermaid() output to path (UTF-8).

read_mermaid

Read a Mermaid flowchart file; see from_mermaid().

networkx, pandas, numpy and SciPy#

from_networkx

AryaGraph copy of a networkx graph (node, edge and graph attributes are copied shallowly).

to_networkx

nx.Graph (undirected) or nx.DiGraph (directed, including DAGs) with every attribute copied.

from_pandas_edgelist

Graph from a DataFrame with one row per edge.

from_pandas

Graph from a node table and/or an edge table (the inverse of to_pandas()).

to_pandas

(nodes_df, edges_df): one row per node (id + attributes) and per edge (source, target + attributes).

from_numpy

Graph from a square adjacency matrix; every non-zero entry is an edge.

to_numpy

Dense adjacency matrix A[i, j] = weight of edge nodes[i] → nodes[j] (nonedge elsewhere).

from_scipy_sparse

Graph from a scipy sparse adjacency matrix (any format); same rules as from_numpy().

to_scipy_sparse

Sparse adjacency matrix (a scipy.sparse array in format: csr, csc, coo, …).