Skip to content

GraphML and GEXF

Read and write GraphML and GEXF files. Both go through NetworkX, so NetworkX must be installed. A graph feature that the format cannot hold goes into a sidecar file beside it. See What each format keeps.

annnet.io.graphml.from_graphml

from_graphml(path, *, hyperedge='reified', sidecar='auto')

Import via NetworkX, using the companion sidecar as the source of truth.

Without one, this is a best-effort import: GraphML keeps no edge id, so the ids are the ones NetworkX invents.

annnet.io.graphml.to_graphml

to_graphml(
    graph,
    path,
    *,
    directed=True,
    hyperedge_mode="reify",
    public_only=False,
    sidecar=True,
    hyperedges=None,
    coefficients="error"
)

Export via NetworkX with reified hyperedges; sanitize attrs for GraphML.

GraphML does not keep an edge id, so the mapping that does goes into the companion sidecar along with everything else the format cannot hold. It used to go into a .manifest.json of this module's own invention, which meant two files beside one export and two things to remember to copy.

annnet.io.graphml.from_gexf

from_gexf(path, *, hyperedge='reified', sidecar='auto')

Import a GEXF graph through NetworkX, using the companion sidecar.

annnet.io.graphml.to_gexf

to_gexf(
    graph,
    path,
    *,
    directed=True,
    hyperedge_mode="reify",
    public_only=False,
    sidecar=True,
    hyperedges=None,
    coefficients="error"
)

Export an AnnNet graph to GEXF via NetworkX.

GEXF (like GraphML) cannot encode None attribute values; the same sanitiser used for GraphML is applied here, and what the format cannot hold — edge identity among it — goes to the one companion sidecar.