Skip to content

Formats ​

Which format should I use ​

  • Between desktop tools: GEXF with Gephi, GraphML with most others (yEd, igraph, NetworkX). Both keep typed attributes, mixed direction and parallel edges.
  • In a web page: JSON. The node-link dialect suits NetworkX and d3, cytoscape Cytoscape.js, and graphology graphology and sigma.js.
  • In a spreadsheet, a database or a script: CSV, with the node table and the edge table written as two files.
  • In Cytoscape: CX2 or XGMML to add a network to an open session, a Cytoscape session to hand over a whole session, and CX2 for NDEx. CX, CX2 and session node ids are integers, so pass sanitizeIds: "mangle" when you save a graph with text ids. A graph read back from such a file that graph-io wrote gets its original ids back; one that Cytoscape wrote has its integer ids, with the node names as labels.
  • In Neo4j: Neo4j CSV, written with exportNeo4jFiles() and loaded with neo4j-admin database import; see Files for neo4j-admin.
  • Ontologies: OBO, or the obographs dialect of JSON.
  • For a picture: DOT, which Graphviz lays out and draws.
  • For Pajek, UCINET or igraph: Pajek .net or GML. Both number their nodes, so checkExport() tells you how your ids will be written.

Every format ​

graph-io reads and writes every format below. The first table lists them; the second shows what a saved file of each format can hold, with one row per JSON dialect. A capability every format has the same value for (for example, none of them writes connected components) has no column there; each format page lists all of them. When a graph holds something a format cannot, checkExport() tells you before you save; see Saving graphs.

In the dtypes column, i32 and u32 are 32-bit integers (signed and unsigned), u8 a byte, f32 and f64 32- and 64-bit floating-point numbers (f64 is a JavaScript number), bool true or false, string text, dict text stored once per distinct value, and list and json lists and nested JSON values. "none" means the format keeps no attribute types: every value reads back as text or a guessed number.

The examples on the format pages read the sample files; each file they name is there.

FormatSubpathExtensionsReadsWritesSeveral graphs per file
json@graphty/graph-io/json.jsonyesyesyes
graphml@graphty/graph-io/graphml.graphml, .xmlyesyesno
gexf@graphty/graph-io/gexf.gexfyesyesno
csv@graphty/graph-io/csv.csv, .tsv, .edges, .edgelistyesyesno
gml@graphty/graph-io/gml.gmlyesyesyes
dot@graphty/graph-io/dot.dot, .gvyesyesyes
pajek@graphty/graph-io/pajek.net, .pajyesyesyes
neo4j@graphty/graph-io/neo4j.csv, .tsvyesyesno
xgmml@graphty/graph-io/xgmml.xgmml, .xmlyesyesyes
cx2@graphty/graph-io/cx2.cx2yesyesno
cx@graphty/graph-io/cx.cxyesyesyes
obo@graphty/graph-io/obo.oboyesyesno
cys@graphty/graph-io/cys.cysyesyesyes

What each writer keeps ​

FormatmixedDirectionedgeIdsidCharsetdtypeslistsjsondefaultsoptionshierarchytemporalgraphAttributespositionsviz
json (node-link)nononeanyf64, i32, bool, stringnoyesnononononeyesnono
json (d3)nononeanyf64, i32, bool, stringnoyesnononononenonono
json (jgf)yesoptionalanyf64, i32, bool, stringnoyesnononononeyesnono
json (cytoscape)norequiredanyf64, i32, bool, stringnoyesnonoyesnoneyesyesno
json (graphology)yesoptionalanyf64, i32, bool, stringnoyesnononononeyesnono
json (vis)nooptionalanyf64, i32, bool, stringnoyesnononononenonono
json (obographs)nononeanynonenononononononenonono
graphmlyesoptionalnmtokenbool, i32, f32, f64, stringnonoyesnoyesnoneyesnono
gexfyesoptionalanyf32, f64, i32, bool, dict, stringyesnoyesyesyesdynamic-valuesnoyesyes
csvyesoptionalanybool, i32, f64, string, dictnononononononenonono
gmlnooptionalintegeri32, f64, string, dict, jsonyesyesnononononeyesyesno
dotnooptionalanybool, i32, f64, stringnonononoyesnoneyesyesno
pajekyesnonedense-1-basedf64, i32, bool, stringnononononospellsnoyesno
neo4jnononeanyf32, f64, i32, bool, stringyesnonononononenonono
xgmmlyesoptionalanystring, dict, f64, f32, i32, u32, u8, bool, listyesnononoyesnoneyesyesno
cx2norequiredintegerstring, f64, i32, boolyesnoyesnonononeyesyesno
cxnorequiredintegerstring, f64, i32, boolyesnononoyesnoneyesyesno
obonononeanynonenononononononenonono
cysyesrequiredintegerstring, dict, f64, i32, bool, listyesnonononononeyesyesno

What the capabilities mean ​

mixedDirection ​

Whether one file can hold directed and undirected edges together. When false, a graph with both needs onMixedDirection ("directed" or "undirected") to be saved.

multiEdges ​

Whether the file can hold two edges between the same pair of nodes. When false, the extra edges are not kept as separate edges.

selfLoops ​

Whether the file can hold an edge from a node to itself. When false, such edges are lost.

edgeIds ​

Whether edges carry ids. "required": every edge has one, and ids are made up (e0, e1, ...) for a graph without them. "optional": edge ids are written when the graph has them. "none": edge ids are lost.

idCharset ​

Which node ids the format can write as they are: "any"; "nmtoken" (XML name tokens: letters, digits and . - _ :, no spaces); "integer"; or "dense-1-based" (the nodes are always numbered 1 to N). Other ids need sanitizeIds: "mangle", which writes the original ids too.

dtypes ​

The attribute types the format keeps exactly: "bool", "i32" (32-bit integer), "u32" (unsigned 32-bit integer), "u8" (byte), "f32" (32-bit float), "f64" (64-bit float, a JavaScript number), "string" (text), "dict" (text stored as a dictionary of repeated values), "list" and "json". An attribute of another type is written as the nearest one the format has, with a W_DTYPE_UNSUPPORTED note.

components ​

Whether an attribute other than the node position can hold several numbers per node or edge (a vector). When false, such an attribute does not read back as one attribute. Positions are covered by positions.

lists ​

Whether an attribute can hold a list per node or edge. When false, list attributes are lost or flattened.

json ​

Whether an attribute can hold nested JSON objects and arrays. When false, such attributes are written as text or lost.

defaults ​

Whether the file can declare a default value for an attribute. When false, declared defaults are lost.

options ​

Whether the file can declare the allowed values of an attribute (GEXF options). When false, those declarations are lost; the values themselves are kept.

hierarchy ​

Whether nodes can sit inside other nodes (groups or clusters). When false, the nesting is lost.

temporal ​

What the file can say about time: "none" (time attributes are lost), "intervals" (one start and end per element), "spells" (several intervals per element), or "dynamic-values" (attribute values that change over time, as well).

graphAttributes ​

Whether the file can hold attributes of the graph itself. When false, graph attributes are lost.

positions ​

Whether the file can hold node positions. When false, the layout is lost.

viz ​

Whether the file can hold node and edge color, size, shape and thickness. When false, they are lost.