Skip to content

GraphML and GEXF

GraphML and GEXF helpers from annnet.io.graphml.

annnet.io.graphml

GraphML/GEXF import and export helpers for AnnNet.

Provides: to_graphml(G, path, ...) -> None from_graphml(path, ...) -> AnnNet to_gexf(G, path, ...) -> None from_gexf(path, ...) -> AnnNet

GraphML and GEXF support are implemented through NetworkX because NetworkX already owns mature readers and writers for these formats. This module is therefore an intentional IO-to-adapter bridge: AnnNet is first projected to a NetworkX graph, then NetworkX handles the file format.

This is an accepted boundary exception.

Classes

Functions

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.

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.

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.

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

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