Skip to content

Generators, datasets and formats ​

cytoscape.use(graphtyCytoscape) adds four core methods for getting graphs in and out of Cytoscape: cy.graphtyGenerate(name, options) builds a graph from one of 59 seeded generators, cy.graphtyDataset(name, options) adds one of 15 sample datasets, cy.graphtyImport(input) reads a graph file and cy.graphtyExport(format) writes one.

The example below generates four planted communities, loads the karate club dataset, and sends that dataset through GraphML and back.

js
import cytoscape from "cytoscape";
import graphtyCytoscape from "@graphty/cytoscape-extensions";

cytoscape.use(graphtyCytoscape);

// the same seed gives the same graph on every platform
const cy = cytoscape({ headless: true });
const generated = await cy.graphtyGenerate("planted-partition", {
    groups: 4,
    groupSize: 25,
    pIn: 0.3,
    pOut: 0.01,
    seed: 1,
});
console.log(generated.elements.nodes().length, generated.directed); // 100 false
console.log(cy.$id("0").data("community")); // 0

// karate comes with the package: it loads from where the package is served, not from graphty.app
const karate = cytoscape({ headless: true });
await karate.graphtyDataset("karate");
console.log(karate.nodes().length, karate.edges().length); // 34 78

const graphml = await karate.graphtyExport("graphml");
const copy = cytoscape({ headless: true });
const imported = await copy.graphtyImport(graphml); // the format defaults to "auto"
console.log(imported.format, copy.nodes().length); // graphml 34

What the methods return ​

graphtyGenerate and graphtyDataset resolve to { elements, directed }: the added nodes and edges as a Cytoscape collection, and whether the graph is directed. graphtyImport adds format and report, and graphtyExport resolves to the file's text. Graphs in and out explains each field, how generated and imported data maps onto elements, and what each format keeps.

Generators ​

cy.graphtyGenerate(name, options) builds the graph that name names, from the options in its table. Most generators also take the two options in the first table. weights is one of { kind: "uniform", min, max } (a real number from min up to max, default 0 to 1), { kind: "integer", min, max } (both ends included), { kind: "exponential", mean } (default mean 1), { kind: "euclidean" } (the distance between the two ends, for the generators that place nodes) or { kind: "column", column, combine } (from a numeric node field of the generator). integer needs both min and max. combine turns the two ends' values into the weight: "sum" (the default), "mean", "product", "min", "max", "difference" (the absolute difference), "source" or "target". The weights land in each edge's data("weight").

Each node's id is "0", "1", ..., and edge k's id is "e<k>", so the same options and seed give the same elements. A generator's grouping (community, side, part, ...) becomes a node data field. The geometric generators, and the lattices with positions: true, give each node a position in the generator's own units, which are small (a lattice's neighbors are 1 apart). Spread them with cy.layout({ name: "preset", spacingFactor: 50 }).run(), or run another layout.

OptionTypeDefaultMeaning
weightsWeightSpecGive every edge a weight from this distribution; absent means unweighted.
seednumber0The seed of the weight draws, an integer in [0, 2^53). Random generators share it with their structure (the weights use their own stream domain, so adding weights never changes the edges).

ak ​

The AK network of B. V. Cherkassky and A. V. Goldberg, a max-flow test graph.

OptionTypeDefaultMeaning
knumberrequiredThe size parameter, in [1, 499998]: 4k + 6 nodes and 6k + 7 arcs.

balanced-tree ​

A tree in which every node above the bottom level has branching children, height levels below the root. Also takes seed and weights.

OptionTypeDefaultMeaning
branchingnumberrequiredChildren per node.
heightnumberrequiredLevels below the root.

barabasi-albert ​

A scale-free graph grown one node at a time: each new node links to m existing nodes, preferring those of high degree. Also takes seed and weights.

OptionTypeDefaultMeaning
nnumberrequiredThe node count, > m.
mnumberrequiredThe number of edges each new node brings, >= 1.
triadProbabilitynumberHolme-Kim: after each preferential edge, the probability that the next of the node's m edges closes a triangle with a neighbor of that edge's target instead. 0 (the default) is plain Barabasi-Albert.

barbell ​

Two cliques of cliqueSize nodes joined by a path of pathLength nodes. Also takes seed and weights.

OptionTypeDefaultMeaning
cliqueSizenumberrequiredNodes in each of the two cliques.
pathLengthnumberrequiredNodes on the path between the cliques.

bianconi-barabasi ​

Like barabasi-albert, but a new node prefers existing nodes of high degree times fitness, so a fit late node can overtake early ones. Also takes seed and weights.

OptionTypeDefaultMeaning
nnumberrequiredThe node count, > m.
mnumberrequiredThe number of edges each new node brings, >= 1.
fitnessArrayLike<number>random, uniform in (0, 1], fixed by seedEach node's fitness, n finite positive values.

bipartite-configuration-model ​

A random bipartite graph whose two sides have the degrees in leftDegrees and rightDegrees. Also takes seed and weights.

OptionTypeDefaultMeaning
leftDegreesArrayLike<number>requiredThe degree of every left node (nodes 0 .. L - 1).
rightDegreesArrayLike<number>requiredThe degree of every right node (nodes L .. L + R - 1); same sum as leftDegrees.
multiEdges"keep" | "erase""erase"Keep or erase repeated pairs (the first occurrence stays).

caveman ​

cliques separate cliques of size nodes, with no edges between them. Also takes seed and weights.

OptionTypeDefaultMeaning
cliquesnumberrequiredNumber of cliques, none joined to another.
sizenumberrequiredNodes per clique.

chung-lu ​

A random graph in which each node's expected degree is its entry in expectedDegrees. Also takes seed and weights.

OptionTypeDefaultMeaning
expectedDegreesArrayLike<number>requiredThe expected degree (weight) of every node, finite and >= 0.

circular-ladder ​

The circular ladder CL_n (the n-prism). Also takes seed and weights.

OptionTypeDefaultMeaning
nnumberrequiredRungs; the graph has 2n nodes.

complete ​

The complete graph K_n. Also takes seed and weights.

OptionTypeDefaultMeaning
nnumberrequiredNodes.

complete-bipartite ​

The complete bipartite graph K_{a,b}. Also takes seed and weights.

OptionTypeDefaultMeaning
anumberrequiredNodes on the first side; their side field is 0.
bnumberrequiredNodes on the second side; their side field is 1.

complete-multipartite ​

The complete multipartite graph K_{s0, s1, ...}. Also takes seed and weights.

OptionTypeDefaultMeaning
sizesreadonly number[]requiredNodes in each part; the part field numbers the parts.

configuration-model ​

A random graph whose nodes have the degrees in degrees, before any self-loops and repeated edges are erased. Also takes seed and weights.

OptionTypeDefaultMeaning
degreesArrayLike<number>requiredThe degree of every node; the sum must be even.
selfLoops"keep" | "erase""erase"Keep or erase self-loops.
multiEdges"keep" | "erase""erase"Keep or erase repeated pairs (the first occurrence in edge order stays).

connected-caveman ​

cliques cliques of size nodes joined into a ring: in each clique one edge is moved to reach the previous clique. Also takes seed and weights.

OptionTypeDefaultMeaning
cliquesnumberrequiredNumber of cliques, joined in a ring.
sizenumberrequiredNodes per clique.

cycle ​

The cycle C_n. Also takes seed and weights.

OptionTypeDefaultMeaning
nnumberrequiredNodes.

degree-corrected-sbm ​

Blocks of nodes (sizes) whose degrees follow expectedDegrees, with a mixing share of each node's edges leaving its block. Also takes seed and weights.

OptionTypeDefaultMeaning
sizesreadonly number[]requiredThe size of every block; block b holds the next sizes[b] node indices.
expectedDegreesArrayLike<number>requiredThe target degree of every node, finite and >= 0; length = the sum of sizes.
mixingnumberrequiredThe mixing parameter mu in [0, 1]: the share of each node's edges that leave its block.

directed-configuration-model ​

A random directed graph whose nodes have the out- and in-degrees in outDegrees and inDegrees. Also takes seed and weights.

OptionTypeDefaultMeaning
outDegreesArrayLike<number>requiredThe out-degree of every node.
inDegreesArrayLike<number>requiredThe in-degree of every node; same length and same sum as outDegrees.
selfLoops"keep" | "erase""erase"Keep or erase self-loops.
multiEdges"keep" | "erase""erase"Keep or erase repeated ordered pairs (the first occurrence stays).

duplication-divergence ​

A graph grown by copying a random node and keeping each of its edges with probability retention, a model of protein interaction networks. Also takes seed and weights.

OptionTypeDefaultMeaning
nnumberrequiredThe node count, >= 2.
retentionnumberrequiredThe probability that a duplicate keeps each of the original's edges, in (0, 1].

empty ​

n nodes and no edges. Also takes seed and weights.

OptionTypeDefaultMeaning
nnumberrequiredNodes.

erdos-renyi ​

n nodes, each of the possible edges present with probability p, independently. Also takes seed and weights.

OptionTypeDefaultMeaning
nnumberrequiredThe node count, >= 0.
pnumberrequiredThe probability of each pair, in [0, 1].
directedbooleanfalse (unordered pairs)Directed: every ordered pair (u, v), u != v, is an arc independently with probability p.

erdos-renyi-gnm ​

n nodes and exactly m edges, chosen uniformly at random. Also takes seed and weights.

OptionTypeDefaultMeaning
nnumberrequiredThe node count, >= 0.
mnumberrequiredThe edge count, in [0, n (n - 1) / 2].

forest-fire ​

A directed graph grown one node at a time: each new node picks a random node, spreads from it through its neighbors as a fire would, and links to every node reached. Also takes seed and weights.

OptionTypeDefaultMeaning
nnumberrequiredThe node count, >= 1.
forwardnumberrequiredThe forward burning probability p, in [0, 1).
backwardnumberrequiredThe backward burning ratio r >= 0; the backward burning probability r p must be below 1.
maxBurnnumber1000The most nodes one new node may burn (and link to), >= 1.

genrmf ​

GENRMF, the max-flow family of D. Goldfarb and M. D. Grigoriadis. Also takes seed.

OptionTypeDefaultMeaning
anumberrequiredThe side of every frame (an a x a grid), >= 1.
bnumberrequiredThe number of frames, >= 1.
c1numberrequiredThe smallest capacity between frames, an integer >= 0.
c2numberrequiredThe largest capacity between frames, an integer >= c1; arcs inside a frame carry c2 a^2.

grid ​

The rows x cols grid. Also takes seed and weights.

OptionTypeDefaultMeaning
directedbooleanEmit each edge once as an arc from the lower index to the higher: a DAG whose only source is node 0 and only sink node n - 1. Not with periodic.
rowsnumberrequiredThe number of rows, >= 1.
colsnumberrequiredThe number of columns, >= 1.
periodicbooleanWrap around (a torus): the last node of each row, column and layer is joined to the first. A dimension shorter than 3 does not wrap, so the graph stays simple.
diagonalsbooleanJoin diagonal neighbors too: the king's graph (8 neighbors) in 2D, the 26-neighbor lattice in 3D.
obstaclesnumberBlock each node independently with this probability, in [0, 1): a blocked node keeps its index (and position) but has no edges, and the u8 node column blocked marks it (1).
positionsbooleanGive each node its place on the lattice, in lattice units: x and y become the node's position, and on grid-3d z becomes a data field.

grid-3d ​

The rows x cols x layers grid. Also takes seed and weights.

OptionTypeDefaultMeaning
rowsnumberrequiredThe number of rows, >= 1.
colsnumberrequiredThe number of columns, >= 1.
layersnumberrequiredThe number of layers, >= 1.
periodicbooleanWrap around (a torus): the last node of each row, column and layer is joined to the first. A dimension shorter than 3 does not wrap, so the graph stays simple.
diagonalsbooleanJoin diagonal neighbors too: the king's graph (8 neighbors) in 2D, the 26-neighbor lattice in 3D.
directedbooleanEmit each edge once as an arc from the lower index to the higher: a DAG whose only source is node 0 and only sink node n - 1. Not with periodic.
obstaclesnumberBlock each node independently with this probability, in [0, 1): a blocked node keeps its index (and position) but has no edges, and the u8 node column blocked marks it (1).
positionsbooleanGive each node its place on the lattice, in lattice units: x and y become the node's position, and on grid-3d z becomes a data field.

grid-flow-network ​

A grid flow network, the shape of graph-cut image segmentation. Also takes seed.

OptionTypeDefaultMeaning
rowsnumberrequiredThe grid's row count, >= 1.
colsnumberrequiredThe grid's column count, >= 2.
minCapacitynumber1The smallest arc capacity, an integer >= 0.
maxCapacitynumber10The largest arc capacity, an integer >= minCapacity.

hexagonal-lattice ​

The hexagonal (honeycomb) lattice in its brick-wall form. Also takes seed and weights.

OptionTypeDefaultMeaning
rowsnumberrequiredThe number of rows, >= 1.
colsnumberrequiredThe number of columns, >= 1.
positionsbooleanGive each node its place on the lattice, in lattice units: x and y become the node's position, and on grid-3d z becomes a data field.

hyperbolic ​

Random points in a hyperbolic disk, joined when close: degrees follow a power law (exponent) and neighbors share many neighbors. Also takes seed and weights.

OptionTypeDefaultMeaning
nnumberrequiredThe node count, in [0, 20000].
averageDegreenumberrequiredThe target mean degree, a finite number > 0; the mean degree you get is close to it, not equal.
exponentnumberrequiredThe power-law exponent gamma of the degree distribution, a finite number > 2.
temperaturenumber0The temperature T in [0, 1); 0 (default) is the threshold model, higher T lowers clustering.

hypercube ​

The hypercube Q_d. Also takes seed and weights.

OptionTypeDefaultMeaning
dimensionnumberrequiredThe dimension d; the graph has 2^d nodes.

knn ​

The k-nearest-neighbor graph of random points, the standard input of spectral clustering. Also takes seed and weights.

OptionTypeDefaultMeaning
nnumberrequiredThe node count, >= 0.
knumberrequiredThe neighbors per node, in [0, n - 1].
dimension2 | 322 (default) or 3.
directedbooleantrueArcs u -> each of u's k nearest, or with false the undirected union without duplicates.
clustersnumberuniform pointsDraw the points from a mixture of this many Gaussian clusters, >= 1.
spreadnumber0.05The standard deviation of every cluster on each axis, a finite number >= 0. Needs clusters.

kronecker ​

A random graph of k^power nodes drawn by nesting the k x k initiator matrix inside itself, with heavy-tailed degrees. Also takes seed and weights.

OptionTypeDefaultMeaning
initiatorreadonly (readonly number[])[]requiredThe k x k initiator matrix, k >= 1, entries in [0, 1].
powernumberrequiredThe Kronecker power, in [1, 64]; the graph has k^power nodes.
edgesnumberround((sum of the initiator)^power)The number of edges to sample.
selfLoops"keep" | "erase"Self-loops: "keep" (the default) or "erase" them.
multiEdges"keep" | "erase"Repeated pairs: "keep" (the default) or "erase" all but the first occurrence in edge order. For an undirected graph (u, v) and (v, u) are the same pair.
permutebooleanfalseRelabel the nodes by a uniformly random permutation, as Graph500 does.
directedbooleantrueWhether the graph is directed.

ladder ​

The ladder L_n. Also takes seed and weights.

OptionTypeDefaultMeaning
nnumberrequiredRungs; the graph has 2n nodes.

layered-flow-network ​

A random layered flow network. Also takes seed.

OptionTypeDefaultMeaning
layersreadonly number[]requiredThe width of every inner layer, >= 1 each; layer i holds the next layers[i] node indices.
pnumberrequiredThe probability of each arc from a node to a node of the next layer.
minCapacitynumber1The smallest arc capacity, an integer >= 0.
maxCapacitynumber10The largest arc capacity, an integer >= minCapacity.

lfr ​

A graph with planted communities whose degrees and community sizes follow power laws, used to test community detection; mixing is the share of each node's edges that leave its community. Also takes seed and weights.

OptionTypeDefaultMeaning
nnumberrequiredThe node count, in [1, 1,000,000].
minDegreenumberrequiredThe smallest degree, >= 1.
maxDegreenumberrequiredThe largest degree, in [minDegree, n - 1].
degreeExponentnumberrequiredThe degree power-law exponent (tau1), a finite number >= 0, typically 2 to 3.
minCommunitynumberrequiredThe smallest community, >= 1.
maxCommunitynumberrequiredThe largest community, in [minCommunity, n].
communityExponentnumberrequiredThe community-size power-law exponent (tau2), a finite number >= 0, typically 1 to 2.
mixingnumberrequiredThe mixing parameter mu in [0, 1]: the share of each node's edges that leave its community.

lollipop ​

A clique of cliqueSize nodes with a path of pathLength nodes hanging off it. Also takes seed and weights.

OptionTypeDefaultMeaning
cliqueSizenumberrequiredNodes in the clique.
pathLengthnumberrequiredNodes on the tail.

mobius-ladder ​

The Moebius ladder M_{2n}. Also takes seed and weights.

OptionTypeDefaultMeaning
nnumberrequiredRungs; the graph has 2n nodes.

named ​

A named graph from the literature, chosen by name. Also takes seed and weights.

OptionTypeDefaultMeaning
name"bull" | "chvatal" | "cubical" | "desargues" | "diamond" | "dodecahedral" | "frucht" | "heawood" | "hoffman-singleton" | "house" | "house-x" | "icosahedral" | "krackhardt-kite" | "moebius-kantor" | "octahedral" | "pappus" | "sedgewick-maze" | "tetrahedral" | "truncated-cube" | "truncated-tetrahedron" | "tutte"requiredWhich graph.

newman-watts ​

A ring in which each node links to its k nearest neighbors, plus random shortcuts, one per ring edge with probability p. Also takes seed and weights.

OptionTypeDefaultMeaning
nnumberrequiredThe node count, > k.
knumberrequiredEach node's ring neighbors, even, >= 2.
pnumberrequiredThe probability of a shortcut per ring edge, in [0, 1].

path ​

The path P_n. Also takes seed and weights.

OptionTypeDefaultMeaning
nnumberrequiredNodes.

petersen ​

The Petersen graph: 10 nodes and 15 edges, every node of degree 3. Also takes seed and weights.

No options of its own.

planted-partition ​

groups groups of groupSize nodes: two nodes are joined with probability pIn inside a group and pOut across groups. Also takes seed and weights.

OptionTypeDefaultMeaning
groupsnumberrequiredThe number of groups, >= 1.
groupSizenumberrequiredThe size of every group, >= 1.
pInnumberrequiredThe edge probability inside a group.
pOutnumberrequiredThe edge probability between groups.

price ​

A directed citation network: each new node cites citations earlier nodes, preferring those already cited often. Also takes seed and weights.

OptionTypeDefaultMeaning
nnumberrequiredThe node count, >= 1.
citationsnumberrequiredThe number of earlier nodes each new node cites, >= 1 (fewer while fewer exist).
attractivenessnumber1The attractiveness a > 0 added to every in-degree.

random-apollonian ​

A planar graph built by placing each new node inside a random triangle and joining it to the triangle's three corners. Also takes seed and weights.

OptionTypeDefaultMeaning
nnumberrequiredThe node count, >= 3.

random-bipartite ​

Two sides of n1 and n2 nodes, each pair across the sides joined with probability p. Also takes seed and weights.

OptionTypeDefaultMeaning
n1numberrequiredThe left side's size, >= 0.
n2numberrequiredThe right side's size, >= 0.
pnumberrequiredThe probability of each left-right pair, in [0, 1].
perfectMatchingbooleanPlant a perfect matching: left node i is always joined to right node matching[i] of a uniformly random permutation, so a perfect matching is guaranteed. Needs n1 === n2.

random-dag ​

A directed acyclic graph in layers: each node links to each node of the next layer with probability p. Also takes seed and weights.

OptionTypeDefaultMeaning
layersreadonly number[]requiredThe width of every layer, top to bottom; layer i holds the next layers[i] node indices.
pnumberrequiredThe probability of each arc from a node to a node of the next layer.

random-geometric ​

n random points in the unit square (or cube), joined when they are at most radius apart. Also takes seed and weights.

OptionTypeDefaultMeaning
nnumberrequiredThe node count, >= 0.
radiusnumberrequiredThe connection radius, a finite number >= 0: u and v are joined iff their distance is <= radius.
dimension2 | 32 (the unit square, default) or 3 (the unit cube).
periodicbooleanfalseMeasure distance on the torus (each axis wraps around), removing the boundary effect.

random-order-dag ​

A directed acyclic graph on n nodes: each arc i -> j with i < j is present with probability p. Also takes seed and weights.

OptionTypeDefaultMeaning
nnumberrequiredThe node count, >= 0.
pnumberrequiredThe probability of each arc i -> j, i < j, in [0, 1].

random-recursive-tree ​

A tree grown one node at a time, each new node joined to an earlier node chosen at random. Also takes seed and weights.

OptionTypeDefaultMeaning
nnumberrequiredThe node count, >= 1.

random-regular ​

A uniformly-ish random d-regular simple graph by the pairing algorithm of A. Steger and N. C. Wormald. Also takes seed and weights.

OptionTypeDefaultMeaning
nnumberrequiredThe node count, >= 0.
dnumberrequiredThe degree of every node, in [0, n - 1]; n d must be even.

random-tree ​

A uniformly random labelled tree. Also takes seed and weights.

OptionTypeDefaultMeaning
nnumberrequiredThe node count, >= 1.

ring-of-cliques ​

cliques cliques of size nodes joined in a ring, one edge between each clique and the next. Also takes seed and weights.

OptionTypeDefaultMeaning
cliquesnumberrequiredNumber of cliques, joined in a ring by one edge each.
sizenumberrequiredNodes per clique.

rmat ​

A random directed graph of 2^scale nodes with heavy-tailed degrees, the Graph500 benchmark generator. Also takes seed and weights.

OptionTypeDefaultMeaning
scalenumberrequiredlog2 of the node count, in [0, 31].
edgeFactornumber16 (Graph500)Edges per node, an integer >= 0.
anumber0.57 (Graph500)The top-left quadrant probability.
bnumber0.19The top-right quadrant probability.
cnumber0.19The bottom-left quadrant probability.
dnumber0.05The bottom-right quadrant probability. a + b + c + d must be 1.
selfLoops"keep" | "erase"Self-loops: "keep" (the default) or "erase" them.
multiEdges"keep" | "erase"Repeated pairs: "keep" (the default) or "erase" all but the first occurrence in edge order. For an undirected graph (u, v) and (v, u) are the same pair.
permutebooleanfalseRelabel the nodes by a uniformly random permutation, as Graph500 does.
directedbooleantrueWhether the graph is directed.

star ​

A hub joined to n - 1 leaves. Also takes seed and weights.

OptionTypeDefaultMeaning
nnumberrequiredNodes, the hub included.

stochastic-block-model ​

Blocks of nodes (sizes): two nodes are joined with the probability probabilities gives for their two blocks. Also takes seed and weights.

OptionTypeDefaultMeaning
sizesreadonly number[]requiredThe size of every block; block b holds the next sizes[b] node indices.
probabilitiesreadonly (readonly number[])[]requiredThe symmetric B x B matrix of edge probabilities between blocks.

triangular-lattice ​

The triangular lattice as a triangulated rows x cols grid. Also takes seed and weights.

OptionTypeDefaultMeaning
rowsnumberrequiredThe number of rows, >= 1.
colsnumberrequiredThe number of columns, >= 1.
positionsbooleanGive each node its place on the lattice, in lattice units: x and y become the node's position, and on grid-3d z becomes a data field.

watts-strogatz ​

A small world: a ring in which each node links to its k nearest neighbors, each edge then moved to a random node with probability beta. Also takes seed and weights.

OptionTypeDefaultMeaning
nnumberrequiredThe node count, > k.
knumberrequiredEach node's ring neighbors before rewiring, even, >= 2.
betanumberrequiredThe rewiring probability of each edge, in [0, 1].

waxman ​

n random points in the unit square, each pair joined with probability beta at distance 0, falling as they get farther apart. Also takes seed and weights.

OptionTypeDefaultMeaning
nnumberrequiredThe node count, >= 0; beta n^2 / 2 must stay below 5e8.
alphanumberrequiredThe distance scale, a finite number > 0: larger alpha makes long edges likelier.
betanumberrequiredThe edge probability at distance 0, in [0, 1].

wheel ​

A cycle of n - 1 nodes, each also joined to a hub. Also takes seed and weights.

OptionTypeDefaultMeaning
nnumberrequiredNodes, the hub included.

wilson-maze ​

A uniform spanning tree of the rows x cols grid, a perfect maze, by Wilson's algorithm. Also takes seed and weights.

OptionTypeDefaultMeaning
rowsnumberrequiredThe number of rows, >= 1.
colsnumberrequiredThe number of columns, >= 1.

Datasets ​

cy.graphtyDataset(name, options) adds one of these. None of them is inside the package: each is downloaded from <baseUrl>/<name>.gsnp.gz when it is asked for, in Node and in a browser alike, so a page opened from file:// works too. The Download column is the size of that file. When the server answers with an error status, the call rejects with a plain Error (no name or code of its own) whose message is fetching <url> failed: HTTP <status>, for example HTTP 404. A network failure rejects with the error fetch threw.

OptionTypeDefaultMeaning
baseUrlstring"https://graphty.app/data/graph-samples/v1/"Where the datasets are fetched from, for a mirror of your own. A trailing slash is optional. Without a baseUrl of your own, a name that is not in the list below rejects with a RangeError naming the closest dataset; with one, any name is fetched.
fetchtypeof fetchthe global fetchThe fetch function the datasets are downloaded with.
signalAbortSignalCancels the load: once it is aborted the call rejects with an AbortError and adds nothing, whatever fetch does with it.

Each dataset's fields are node data fields, and weight is an edge data field. Nodes have no position: the latitude and longitude of the geographic datasets are data fields, so place the nodes with a preset layout or run another layout.

Each dataset is the work of its authors and carries its own license, not this package's. Cite the source when you publish results from one, and check the license before you redistribute it.

NameNodesEdgesDirectedData fieldsDownloadLicenseSource
karate3478nonodes: club; edges: weight2 kBFacts published in a 1977 journal article; converted from the networkx 3.1 copy (BSD-3-Clause).https://raw.githubusercontent.com/networkx/networkx/networkx-3.1/networkx/generators/social.py
florentine-families1520nonone1 kBFacts published in the cited articles; converted from the networkx 3.1 copy (BSD-3-Clause).https://raw.githubusercontent.com/networkx/networkx/networkx-3.1/networkx/generators/social.py
davis-southern-women3289nonodes: side2 kBFacts published in a 1941 book; converted from the networkx 3.1 copy (BSD-3-Clause).https://raw.githubusercontent.com/networkx/networkx/networkx-3.1/networkx/generators/social.py
les-miserables77254noedges: weight4 kBDerived from the Stanford GraphBase file jean.dat (copyright D. E. Knuth; may be freely copied and distributed, and a changed file must be renamed and identified as not part of the Stanford GraphBase -- this is such a changed file) through the networkx 3.1 copy (BSD-3-Clause).https://raw.githubusercontent.com/networkx/networkx/networkx-3.1/networkx/generators/social.py
football115613nonodes: label, conference8 kBCC BY 4.0 (the figshare record of T. S. Evans).https://figshare.com/articles/dataset/American_College_Football_Network_Files/93179
political-books105441nonodes: label, lean7 kBunclear: Mark Newman's data page says only "free for scientific use to the best of my knowledge"; the SuiteSparse Matrix Collection republishes the graph under CC BY 4.0.https://web.archive.org/web/20240730210010id_/https://public.websites.umich.edu/~mejn/netdata/polbooks.zip
dolphins62159nonodes: label3 kBunclear: posted on Mark Newman's data page with the permission of D. Lusseau, "free for scientific use"; the SuiteSparse Matrix Collection republishes the graph under CC BY 4.0.https://web.archive.org/web/20231115052843id_/https://www-personal.umich.edu/~mejn/netdata/dolphins.zip
contiguous-usa49107nonodes: label, latitude, longitude, population4 kBPublic domain: works of the US federal government (17 U.S.C. 105). Borders derived from the Census county adjacency file; centers of population from https://www2.census.gov/geo/docs/reference/cenpop2020/CenPop2020_Mean_ST.txthttps://www2.census.gov/geo/docs/reference/county_adjacency/county_adjacency2024.txt
knuth-miles1288128nonodes: latitude, longitude, population; edges: weight99 kBDerived from the Stanford GraphBase file miles.dat (copyright 1992 Stanford University; "may be freely copied but please do not change it in any way") -- this is a changed file, converted to a graph, and is not part of the Stanford GraphBase.https://mirrors.ctan.org/support/graphbase/miles.dat
celegans-neural2972345yesnodes: label; edges: weight17 kBunclear: Mark Newman's data page says only "free for scientific use to the best of my knowledge"; the SuiteSparse Matrix Collection republishes the graph under CC BY 4.0.https://web.archive.org/web/20231227004245id_/https://public.websites.umich.edu/~mejn/netdata/celegansneural.zip
political-blogs149019022yesnodes: label, lean, directory143 kBunclear: posted on Mark Newman's data page with the authors' permission, "free for scientific use"; the SuiteSparse Matrix Collection republishes the graph under CC BY 4.0.https://web.archive.org/web/20240730122800id_/https://public.websites.umich.edu/~mejn/netdata/polblogs.zip
openflights321436906yesnodes: label, city, country, latitude, longitude; edges: weight370 kBOpen Database License (ODbL) 1.0, contents under the Database Contents License 1.0. This converted database is a derived database and is itself available under the ODbL 1.0.https://github.com/jpatokal/openflights/tree/e3bc6dedbcceb8b7b74248a00dcd6207254da6bd/data
yeast-perturbation331361yesnode positions; nodes: label, gal1RGexp, gal4RGexp, gal80Rexp14 kBCC0-1.0 (cytoscape-tutorials LICENSE).https://raw.githubusercontent.com/cytoscape/cytoscape-tutorials/8d1f66e4cd12446f4a928ab72e3cf2660cd6c74a/protocols/data/galFiltered.cys
stelzl-interactome16913128yesnode positions; nodes: label51 kBCC0-1.0 (cytoscape-tutorials LICENSE).https://raw.githubusercontent.com/cytoscape/cytoscape-tutorials/8d1f66e4cd12446f4a928ab72e3cf2660cd6c74a/protocols/data/STELZ.cys
wikipathways-senescence-autophagy161118yesnode positions; nodes: label, type5 kBCC0 1.0 (the network's rights: Waiver-No Rights Reserved (CC0), holder WikiPathways).https://www.ndexbio.org/v3/networks/72288e93-5c67-11ec-b3be-0ac135e8bacf
go-slim-generic14062yesnodes: label, namespace4 kBCC BY 4.0 (Gene Ontology Consortium; https://geneontology.org/docs/go-citation-policy/).https://release.geneontology.org/2026-08-05/ontology/subsets/goslim_generic.obo
road-ny264346733846yesnodes: longitude, latitude; edges: weight9.4 MBPublic domain: derived from the US Census Bureau TIGER/Line files, a work of the US federal government; the challenge page states no further terms.http://www.diag.uniroma1.it/challenge9/data/USA-road-d/USA-road-d.NY.gr.gz
ogbn-arxiv1693431166243yesnodes: year, subject10.6 MBODC-BY 1.0 (Open Data Commons Attribution License), as stated by the Open Graph Benchmark.http://snap.stanford.edu/ogb/data/nodeproppred/arxiv.zip
go-basic4834071496yesnodes: label, namespace, obsolete1.4 MBCC BY 4.0 (Gene Ontology Consortium; https://geneontology.org/docs/go-citation-policy/).https://release.geneontology.org/2026-08-05/ontology/go-basic.obo
disease-ontology1485417479yesnodes: label, obsolete289 kBCC0 1.0 (the ontology's own terms:license).https://raw.githubusercontent.com/DiseaseOntology/HumanDiseaseOntology/v2026-09-30/src/ontology/doid.obo
bioplex3-hct1161025175346yesnode positions; nodes: label719 kBCC0 1.0 (the network's rights: Waiver-No rights reserved (CC0), holder Harvard Medical School).https://www.ndexbio.org/v3/networks/e96d063d-237a-11ea-bb65-0ac135e8bacf
com-dblp3170801049866nonone15.6 MBunclear: SNAP states no license for its files; the underlying dblp data is CC0 1.0 (https://dblp.org/db/about/copyright.html).https://snap.stanford.edu/data/bigdata/communities/com-dblp.ungraph.txt.gz

File formats ​

cy.graphtyImport(input, format, options) reads every format below; format defaults to "auto", which detects it from the content. cy.graphtyExport(format, options) writes the ones marked for export. Each format's own options follow the table. graphtyExport also takes directed, onLoss and sanitizeIds (default "mangle"), and graphtyImport takes weightFrom, signal and onProgress; Graphs in and out explains them.

FormatImportExportWhat it is
gexfyesyesGephi's XML format, with node and edge attributes and positions.
graphmlyesyesThe XML format of yEd and NetworkX, with typed node and edge attributes.
gmlyesyesGraph Modelling Language text, as NetworkX and igraph write it.
dotyesyesGraphviz DOT text.
pajekyesyesPajek .net text: a *Vertices list, then *Edges or *Arcs lists.
csvyesyesDelimited text. By default an edge table with a header row naming the source and target columns; its other columns become edge data. table: "nodes" reads a node table, and nodes takes a node table to read with the edges.
jsonyesyesJSON graphs: Cytoscape JSON (what cy.json() writes, and the export default), NetworkX node-link, d3, JSON Graph Format, graphology and vis.js. An import detects the dialect.
neo4jyesyesThe CSV files of neo4j-admin import: a node file with an :ID column as the input, and relationship files with :START_ID and :END_ID columns in relationships. The text graphtyExport writes holds both, and one graphtyImport call reads it back; relationships is for separate files.
xgmmlyesyesThe XML network format of Cytoscape desktop (2.x and 3.x). Cytoscape desktop opens the XGMML graphtyExport writes, so it is the way back into Cytoscape desktop.
cx2yesyesCytoscape Exchange 2 JSON, what Cytoscape desktop and NDEx write.
cxyesnoCytoscape Exchange version 1 JSON.
oboyesnoAn ontology in OBO flat file form, such as the Gene Ontology: each [Term] is a node, and its is_a and relationship lines are edges.
cysyesnoA Cytoscape desktop session file (.cys), passed as bytes (an ArrayBuffer or Uint8Array), not text. It reads the session's first network; graphIndex or graphName picks another.

gexf ​

graphtyImport options:

OptionTypeDefaultMeaning
vizbooleanRead the viz elements: color, position, size, shape and thickness. false ignores them, with one warning.
ids"string" | "number" | "keep" | "canonical""keep" for JSONHow id text becomes a node id. "canonical": integer text such as "42" becomes the number 42 and everything else ("042", "4.2", "a") stays text. "string": every id stays text. "number": every id is read as a number, so "042" and "42" become one node (with a warning) and text that is not a number is an error. "keep": ids keep the type the file gives them. The default is "keep" for JSON, OBO, XGMML, CX, CX2 and Cytoscape sessions, and "canonical" for the other formats.
nodeIdFrom"id" | "label" | "index"Which value becomes the node id: the file's own id ("id"), the node's label ("label"), or its position among the nodes, counting from 0 ("index"). Use it when a file's ids are meaningless numbers and the labels are the real names. In d3 JSON, "index" also reads edges whose ends are node positions. In GML and Pajek it only renames: every node still needs its id key or vertex number, because edges refer to nodes by it, and a GML node without an id key is skipped with E_MISSING_ID. CSV reads this option only when there is a node table, and it does not just rename: with "label" the node table's label column (label, or the labelColumn option) gives the ids, so the edge table must name its nodes by those labels.
addMissingNodesbooleanfalse for GEXFWhether an edge may name a node the file never declares; that node is then created. When false, such an edge is skipped as an error. The default is false for GEXF, XGMML, CX, CX2 and Cytoscape sessions, whose files must declare every node, and true for the other formats.
duplicateEdges"max" | "keep" | "error" | "first" | "last" | "sum" | "min"What to do with a second edge between the same two nodes: "keep" keeps both, "first" / "last" keep one, "sum" / "min" / "max" keep one with the weights combined, and "error" stops the import. Merged edges are reported once as W_EDGES_MERGED.
selfLoops"keep" | "error" | "drop"What to do with an edge from a node to itself: "keep", "drop" (reported once as W_SELF_LOOPS_DROPPED with the number removed), or "error" to stop the import.
onMixedDirection"directed" | "error" | "expand" | "undirected"How edge direction is read. "expand" (the default) keeps the file's direction, and for a file that has both directed and undirected edges makes a directed graph in which each undirected edge is two edges, marked so an export can write them back as one. "directed" / "undirected" read every edge of any file that way, including a file whose edges all have the other direction, with a W_DIRECTION_FORCED warning. "error" stops the import at the first edge whose direction differs from the file's.
defaultDirectedbooleanundirected for GraphMLWhether the graph is directed when the file does not say. The default is undirected for GraphML, GEXF, GML, JSON and XGMML, and directed for CSV, Pajek and Cytoscape sessions. DOT, Neo4j, CX, CX2 and OBO files always settle the direction themselves (DOT by graph or digraph; the others are always directed), so those formats do not read this option and report it as W_OPTION_IGNORED.
weightFromstring"weight"The edge attribute read as the edge weight. The default is "weight", except "value" for GML and Pajek and none for OBO. Pass null to read every attribute as a plain attribute and leave the graph unweighted. A name no edge has leaves the graph unweighted, with a W_WEIGHT_NOT_FOUND warning: one options object with weightFrom: "weight" shared across formats reads GML and Pajek files, which keep their weights in value, without weights. An edge whose weight cell is empty or missing gets the default weight 1, and an export writes no weight for it.
weightDtype"f32" | "f64"Whether weights a 32-bit float cannot hold exactly are also kept exactly. "f64" keeps them in an edge column that snapshot.edges.byRole("weight") finds, so 0.1 and 16777217 stay exact. "f32" keeps no such column and uses less memory: the 32-bit weight arrays snapshot.weights and snapshot.edgeList().weights, which every import fills, are then the only weights.
long"string" | "f64"How a column the file declares as a 64-bit integer is stored: "f64" (a number, exact up to 2^53) or "string" (every digit kept, as text). GML declares no types, so there it applies to a key whose integer values go beyond 2^53.
restoreMangledIdsbooleanWhether to give back the original ids that an export with sanitizeIds: "mangle" had to rewrite. The export writes them to the file in an attribute whose name each format page gives. When false, the rewritten ids stay the ids and the originals are an ordinary node attribute, named after the format's spelling: graphty.originalId in GraphML, graphty_originalId in GML and Pajek, graphty:originalId in CX, CX2 and Cytoscape sessions, and a graphty:originalId entry of the property_value attribute in OBO.
hyperedges"error" | "skip" | "star" | "clique"What to do with a GraphML or JGF hyperedge (an edge with more than two ends): "skip" leaves it out with a warning, "error" stops the import, and "star" and "clique" turn it into ordinary edges. "clique" joins every pair of ends. "star" works differently per format: GraphML adds a new hub node joined to every end, while JGF makes the hyperedge's first node the hub, so no node is added. A directed JGF hyperedge (source and target arrays) becomes one edge from every source to every target under both. In JGF every edge made from a hyperedge carries the hyperedge's id, label, relation and metadata; GraphML drops a hyperedge's <data> and its <desc>, with a warning.
errorLimitnumberHow many errors an import tolerates. Each error skips one node, edge or value and is listed in the report; one error more than this stops the import with an ImportError. Pass 0 to stop at the first error.
signalAbortSignalCancels the import. When it aborts, the import stops and rejects with the signal's reason (an AbortError, or a TimeoutError from AbortSignal.timeout()).
onProgress(bytesDone: number, bytesTotal?: number | undefined) => voidCalled as the input is read, with the bytes read so far and the total. For a string or a Uint8Array the total is known from the first call. For a stream (which includes loadFromUrl() and loadFromFile()) it is undefined until the last call, which always has bytesDone === bytesTotal. Text counts its UTF-8 length.
encodingstringThe character encoding of byte input, as a label such as "utf-8", "windows-1252" or "utf-16le". Without it graph-io uses a byte order mark, then the encoding the file declares (an XML declaration, DOT's charset), then UTF-8, and reads bytes that are not UTF-8 as windows-1252 with a warning. A byte order mark wins over this option. A string input is already text: setting this option for one adds a W_OPTION_IGNORED warning, once per input (a CSV import with a nodes table has two inputs).

graphtyExport options:

OptionTypeDefaultMeaning
version"1.2" | "1.3"The GEXF version to write.
sanitizeIds"error" | "mangle"What to do with node ids the format cannot hold. "error": the export throws (E_INVALID_ID) and no node is renamed. "mangle": such ids are rewritten and the originals are written to the file too, so an import with restoreMangledIds (on by default) reads the original ids back. Pajek is the exception: it always numbers nodes 1 to N and keeps the old ids as labels.
onMixedDirection"directed" | "error" | "undirected"What a format with one direction per file does with a graph that has both directed and undirected edges: "error" throws (E_DIRECTED), "directed" writes every edge as directed (an undirected edge once, as one directed edge), "undirected" writes the whole graph undirected. A format that keeps each edge's own direction (GraphML, GEXF, CSV, Pajek, XGMML, Cytoscape sessions, and the JGF and graphology JSON dialects) ignores it and writes both kinds; to make such a graph all one direction, read it with the import option onMixedDirection.

graphml ​

graphtyImport options:

OptionTypeDefaultMeaning
yfiles"json" | "skip""json" keeps the yEd graphics of each element as a JSON data field; "skip" leaves them out, with one warning.
ids"string" | "number" | "keep" | "canonical""keep" for JSONHow id text becomes a node id. "canonical": integer text such as "42" becomes the number 42 and everything else ("042", "4.2", "a") stays text. "string": every id stays text. "number": every id is read as a number, so "042" and "42" become one node (with a warning) and text that is not a number is an error. "keep": ids keep the type the file gives them. The default is "keep" for JSON, OBO, XGMML, CX, CX2 and Cytoscape sessions, and "canonical" for the other formats.
nodeIdFrom"id" | "label" | "index"Which value becomes the node id: the file's own id ("id"), the node's label ("label"), or its position among the nodes, counting from 0 ("index"). Use it when a file's ids are meaningless numbers and the labels are the real names. In d3 JSON, "index" also reads edges whose ends are node positions. In GML and Pajek it only renames: every node still needs its id key or vertex number, because edges refer to nodes by it, and a GML node without an id key is skipped with E_MISSING_ID. CSV reads this option only when there is a node table, and it does not just rename: with "label" the node table's label column (label, or the labelColumn option) gives the ids, so the edge table must name its nodes by those labels.
addMissingNodesbooleanfalse for GEXFWhether an edge may name a node the file never declares; that node is then created. When false, such an edge is skipped as an error. The default is false for GEXF, XGMML, CX, CX2 and Cytoscape sessions, whose files must declare every node, and true for the other formats.
duplicateEdges"max" | "keep" | "error" | "first" | "last" | "sum" | "min"What to do with a second edge between the same two nodes: "keep" keeps both, "first" / "last" keep one, "sum" / "min" / "max" keep one with the weights combined, and "error" stops the import. Merged edges are reported once as W_EDGES_MERGED.
selfLoops"keep" | "error" | "drop"What to do with an edge from a node to itself: "keep", "drop" (reported once as W_SELF_LOOPS_DROPPED with the number removed), or "error" to stop the import.
onMixedDirection"directed" | "error" | "expand" | "undirected"How edge direction is read. "expand" (the default) keeps the file's direction, and for a file that has both directed and undirected edges makes a directed graph in which each undirected edge is two edges, marked so an export can write them back as one. "directed" / "undirected" read every edge of any file that way, including a file whose edges all have the other direction, with a W_DIRECTION_FORCED warning. "error" stops the import at the first edge whose direction differs from the file's.
defaultDirectedbooleanundirected for GraphMLWhether the graph is directed when the file does not say. The default is undirected for GraphML, GEXF, GML, JSON and XGMML, and directed for CSV, Pajek and Cytoscape sessions. DOT, Neo4j, CX, CX2 and OBO files always settle the direction themselves (DOT by graph or digraph; the others are always directed), so those formats do not read this option and report it as W_OPTION_IGNORED.
weightFromstring"weight"The edge attribute read as the edge weight. The default is "weight", except "value" for GML and Pajek and none for OBO. Pass null to read every attribute as a plain attribute and leave the graph unweighted. A name no edge has leaves the graph unweighted, with a W_WEIGHT_NOT_FOUND warning: one options object with weightFrom: "weight" shared across formats reads GML and Pajek files, which keep their weights in value, without weights. An edge whose weight cell is empty or missing gets the default weight 1, and an export writes no weight for it.
weightDtype"f32" | "f64"Whether weights a 32-bit float cannot hold exactly are also kept exactly. "f64" keeps them in an edge column that snapshot.edges.byRole("weight") finds, so 0.1 and 16777217 stay exact. "f32" keeps no such column and uses less memory: the 32-bit weight arrays snapshot.weights and snapshot.edgeList().weights, which every import fills, are then the only weights.
long"string" | "f64"How a column the file declares as a 64-bit integer is stored: "f64" (a number, exact up to 2^53) or "string" (every digit kept, as text). GML declares no types, so there it applies to a key whose integer values go beyond 2^53.
restoreMangledIdsbooleanWhether to give back the original ids that an export with sanitizeIds: "mangle" had to rewrite. The export writes them to the file in an attribute whose name each format page gives. When false, the rewritten ids stay the ids and the originals are an ordinary node attribute, named after the format's spelling: graphty.originalId in GraphML, graphty_originalId in GML and Pajek, graphty:originalId in CX, CX2 and Cytoscape sessions, and a graphty:originalId entry of the property_value attribute in OBO.
hyperedges"error" | "skip" | "star" | "clique"What to do with a GraphML or JGF hyperedge (an edge with more than two ends): "skip" leaves it out with a warning, "error" stops the import, and "star" and "clique" turn it into ordinary edges. "clique" joins every pair of ends. "star" works differently per format: GraphML adds a new hub node joined to every end, while JGF makes the hyperedge's first node the hub, so no node is added. A directed JGF hyperedge (source and target arrays) becomes one edge from every source to every target under both. In JGF every edge made from a hyperedge carries the hyperedge's id, label, relation and metadata; GraphML drops a hyperedge's <data> and its <desc>, with a warning.
errorLimitnumberHow many errors an import tolerates. Each error skips one node, edge or value and is listed in the report; one error more than this stops the import with an ImportError. Pass 0 to stop at the first error.
signalAbortSignalCancels the import. When it aborts, the import stops and rejects with the signal's reason (an AbortError, or a TimeoutError from AbortSignal.timeout()).
onProgress(bytesDone: number, bytesTotal?: number | undefined) => voidCalled as the input is read, with the bytes read so far and the total. For a string or a Uint8Array the total is known from the first call. For a stream (which includes loadFromUrl() and loadFromFile()) it is undefined until the last call, which always has bytesDone === bytesTotal. Text counts its UTF-8 length.
encodingstringThe character encoding of byte input, as a label such as "utf-8", "windows-1252" or "utf-16le". Without it graph-io uses a byte order mark, then the encoding the file declares (an XML declaration, DOT's charset), then UTF-8, and reads bytes that are not UTF-8 as windows-1252 with a warning. A byte order mark wins over this option. A string input is already text: setting this option for one adds a W_OPTION_IGNORED warning, once per input (a CSV import with a nodes table has two inputs).

graphtyExport options:

OptionTypeDefaultMeaning
prettybooleanIndent nested elements; false writes one element per line without indentation.
edgedefault"directed" | "undirected"the graph's directionThe top-level edgedefault: directed when you pass directed: true, else undirected.
sanitizeIds"error" | "mangle"What to do with node ids the format cannot hold. "error": the export throws (E_INVALID_ID) and no node is renamed. "mangle": such ids are rewritten and the originals are written to the file too, so an import with restoreMangledIds (on by default) reads the original ids back. Pajek is the exception: it always numbers nodes 1 to N and keeps the old ids as labels.
onMixedDirection"directed" | "error" | "undirected"What a format with one direction per file does with a graph that has both directed and undirected edges: "error" throws (E_DIRECTED), "directed" writes every edge as directed (an undirected edge once, as one directed edge), "undirected" writes the whole graph undirected. A format that keeps each edge's own direction (GraphML, GEXF, CSV, Pajek, XGMML, Cytoscape sessions, and the JGF and graphology JSON dialects) ignores it and writes both kinds; to make such a graph all one direction, read it with the import option onMixedDirection.

gml ​

graphtyImport options:

OptionTypeDefaultMeaning
positionsbooleanRead a node's graphics [ x y ] as its position; false keeps the whole record as the data field graphics.
keepPositionSourcebooleanWith positions, also keep the whole graphics record, x and y included, as the data field graphics.
dictionariesbooleanStore repeated text values compactly while reading; the data you get is the same.
graphIndexnumberWhich graph of the file to read, 0-based in file order. When a file holds more than one graph, report.issues has a W_MULTIPLE_GRAPHS issue whose message gives the count.
graphNamestringWhich graph of the file to read, by the name the file gives it; a name two graphs share is refused.
ids"string" | "number" | "keep" | "canonical""keep" for JSONHow id text becomes a node id. "canonical": integer text such as "42" becomes the number 42 and everything else ("042", "4.2", "a") stays text. "string": every id stays text. "number": every id is read as a number, so "042" and "42" become one node (with a warning) and text that is not a number is an error. "keep": ids keep the type the file gives them. The default is "keep" for JSON, OBO, XGMML, CX, CX2 and Cytoscape sessions, and "canonical" for the other formats.
nodeIdFrom"id" | "label" | "index"Which value becomes the node id: the file's own id ("id"), the node's label ("label"), or its position among the nodes, counting from 0 ("index"). Use it when a file's ids are meaningless numbers and the labels are the real names. In d3 JSON, "index" also reads edges whose ends are node positions. In GML and Pajek it only renames: every node still needs its id key or vertex number, because edges refer to nodes by it, and a GML node without an id key is skipped with E_MISSING_ID. CSV reads this option only when there is a node table, and it does not just rename: with "label" the node table's label column (label, or the labelColumn option) gives the ids, so the edge table must name its nodes by those labels.
addMissingNodesbooleanfalse for GEXFWhether an edge may name a node the file never declares; that node is then created. When false, such an edge is skipped as an error. The default is false for GEXF, XGMML, CX, CX2 and Cytoscape sessions, whose files must declare every node, and true for the other formats.
duplicateEdges"max" | "keep" | "error" | "first" | "last" | "sum" | "min"What to do with a second edge between the same two nodes: "keep" keeps both, "first" / "last" keep one, "sum" / "min" / "max" keep one with the weights combined, and "error" stops the import. Merged edges are reported once as W_EDGES_MERGED.
selfLoops"keep" | "error" | "drop"What to do with an edge from a node to itself: "keep", "drop" (reported once as W_SELF_LOOPS_DROPPED with the number removed), or "error" to stop the import.
onMixedDirection"directed" | "error" | "expand" | "undirected"How edge direction is read. "expand" (the default) keeps the file's direction, and for a file that has both directed and undirected edges makes a directed graph in which each undirected edge is two edges, marked so an export can write them back as one. "directed" / "undirected" read every edge of any file that way, including a file whose edges all have the other direction, with a W_DIRECTION_FORCED warning. "error" stops the import at the first edge whose direction differs from the file's.
defaultDirectedbooleanundirected for GraphMLWhether the graph is directed when the file does not say. The default is undirected for GraphML, GEXF, GML, JSON and XGMML, and directed for CSV, Pajek and Cytoscape sessions. DOT, Neo4j, CX, CX2 and OBO files always settle the direction themselves (DOT by graph or digraph; the others are always directed), so those formats do not read this option and report it as W_OPTION_IGNORED.
weightFromstring"weight"The edge attribute read as the edge weight. The default is "weight", except "value" for GML and Pajek and none for OBO. Pass null to read every attribute as a plain attribute and leave the graph unweighted. A name no edge has leaves the graph unweighted, with a W_WEIGHT_NOT_FOUND warning: one options object with weightFrom: "weight" shared across formats reads GML and Pajek files, which keep their weights in value, without weights. An edge whose weight cell is empty or missing gets the default weight 1, and an export writes no weight for it.
weightDtype"f32" | "f64"Whether weights a 32-bit float cannot hold exactly are also kept exactly. "f64" keeps them in an edge column that snapshot.edges.byRole("weight") finds, so 0.1 and 16777217 stay exact. "f32" keeps no such column and uses less memory: the 32-bit weight arrays snapshot.weights and snapshot.edgeList().weights, which every import fills, are then the only weights.
long"string" | "f64"How a column the file declares as a 64-bit integer is stored: "f64" (a number, exact up to 2^53) or "string" (every digit kept, as text). GML declares no types, so there it applies to a key whose integer values go beyond 2^53.
restoreMangledIdsbooleanWhether to give back the original ids that an export with sanitizeIds: "mangle" had to rewrite. The export writes them to the file in an attribute whose name each format page gives. When false, the rewritten ids stay the ids and the originals are an ordinary node attribute, named after the format's spelling: graphty.originalId in GraphML, graphty_originalId in GML and Pajek, graphty:originalId in CX, CX2 and Cytoscape sessions, and a graphty:originalId entry of the property_value attribute in OBO.
hyperedges"error" | "skip" | "star" | "clique"What to do with a GraphML or JGF hyperedge (an edge with more than two ends): "skip" leaves it out with a warning, "error" stops the import, and "star" and "clique" turn it into ordinary edges. "clique" joins every pair of ends. "star" works differently per format: GraphML adds a new hub node joined to every end, while JGF makes the hyperedge's first node the hub, so no node is added. A directed JGF hyperedge (source and target arrays) becomes one edge from every source to every target under both. In JGF every edge made from a hyperedge carries the hyperedge's id, label, relation and metadata; GraphML drops a hyperedge's <data> and its <desc>, with a warning.
errorLimitnumberHow many errors an import tolerates. Each error skips one node, edge or value and is listed in the report; one error more than this stops the import with an ImportError. Pass 0 to stop at the first error.
signalAbortSignalCancels the import. When it aborts, the import stops and rejects with the signal's reason (an AbortError, or a TimeoutError from AbortSignal.timeout()).
onProgress(bytesDone: number, bytesTotal?: number | undefined) => voidCalled as the input is read, with the bytes read so far and the total. For a string or a Uint8Array the total is known from the first call. For a stream (which includes loadFromUrl() and loadFromFile()) it is undefined until the last call, which always has bytesDone === bytesTotal. Text counts its UTF-8 length.
encodingstringThe character encoding of byte input, as a label such as "utf-8", "windows-1252" or "utf-16le". Without it graph-io uses a byte order mark, then the encoding the file declares (an XML declaration, DOT's charset), then UTF-8, and reads bytes that are not UTF-8 as windows-1252 with a warning. A byte order mark wins over this option. A string input is already text: setting this option for one adds a W_OPTION_IGNORED warning, once per input (a CSV import with a nodes table has two inputs).

graphtyExport options:

OptionTypeDefaultMeaning
weightKeystring"value"The edge key the edge weights are written under.
sanitizeKeys"error" | "mangle"What to do with an attribute name or record key that GML cannot write: one that is not a GML key (letters, digits and _, starting with a letter, so Edge Label is not one), or one that GML uses itself in that record: id for a node attribute; source, target and directed for an edge attribute; node, edge, directed and multigraph for a graph attribute. A node attribute named source is fine. "error" makes the save fail, "mangle" rewrites the name (. and other characters become _, a clash gets a _2 suffix) and checkExport() lists each rename. An options object shared by saves to several formats that include GML should set it.
sanitizeIds"error" | "mangle"What to do with node ids the format cannot hold. "error": the export throws (E_INVALID_ID) and no node is renamed. "mangle": such ids are rewritten and the originals are written to the file too, so an import with restoreMangledIds (on by default) reads the original ids back. Pajek is the exception: it always numbers nodes 1 to N and keeps the old ids as labels.
onMixedDirection"directed" | "error" | "undirected"What a format with one direction per file does with a graph that has both directed and undirected edges: "error" throws (E_DIRECTED), "directed" writes every edge as directed (an undirected edge once, as one directed edge), "undirected" writes the whole graph undirected. A format that keeps each edge's own direction (GraphML, GEXF, CSV, Pajek, XGMML, Cytoscape sessions, and the JGF and graphology JSON dialects) ignores it and writes both kinds; to make such a graph all one direction, read it with the import option onMixedDirection.

dot ​

graphtyImport options:

OptionTypeDefaultMeaning
mismatchedEdgeOperator"error" | "operator" | "header"What an edge operator that contradicts the graph keyword means (-- in a digraph, -> in a graph; Graphviz refuses such a file): "operator" reads the edge with the operator's direction, so the graph has both directions and onMixedDirection decides, with a warning; "header" reads it with the graph's direction, with a warning; "error" stops the import with an ImportError whose issue.code is E_SYNTAX, as Graphviz does.
positionsbooleanRead a node's pos attribute as its position; false keeps pos as the text the file wrote.
keepPositionSourcebooleanWith positions, also keep pos as the text the file wrote.
graphIndexnumberWhich graph of the file to read, 0-based in file order. When a file holds more than one graph, report.issues has a W_MULTIPLE_GRAPHS issue whose message gives the count.
graphNamestringWhich graph of the file to read, by the name the file gives it; a name two graphs share is refused.
ids"string" | "number" | "keep" | "canonical""keep" for JSONHow id text becomes a node id. "canonical": integer text such as "42" becomes the number 42 and everything else ("042", "4.2", "a") stays text. "string": every id stays text. "number": every id is read as a number, so "042" and "42" become one node (with a warning) and text that is not a number is an error. "keep": ids keep the type the file gives them. The default is "keep" for JSON, OBO, XGMML, CX, CX2 and Cytoscape sessions, and "canonical" for the other formats.
nodeIdFrom"id" | "label" | "index"Which value becomes the node id: the file's own id ("id"), the node's label ("label"), or its position among the nodes, counting from 0 ("index"). Use it when a file's ids are meaningless numbers and the labels are the real names. In d3 JSON, "index" also reads edges whose ends are node positions. In GML and Pajek it only renames: every node still needs its id key or vertex number, because edges refer to nodes by it, and a GML node without an id key is skipped with E_MISSING_ID. CSV reads this option only when there is a node table, and it does not just rename: with "label" the node table's label column (label, or the labelColumn option) gives the ids, so the edge table must name its nodes by those labels.
addMissingNodesbooleanfalse for GEXFWhether an edge may name a node the file never declares; that node is then created. When false, such an edge is skipped as an error. The default is false for GEXF, XGMML, CX, CX2 and Cytoscape sessions, whose files must declare every node, and true for the other formats.
duplicateEdges"max" | "keep" | "error" | "first" | "last" | "sum" | "min"What to do with a second edge between the same two nodes: "keep" keeps both, "first" / "last" keep one, "sum" / "min" / "max" keep one with the weights combined, and "error" stops the import. Merged edges are reported once as W_EDGES_MERGED.
selfLoops"keep" | "error" | "drop"What to do with an edge from a node to itself: "keep", "drop" (reported once as W_SELF_LOOPS_DROPPED with the number removed), or "error" to stop the import.
onMixedDirection"directed" | "error" | "expand" | "undirected"How edge direction is read. "expand" (the default) keeps the file's direction, and for a file that has both directed and undirected edges makes a directed graph in which each undirected edge is two edges, marked so an export can write them back as one. "directed" / "undirected" read every edge of any file that way, including a file whose edges all have the other direction, with a W_DIRECTION_FORCED warning. "error" stops the import at the first edge whose direction differs from the file's.
defaultDirectedbooleanundirected for GraphMLWhether the graph is directed when the file does not say. The default is undirected for GraphML, GEXF, GML, JSON and XGMML, and directed for CSV, Pajek and Cytoscape sessions. DOT, Neo4j, CX, CX2 and OBO files always settle the direction themselves (DOT by graph or digraph; the others are always directed), so those formats do not read this option and report it as W_OPTION_IGNORED.
weightFromstring"weight"The edge attribute read as the edge weight. The default is "weight", except "value" for GML and Pajek and none for OBO. Pass null to read every attribute as a plain attribute and leave the graph unweighted. A name no edge has leaves the graph unweighted, with a W_WEIGHT_NOT_FOUND warning: one options object with weightFrom: "weight" shared across formats reads GML and Pajek files, which keep their weights in value, without weights. An edge whose weight cell is empty or missing gets the default weight 1, and an export writes no weight for it.
weightDtype"f32" | "f64"Whether weights a 32-bit float cannot hold exactly are also kept exactly. "f64" keeps them in an edge column that snapshot.edges.byRole("weight") finds, so 0.1 and 16777217 stay exact. "f32" keeps no such column and uses less memory: the 32-bit weight arrays snapshot.weights and snapshot.edgeList().weights, which every import fills, are then the only weights.
long"string" | "f64"How a column the file declares as a 64-bit integer is stored: "f64" (a number, exact up to 2^53) or "string" (every digit kept, as text). GML declares no types, so there it applies to a key whose integer values go beyond 2^53.
restoreMangledIdsbooleanWhether to give back the original ids that an export with sanitizeIds: "mangle" had to rewrite. The export writes them to the file in an attribute whose name each format page gives. When false, the rewritten ids stay the ids and the originals are an ordinary node attribute, named after the format's spelling: graphty.originalId in GraphML, graphty_originalId in GML and Pajek, graphty:originalId in CX, CX2 and Cytoscape sessions, and a graphty:originalId entry of the property_value attribute in OBO.
hyperedges"error" | "skip" | "star" | "clique"What to do with a GraphML or JGF hyperedge (an edge with more than two ends): "skip" leaves it out with a warning, "error" stops the import, and "star" and "clique" turn it into ordinary edges. "clique" joins every pair of ends. "star" works differently per format: GraphML adds a new hub node joined to every end, while JGF makes the hyperedge's first node the hub, so no node is added. A directed JGF hyperedge (source and target arrays) becomes one edge from every source to every target under both. In JGF every edge made from a hyperedge carries the hyperedge's id, label, relation and metadata; GraphML drops a hyperedge's <data> and its <desc>, with a warning.
errorLimitnumberHow many errors an import tolerates. Each error skips one node, edge or value and is listed in the report; one error more than this stops the import with an ImportError. Pass 0 to stop at the first error.
signalAbortSignalCancels the import. When it aborts, the import stops and rejects with the signal's reason (an AbortError, or a TimeoutError from AbortSignal.timeout()).
onProgress(bytesDone: number, bytesTotal?: number | undefined) => voidCalled as the input is read, with the bytes read so far and the total. For a string or a Uint8Array the total is known from the first call. For a stream (which includes loadFromUrl() and loadFromFile()) it is undefined until the last call, which always has bytesDone === bytesTotal. Text counts its UTF-8 length.
encodingstringThe character encoding of byte input, as a label such as "utf-8", "windows-1252" or "utf-16le". Without it graph-io uses a byte order mark, then the encoding the file declares (an XML declaration, DOT's charset), then UTF-8, and reads bytes that are not UTF-8 as windows-1252 with a warning. A byte order mark wins over this option. A string input is already text: setting this option for one adds a W_OPTION_IGNORED warning, once per input (a CSV import with a nodes table has two inputs).

graphtyExport options:

OptionTypeDefaultMeaning
indentstring | numberfour spacesThe indentation of one nesting level.
namestringnoneThe graph name to write.
strictbooleanfalseWrite the strict keyword.
sanitizeIds"error" | "mangle"What to do with node ids the format cannot hold. "error": the export throws (E_INVALID_ID) and no node is renamed. "mangle": such ids are rewritten and the originals are written to the file too, so an import with restoreMangledIds (on by default) reads the original ids back. Pajek is the exception: it always numbers nodes 1 to N and keeps the old ids as labels.
onMixedDirection"directed" | "error" | "undirected"What a format with one direction per file does with a graph that has both directed and undirected edges: "error" throws (E_DIRECTED), "directed" writes every edge as directed (an undirected edge once, as one directed edge), "undirected" writes the whole graph undirected. A format that keeps each edge's own direction (GraphML, GEXF, CSV, Pajek, XGMML, Cytoscape sessions, and the JGF and graphology JSON dialects) ignores it and writes both kinds; to make such a graph all one direction, read it with the import option onMixedDirection.

pajek ​

graphtyImport options:

OptionTypeDefaultMeaning
firstVertex0 | "auto" | 1The number of the first vertex: 1 (Pajek's rule), 0 (files written by zero-based scripts), or "auto": 0 when the first vertex line is numbered 0, 1 otherwise.
graphIndexnumberWhich graph of the file to read, 0-based in file order. When a file holds more than one graph, report.issues has a W_MULTIPLE_GRAPHS issue whose message gives the count.
graphNamestringWhich graph of the file to read, by the name the file gives it; a name two graphs share is refused.
ids"string" | "number" | "keep" | "canonical""keep" for JSONHow id text becomes a node id. "canonical": integer text such as "42" becomes the number 42 and everything else ("042", "4.2", "a") stays text. "string": every id stays text. "number": every id is read as a number, so "042" and "42" become one node (with a warning) and text that is not a number is an error. "keep": ids keep the type the file gives them. The default is "keep" for JSON, OBO, XGMML, CX, CX2 and Cytoscape sessions, and "canonical" for the other formats.
nodeIdFrom"id" | "label" | "index"Which value becomes the node id: the file's own id ("id"), the node's label ("label"), or its position among the nodes, counting from 0 ("index"). Use it when a file's ids are meaningless numbers and the labels are the real names. In d3 JSON, "index" also reads edges whose ends are node positions. In GML and Pajek it only renames: every node still needs its id key or vertex number, because edges refer to nodes by it, and a GML node without an id key is skipped with E_MISSING_ID. CSV reads this option only when there is a node table, and it does not just rename: with "label" the node table's label column (label, or the labelColumn option) gives the ids, so the edge table must name its nodes by those labels.
addMissingNodesbooleanfalse for GEXFWhether an edge may name a node the file never declares; that node is then created. When false, such an edge is skipped as an error. The default is false for GEXF, XGMML, CX, CX2 and Cytoscape sessions, whose files must declare every node, and true for the other formats.
duplicateEdges"max" | "keep" | "error" | "first" | "last" | "sum" | "min"What to do with a second edge between the same two nodes: "keep" keeps both, "first" / "last" keep one, "sum" / "min" / "max" keep one with the weights combined, and "error" stops the import. Merged edges are reported once as W_EDGES_MERGED.
selfLoops"keep" | "error" | "drop"What to do with an edge from a node to itself: "keep", "drop" (reported once as W_SELF_LOOPS_DROPPED with the number removed), or "error" to stop the import.
onMixedDirection"directed" | "error" | "expand" | "undirected"How edge direction is read. "expand" (the default) keeps the file's direction, and for a file that has both directed and undirected edges makes a directed graph in which each undirected edge is two edges, marked so an export can write them back as one. "directed" / "undirected" read every edge of any file that way, including a file whose edges all have the other direction, with a W_DIRECTION_FORCED warning. "error" stops the import at the first edge whose direction differs from the file's.
defaultDirectedbooleanundirected for GraphMLWhether the graph is directed when the file does not say. The default is undirected for GraphML, GEXF, GML, JSON and XGMML, and directed for CSV, Pajek and Cytoscape sessions. DOT, Neo4j, CX, CX2 and OBO files always settle the direction themselves (DOT by graph or digraph; the others are always directed), so those formats do not read this option and report it as W_OPTION_IGNORED.
weightFromstring"weight"The edge attribute read as the edge weight. The default is "weight", except "value" for GML and Pajek and none for OBO. Pass null to read every attribute as a plain attribute and leave the graph unweighted. A name no edge has leaves the graph unweighted, with a W_WEIGHT_NOT_FOUND warning: one options object with weightFrom: "weight" shared across formats reads GML and Pajek files, which keep their weights in value, without weights. An edge whose weight cell is empty or missing gets the default weight 1, and an export writes no weight for it.
weightDtype"f32" | "f64"Whether weights a 32-bit float cannot hold exactly are also kept exactly. "f64" keeps them in an edge column that snapshot.edges.byRole("weight") finds, so 0.1 and 16777217 stay exact. "f32" keeps no such column and uses less memory: the 32-bit weight arrays snapshot.weights and snapshot.edgeList().weights, which every import fills, are then the only weights.
long"string" | "f64"How a column the file declares as a 64-bit integer is stored: "f64" (a number, exact up to 2^53) or "string" (every digit kept, as text). GML declares no types, so there it applies to a key whose integer values go beyond 2^53.
restoreMangledIdsbooleanWhether to give back the original ids that an export with sanitizeIds: "mangle" had to rewrite. The export writes them to the file in an attribute whose name each format page gives. When false, the rewritten ids stay the ids and the originals are an ordinary node attribute, named after the format's spelling: graphty.originalId in GraphML, graphty_originalId in GML and Pajek, graphty:originalId in CX, CX2 and Cytoscape sessions, and a graphty:originalId entry of the property_value attribute in OBO.
hyperedges"error" | "skip" | "star" | "clique"What to do with a GraphML or JGF hyperedge (an edge with more than two ends): "skip" leaves it out with a warning, "error" stops the import, and "star" and "clique" turn it into ordinary edges. "clique" joins every pair of ends. "star" works differently per format: GraphML adds a new hub node joined to every end, while JGF makes the hyperedge's first node the hub, so no node is added. A directed JGF hyperedge (source and target arrays) becomes one edge from every source to every target under both. In JGF every edge made from a hyperedge carries the hyperedge's id, label, relation and metadata; GraphML drops a hyperedge's <data> and its <desc>, with a warning.
errorLimitnumberHow many errors an import tolerates. Each error skips one node, edge or value and is listed in the report; one error more than this stops the import with an ImportError. Pass 0 to stop at the first error.
signalAbortSignalCancels the import. When it aborts, the import stops and rejects with the signal's reason (an AbortError, or a TimeoutError from AbortSignal.timeout()).
onProgress(bytesDone: number, bytesTotal?: number | undefined) => voidCalled as the input is read, with the bytes read so far and the total. For a string or a Uint8Array the total is known from the first call. For a stream (which includes loadFromUrl() and loadFromFile()) it is undefined until the last call, which always has bytesDone === bytesTotal. Text counts its UTF-8 length.
encodingstringThe character encoding of byte input, as a label such as "utf-8", "windows-1252" or "utf-16le". Without it graph-io uses a byte order mark, then the encoding the file declares (an XML declaration, DOT's charset), then UTF-8, and reads bytes that are not UTF-8 as windows-1252 with a warning. A byte order mark wins over this option. A string input is already text: setting this option for one adds a W_OPTION_IGNORED warning, once per input (a CSV import with a nodes table has two inputs).

graphtyExport options:

OptionTypeDefaultMeaning
networkHeaderbooleanHas no effect from Cytoscape: the *Network line carries the graph's name, and an exported collection has none.
namestringthe graph's name (snapshot.meta.name)The network name written on the *Network line. Giving one writes the line, unless networkHeader is false. The default is the graph's name (snapshot.meta.name), which a Pajek, DOT, GML or GEXF import keeps; a graph read from CSV has none.
sanitizeIds"error" | "mangle"What to do with node ids the format cannot hold. "error": the export throws (E_INVALID_ID) and no node is renamed. "mangle": such ids are rewritten and the originals are written to the file too, so an import with restoreMangledIds (on by default) reads the original ids back. Pajek is the exception: it always numbers nodes 1 to N and keeps the old ids as labels.
onMixedDirection"directed" | "error" | "undirected"What a format with one direction per file does with a graph that has both directed and undirected edges: "error" throws (E_DIRECTED), "directed" writes every edge as directed (an undirected edge once, as one directed edge), "undirected" writes the whole graph undirected. A format that keeps each edge's own direction (GraphML, GEXF, CSV, Pajek, XGMML, Cytoscape sessions, and the JGF and graphology JSON dialects) ignores it and writes both kinds; to make such a graph all one direction, read it with the import option onMixedDirection.

csv ​

graphtyImport options:

OptionTypeDefaultMeaning
delimiterstringto detect it from the first rows: ,The field delimiter. The default is to detect it from the first rows: ,, tab, ;, | or space. It applies to the nodes table too.
decimal"." | ","The decimal separator of numbers. With ",", a cell such as 2,5 (digits, a comma, digits) is read as the number 2.5, for weights and attributes alike, and the delimiter is detected among the others (;, tab, |, space), so a spreadsheet saved in a locale that writes decimal commas reads as it is. A thousands separator is not read.
headerboolean | "auto"Whether the first row is a header; "auto" decides from its content (a header names columns, a data row holds ids and numbers). It applies to the nodes table too.
table"auto" | "edges" | "nodes" | "adjacency"What the input is: "edges" (one edge per row), "nodes" (one node per row), "adjacency" (a node and its neighbors per row, node,neighbor[:weight],..., with no header unless you pass header: true), or "auto": an edge table when source and target columns can be found, a node table when only an id column can. An adjacency table is never detected, because its rows look like an edge list.
sourceColumnCsvColumnRefthe column whose header is a recognized source name (source, from, src and others; the CSV format page lists them all)The source column, by name or 0-based position. The default is the column whose header is a recognized source name (source, from, src and others; the CSV format page lists them all); in a file without a header, the first column. A header with no recognized source and target names needs this option and targetColumn.
targetColumnCsvColumnRefthe column whose header is a recognized target name (target, to, dst and others; the CSV format page lists them all)The target column, by name or 0-based position. The default is the column whose header is a recognized target name (target, to, dst and others; the CSV format page lists them all); in a file without a header, the second column.
typeColumnCsvColumnRefthe Type column of a Gephi table (one whose header has exactly Source and Target)The column that gives each edge's direction (Directed / Undirected / Mutual), by name or position. The default is the Type column of a Gephi table (one whose header has exactly Source and Target); null reads no such column.
idColumnCsvColumnRefthe column the header names id (or node, name, key)The id column of a node table, by name or position. The default is the column the header names id (or node, name, key).
labelColumnCsvColumnRefthe column the header names label (in any case)The label column of a node table, by name or position. The default is the column the header names label (in any case). With nodeIdFrom: "label", the node ids come from this column, and the edge table must name its nodes by these labels too.
nodesImportInput | BlobA node table to read before the edges: its ids become nodes and its other columns node attributes. Pass it as a string, bytes, a stream, or a File or Blob (for example, the second file a user picked).
rowNumberIdsbooleanfalseGive the nodes of a node table without an id column the row number as id (0 for the first data row, turned into an id by ids), instead of failing with E_CSV_NO_ID_COLUMN. It applies to the nodes table when you pass one, else to the input. Under header: "auto" that table's first row is then read as a header; under header: false the option is ignored with a warning, because a table without a header takes its ids from its first column.
ids"string" | "number" | "keep" | "canonical""keep" for JSONHow id text becomes a node id. "canonical": integer text such as "42" becomes the number 42 and everything else ("042", "4.2", "a") stays text. "string": every id stays text. "number": every id is read as a number, so "042" and "42" become one node (with a warning) and text that is not a number is an error. "keep": ids keep the type the file gives them. The default is "keep" for JSON, OBO, XGMML, CX, CX2 and Cytoscape sessions, and "canonical" for the other formats.
nodeIdFrom"id" | "label" | "index"Which value becomes the node id: the file's own id ("id"), the node's label ("label"), or its position among the nodes, counting from 0 ("index"). Use it when a file's ids are meaningless numbers and the labels are the real names. In d3 JSON, "index" also reads edges whose ends are node positions. In GML and Pajek it only renames: every node still needs its id key or vertex number, because edges refer to nodes by it, and a GML node without an id key is skipped with E_MISSING_ID. CSV reads this option only when there is a node table, and it does not just rename: with "label" the node table's label column (label, or the labelColumn option) gives the ids, so the edge table must name its nodes by those labels.
addMissingNodesbooleanfalse for GEXFWhether an edge may name a node the file never declares; that node is then created. When false, such an edge is skipped as an error. The default is false for GEXF, XGMML, CX, CX2 and Cytoscape sessions, whose files must declare every node, and true for the other formats.
duplicateEdges"max" | "keep" | "error" | "first" | "last" | "sum" | "min"What to do with a second edge between the same two nodes: "keep" keeps both, "first" / "last" keep one, "sum" / "min" / "max" keep one with the weights combined, and "error" stops the import. Merged edges are reported once as W_EDGES_MERGED.
selfLoops"keep" | "error" | "drop"What to do with an edge from a node to itself: "keep", "drop" (reported once as W_SELF_LOOPS_DROPPED with the number removed), or "error" to stop the import.
onMixedDirection"directed" | "error" | "expand" | "undirected"How edge direction is read. "expand" (the default) keeps the file's direction, and for a file that has both directed and undirected edges makes a directed graph in which each undirected edge is two edges, marked so an export can write them back as one. "directed" / "undirected" read every edge of any file that way, including a file whose edges all have the other direction, with a W_DIRECTION_FORCED warning. "error" stops the import at the first edge whose direction differs from the file's.
defaultDirectedbooleanundirected for GraphMLWhether the graph is directed when the file does not say. The default is undirected for GraphML, GEXF, GML, JSON and XGMML, and directed for CSV, Pajek and Cytoscape sessions. DOT, Neo4j, CX, CX2 and OBO files always settle the direction themselves (DOT by graph or digraph; the others are always directed), so those formats do not read this option and report it as W_OPTION_IGNORED.
weightFromstring"weight"The edge attribute read as the edge weight. The default is "weight", except "value" for GML and Pajek and none for OBO. Pass null to read every attribute as a plain attribute and leave the graph unweighted. A name no edge has leaves the graph unweighted, with a W_WEIGHT_NOT_FOUND warning: one options object with weightFrom: "weight" shared across formats reads GML and Pajek files, which keep their weights in value, without weights. An edge whose weight cell is empty or missing gets the default weight 1, and an export writes no weight for it.
weightDtype"f32" | "f64"Whether weights a 32-bit float cannot hold exactly are also kept exactly. "f64" keeps them in an edge column that snapshot.edges.byRole("weight") finds, so 0.1 and 16777217 stay exact. "f32" keeps no such column and uses less memory: the 32-bit weight arrays snapshot.weights and snapshot.edgeList().weights, which every import fills, are then the only weights.
long"string" | "f64"How a column the file declares as a 64-bit integer is stored: "f64" (a number, exact up to 2^53) or "string" (every digit kept, as text). GML declares no types, so there it applies to a key whose integer values go beyond 2^53.
restoreMangledIdsbooleanWhether to give back the original ids that an export with sanitizeIds: "mangle" had to rewrite. The export writes them to the file in an attribute whose name each format page gives. When false, the rewritten ids stay the ids and the originals are an ordinary node attribute, named after the format's spelling: graphty.originalId in GraphML, graphty_originalId in GML and Pajek, graphty:originalId in CX, CX2 and Cytoscape sessions, and a graphty:originalId entry of the property_value attribute in OBO.
hyperedges"error" | "skip" | "star" | "clique"What to do with a GraphML or JGF hyperedge (an edge with more than two ends): "skip" leaves it out with a warning, "error" stops the import, and "star" and "clique" turn it into ordinary edges. "clique" joins every pair of ends. "star" works differently per format: GraphML adds a new hub node joined to every end, while JGF makes the hyperedge's first node the hub, so no node is added. A directed JGF hyperedge (source and target arrays) becomes one edge from every source to every target under both. In JGF every edge made from a hyperedge carries the hyperedge's id, label, relation and metadata; GraphML drops a hyperedge's <data> and its <desc>, with a warning.
errorLimitnumberHow many errors an import tolerates. Each error skips one node, edge or value and is listed in the report; one error more than this stops the import with an ImportError. Pass 0 to stop at the first error.
signalAbortSignalCancels the import. When it aborts, the import stops and rejects with the signal's reason (an AbortError, or a TimeoutError from AbortSignal.timeout()).
onProgress(bytesDone: number, bytesTotal?: number | undefined) => voidCalled as the input is read, with the bytes read so far and the total. For a string or a Uint8Array the total is known from the first call. For a stream (which includes loadFromUrl() and loadFromFile()) it is undefined until the last call, which always has bytesDone === bytesTotal. Text counts its UTF-8 length.
encodingstringThe character encoding of byte input, as a label such as "utf-8", "windows-1252" or "utf-16le". Without it graph-io uses a byte order mark, then the encoding the file declares (an XML declaration, DOT's charset), then UTF-8, and reads bytes that are not UTF-8 as windows-1252 with a warning. A byte order mark wins over this option. A string input is already text: setting this option for one adds a W_OPTION_IGNORED warning, once per input (a CSV import with a nodes table has two inputs).

graphtyExport options:

OptionTypeDefaultMeaning
dialect"gephi" | "generic"The header spelling: "gephi" writes Source,Target,Type,...,Weight, with each edge's direction in Type; "generic" writes source,target,...,weight and no direction column. A JSON dialect name, from an options object shared with JSON saves, is ignored.
table"edges" | "nodes" | "adjacency""edges"Which table to write: the edge table, the node table, or an adjacency table (a node and its neighbors per row; read it back with table: "adjacency").
delimiterstring","The field delimiter.
newline"\n" | "\r\n""\n"The line terminator.
headerbooleantrueWrite the header row; an adjacency table never has one.
sanitizeIds"error" | "mangle"What to do with node ids the format cannot hold. "error": the export throws (E_INVALID_ID) and no node is renamed. "mangle": such ids are rewritten and the originals are written to the file too, so an import with restoreMangledIds (on by default) reads the original ids back. Pajek is the exception: it always numbers nodes 1 to N and keeps the old ids as labels.
onMixedDirection"directed" | "error" | "undirected"What a format with one direction per file does with a graph that has both directed and undirected edges: "error" throws (E_DIRECTED), "directed" writes every edge as directed (an undirected edge once, as one directed edge), "undirected" writes the whole graph undirected. A format that keeps each edge's own direction (GraphML, GEXF, CSV, Pajek, XGMML, Cytoscape sessions, and the JGF and graphology JSON dialects) ignores it and writes both kinds; to make such a graph all one direction, read it with the import option onMixedDirection.

json ​

graphtyImport options:

OptionTypeDefaultMeaning
dialect"auto" | "adjacency" | "node-link" | "d3" | "jgf" | "cytoscape" | "graphology" | "vis" | "obographs" | "tree"The dialect to read; "auto" detects it from the document. jsonShapeOf(snapshot).dialect is the dialect that was read.
nodeIdKeystringis "id" (for node-link and d3, "name" when no node has an "id")node-link, d3, vis, adjacency and tree documents: the node key that holds the id. The default is "id" (for node-link and d3, "name" when no node has an "id").
edgesKeystring"edges" when the document has itnode-link and d3 documents: the top-level key that holds the edges. The default is "edges" when the document has it, else "links".
sourceKeystringthe first of "source"node-link, d3 and vis documents: the edge key that holds the source. The default is the first of "source", "src" and "from" the edges use (vis: "from").
targetKeystringthe first of "target"node-link, d3 and vis documents: the edge key that holds the target. The default is the first of "target", "dst" and "to" the edges use (vis: "to").
indexLinksboolean | "auto"node-link and d3 documents: whether edge ends are positions in the node array rather than ids; "auto" says yes when every end is an integer below the number of nodes and no node id is a number.
oboIds"curie" | "iri"OBO Graphs documents: "curie" reads http://purl.obolibrary.org/obo/GO_0008150 as GO:0008150 and .../obo/go#regulates as regulates, the ids the .obo file of the same ontology uses; "iri" keeps every IRI as written.
typedefs"nodes" | "metadata"OBO Graphs documents: "metadata" keeps the relation definitions (PROPERTY nodes, with their subPropertyOf and inverseOf edges) in snapshot.meta.extra.obographs, the way the OBO importer keeps [Typedef] frames; "nodes" makes them nodes and edges of the graph.
nodesPathstringnode-link, d3, vis and graphology documents: where the node array is, as a dotted path of keys and array positions from the top of the document ("data.nodes", "graphs.0.nodes"). The object that holds the array is read as the graph (its directed, multigraph, graph and edge keys). A path that leads nowhere is reported as E_MISSING_SECTION and the graph has no nodes.
edgesPathstringthe edges or links key next to the node arraynode-link, d3, vis and graphology documents: where the edge array is, as a dotted path ("data.links"). The default is the edges or links key next to the node array. A path that leads nowhere is reported as E_MISSING_SECTION and the graph has no edges.
graphIndexnumberWhich graph of the file to read, 0-based in file order. When a file holds more than one graph, report.issues has a W_MULTIPLE_GRAPHS issue whose message gives the count.
graphNamestringWhich graph of the file to read, by the name the file gives it; a name two graphs share is refused.
ids"string" | "number" | "keep" | "canonical""keep" for JSONHow id text becomes a node id. "canonical": integer text such as "42" becomes the number 42 and everything else ("042", "4.2", "a") stays text. "string": every id stays text. "number": every id is read as a number, so "042" and "42" become one node (with a warning) and text that is not a number is an error. "keep": ids keep the type the file gives them. The default is "keep" for JSON, OBO, XGMML, CX, CX2 and Cytoscape sessions, and "canonical" for the other formats.
nodeIdFrom"id" | "label" | "index"Which value becomes the node id: the file's own id ("id"), the node's label ("label"), or its position among the nodes, counting from 0 ("index"). Use it when a file's ids are meaningless numbers and the labels are the real names. In d3 JSON, "index" also reads edges whose ends are node positions. In GML and Pajek it only renames: every node still needs its id key or vertex number, because edges refer to nodes by it, and a GML node without an id key is skipped with E_MISSING_ID. CSV reads this option only when there is a node table, and it does not just rename: with "label" the node table's label column (label, or the labelColumn option) gives the ids, so the edge table must name its nodes by those labels.
addMissingNodesbooleanfalse for GEXFWhether an edge may name a node the file never declares; that node is then created. When false, such an edge is skipped as an error. The default is false for GEXF, XGMML, CX, CX2 and Cytoscape sessions, whose files must declare every node, and true for the other formats.
duplicateEdges"max" | "keep" | "error" | "first" | "last" | "sum" | "min"What to do with a second edge between the same two nodes: "keep" keeps both, "first" / "last" keep one, "sum" / "min" / "max" keep one with the weights combined, and "error" stops the import. Merged edges are reported once as W_EDGES_MERGED.
selfLoops"keep" | "error" | "drop"What to do with an edge from a node to itself: "keep", "drop" (reported once as W_SELF_LOOPS_DROPPED with the number removed), or "error" to stop the import.
onMixedDirection"directed" | "error" | "expand" | "undirected"How edge direction is read. "expand" (the default) keeps the file's direction, and for a file that has both directed and undirected edges makes a directed graph in which each undirected edge is two edges, marked so an export can write them back as one. "directed" / "undirected" read every edge of any file that way, including a file whose edges all have the other direction, with a W_DIRECTION_FORCED warning. "error" stops the import at the first edge whose direction differs from the file's.
defaultDirectedbooleanundirected for GraphMLWhether the graph is directed when the file does not say. The default is undirected for GraphML, GEXF, GML, JSON and XGMML, and directed for CSV, Pajek and Cytoscape sessions. DOT, Neo4j, CX, CX2 and OBO files always settle the direction themselves (DOT by graph or digraph; the others are always directed), so those formats do not read this option and report it as W_OPTION_IGNORED.
weightFromstring"weight"The edge attribute read as the edge weight. The default is "weight", except "value" for GML and Pajek and none for OBO. Pass null to read every attribute as a plain attribute and leave the graph unweighted. A name no edge has leaves the graph unweighted, with a W_WEIGHT_NOT_FOUND warning: one options object with weightFrom: "weight" shared across formats reads GML and Pajek files, which keep their weights in value, without weights. An edge whose weight cell is empty or missing gets the default weight 1, and an export writes no weight for it.
weightDtype"f32" | "f64"Whether weights a 32-bit float cannot hold exactly are also kept exactly. "f64" keeps them in an edge column that snapshot.edges.byRole("weight") finds, so 0.1 and 16777217 stay exact. "f32" keeps no such column and uses less memory: the 32-bit weight arrays snapshot.weights and snapshot.edgeList().weights, which every import fills, are then the only weights.
long"string" | "f64"How a column the file declares as a 64-bit integer is stored: "f64" (a number, exact up to 2^53) or "string" (every digit kept, as text). GML declares no types, so there it applies to a key whose integer values go beyond 2^53.
restoreMangledIdsbooleanWhether to give back the original ids that an export with sanitizeIds: "mangle" had to rewrite. The export writes them to the file in an attribute whose name each format page gives. When false, the rewritten ids stay the ids and the originals are an ordinary node attribute, named after the format's spelling: graphty.originalId in GraphML, graphty_originalId in GML and Pajek, graphty:originalId in CX, CX2 and Cytoscape sessions, and a graphty:originalId entry of the property_value attribute in OBO.
hyperedges"error" | "skip" | "star" | "clique"What to do with a GraphML or JGF hyperedge (an edge with more than two ends): "skip" leaves it out with a warning, "error" stops the import, and "star" and "clique" turn it into ordinary edges. "clique" joins every pair of ends. "star" works differently per format: GraphML adds a new hub node joined to every end, while JGF makes the hyperedge's first node the hub, so no node is added. A directed JGF hyperedge (source and target arrays) becomes one edge from every source to every target under both. In JGF every edge made from a hyperedge carries the hyperedge's id, label, relation and metadata; GraphML drops a hyperedge's <data> and its <desc>, with a warning.
errorLimitnumberHow many errors an import tolerates. Each error skips one node, edge or value and is listed in the report; one error more than this stops the import with an ImportError. Pass 0 to stop at the first error.
signalAbortSignalCancels the import. When it aborts, the import stops and rejects with the signal's reason (an AbortError, or a TimeoutError from AbortSignal.timeout()).
onProgress(bytesDone: number, bytesTotal?: number | undefined) => voidCalled as the input is read, with the bytes read so far and the total. For a string or a Uint8Array the total is known from the first call. For a stream (which includes loadFromUrl() and loadFromFile()) it is undefined until the last call, which always has bytesDone === bytesTotal. Text counts its UTF-8 length.
encodingstringThe character encoding of byte input, as a label such as "utf-8", "windows-1252" or "utf-16le". Without it graph-io uses a byte order mark, then the encoding the file declares (an XML declaration, DOT's charset), then UTF-8, and reads bytes that are not UTF-8 as windows-1252 with a warning. A byte order mark wins over this option. A string input is already text: setting this option for one adds a W_OPTION_IGNORED warning, once per input (a CSV import with a nodes table has two inputs).

graphtyExport options:

OptionTypeDefaultMeaning
dialect"node-link" | "d3" | "jgf" | "cytoscape" | "graphology" | "vis" | "obographs""cytoscape"The dialect to write. "cytoscape" is what cy.json() and cy.add() use and keeps edge ids, compound parents and positions; "node-link" is the NetworkX shape.
indentstring | numberThe indentation of one level: a number of spaces, or the text itself (spaces or tabs, such as "\t"). 0 or "" writes compact JSON on one line.
edgesKeystring"edges"node-link and d3: the key of the edge array (d3: "links").
nodeIdKeystring"id"node-link, d3 and vis: the node id key.
indexLinksbooleanfalsenode-link and d3: write endpoints as node array positions.
sourceKeystring"source"node-link, d3 and vis: the source key (vis: "from").
targetKeystring"target"node-link, d3 and vis: the target key (vis: "to").
weightKeystring"weight"The key the edge weight is written under.
ontologyIristringOBO address (http://purl.obolibrary.org/obo/graph.owl#a)OBO Graphs: the graph id written when the graph has none. A graph read from an OBO Graphs document keeps its own graph id, which this option does not change. Node ids are written in the form graph-io reads back as the same id: an IRI as it is, a prefixed id such as GO:0008150 as its OBO address, and an id without a prefix (a) under the default OBO address (http://purl.obolibrary.org/obo/graph.owl#a), or as it is when you pass another IRI here. The default is http://purl.obolibrary.org/obo/<ontology>.owl.
sanitizeIds"error" | "mangle"What to do with node ids the format cannot hold. "error": the export throws (E_INVALID_ID) and no node is renamed. "mangle": such ids are rewritten and the originals are written to the file too, so an import with restoreMangledIds (on by default) reads the original ids back. Pajek is the exception: it always numbers nodes 1 to N and keeps the old ids as labels.
onMixedDirection"directed" | "error" | "undirected"What a format with one direction per file does with a graph that has both directed and undirected edges: "error" throws (E_DIRECTED), "directed" writes every edge as directed (an undirected edge once, as one directed edge), "undirected" writes the whole graph undirected. A format that keeps each edge's own direction (GraphML, GEXF, CSV, Pajek, XGMML, Cytoscape sessions, and the JGF and graphology JSON dialects) ignores it and writes both kinds; to make such a graph all one direction, read it with the import option onMixedDirection.

neo4j ​

graphtyImport options:

OptionTypeDefaultMeaning
nodesImportInput | readonly ImportInput[]More node files, each a string, bytes or a stream with its own header row; read after the main input.
relationshipsImportInput | readonly ImportInput[]Relationship files, each a string, bytes or a stream with its own header row; read after the node files.
delimiterstringto detect "," or a tab from the first rowsThe field delimiter, one character (neo4j-admin's --delimiter). The default is to detect "," or a tab from the first rows, so a .tsv file needs no option. It must differ from arrayDelimiter: with delimiter: ";", also pass arrayDelimiter: "," or "|".
arrayDelimiter"," | ";" | "|"";"The delimiter inside list values and :LABEL cells (neo4j-admin's --array-delimiter). It must differ from delimiter.
quotestringa double quoteThe quote character, one character (neo4j-admin's --quote).
ids"string" | "number" | "keep" | "canonical""keep" for JSONHow id text becomes a node id. "canonical": integer text such as "42" becomes the number 42 and everything else ("042", "4.2", "a") stays text. "string": every id stays text. "number": every id is read as a number, so "042" and "42" become one node (with a warning) and text that is not a number is an error. "keep": ids keep the type the file gives them. The default is "keep" for JSON, OBO, XGMML, CX, CX2 and Cytoscape sessions, and "canonical" for the other formats.
nodeIdFrom"id" | "label" | "index"Which value becomes the node id: the file's own id ("id"), the node's label ("label"), or its position among the nodes, counting from 0 ("index"). Use it when a file's ids are meaningless numbers and the labels are the real names. In d3 JSON, "index" also reads edges whose ends are node positions. In GML and Pajek it only renames: every node still needs its id key or vertex number, because edges refer to nodes by it, and a GML node without an id key is skipped with E_MISSING_ID. CSV reads this option only when there is a node table, and it does not just rename: with "label" the node table's label column (label, or the labelColumn option) gives the ids, so the edge table must name its nodes by those labels.
addMissingNodesbooleanfalse for GEXFWhether an edge may name a node the file never declares; that node is then created. When false, such an edge is skipped as an error. The default is false for GEXF, XGMML, CX, CX2 and Cytoscape sessions, whose files must declare every node, and true for the other formats.
duplicateEdges"max" | "keep" | "error" | "first" | "last" | "sum" | "min"What to do with a second edge between the same two nodes: "keep" keeps both, "first" / "last" keep one, "sum" / "min" / "max" keep one with the weights combined, and "error" stops the import. Merged edges are reported once as W_EDGES_MERGED.
selfLoops"keep" | "error" | "drop"What to do with an edge from a node to itself: "keep", "drop" (reported once as W_SELF_LOOPS_DROPPED with the number removed), or "error" to stop the import.
onMixedDirection"directed" | "error" | "expand" | "undirected"How edge direction is read. "expand" (the default) keeps the file's direction, and for a file that has both directed and undirected edges makes a directed graph in which each undirected edge is two edges, marked so an export can write them back as one. "directed" / "undirected" read every edge of any file that way, including a file whose edges all have the other direction, with a W_DIRECTION_FORCED warning. "error" stops the import at the first edge whose direction differs from the file's.
defaultDirectedbooleanundirected for GraphMLWhether the graph is directed when the file does not say. The default is undirected for GraphML, GEXF, GML, JSON and XGMML, and directed for CSV, Pajek and Cytoscape sessions. DOT, Neo4j, CX, CX2 and OBO files always settle the direction themselves (DOT by graph or digraph; the others are always directed), so those formats do not read this option and report it as W_OPTION_IGNORED.
weightFromstring"weight"The edge attribute read as the edge weight. The default is "weight", except "value" for GML and Pajek and none for OBO. Pass null to read every attribute as a plain attribute and leave the graph unweighted. A name no edge has leaves the graph unweighted, with a W_WEIGHT_NOT_FOUND warning: one options object with weightFrom: "weight" shared across formats reads GML and Pajek files, which keep their weights in value, without weights. An edge whose weight cell is empty or missing gets the default weight 1, and an export writes no weight for it.
weightDtype"f32" | "f64"Whether weights a 32-bit float cannot hold exactly are also kept exactly. "f64" keeps them in an edge column that snapshot.edges.byRole("weight") finds, so 0.1 and 16777217 stay exact. "f32" keeps no such column and uses less memory: the 32-bit weight arrays snapshot.weights and snapshot.edgeList().weights, which every import fills, are then the only weights.
long"string" | "f64"How a column the file declares as a 64-bit integer is stored: "f64" (a number, exact up to 2^53) or "string" (every digit kept, as text). GML declares no types, so there it applies to a key whose integer values go beyond 2^53.
restoreMangledIdsbooleanWhether to give back the original ids that an export with sanitizeIds: "mangle" had to rewrite. The export writes them to the file in an attribute whose name each format page gives. When false, the rewritten ids stay the ids and the originals are an ordinary node attribute, named after the format's spelling: graphty.originalId in GraphML, graphty_originalId in GML and Pajek, graphty:originalId in CX, CX2 and Cytoscape sessions, and a graphty:originalId entry of the property_value attribute in OBO.
hyperedges"error" | "skip" | "star" | "clique"What to do with a GraphML or JGF hyperedge (an edge with more than two ends): "skip" leaves it out with a warning, "error" stops the import, and "star" and "clique" turn it into ordinary edges. "clique" joins every pair of ends. "star" works differently per format: GraphML adds a new hub node joined to every end, while JGF makes the hyperedge's first node the hub, so no node is added. A directed JGF hyperedge (source and target arrays) becomes one edge from every source to every target under both. In JGF every edge made from a hyperedge carries the hyperedge's id, label, relation and metadata; GraphML drops a hyperedge's <data> and its <desc>, with a warning.
errorLimitnumberHow many errors an import tolerates. Each error skips one node, edge or value and is listed in the report; one error more than this stops the import with an ImportError. Pass 0 to stop at the first error.
signalAbortSignalCancels the import. When it aborts, the import stops and rejects with the signal's reason (an AbortError, or a TimeoutError from AbortSignal.timeout()).
onProgress(bytesDone: number, bytesTotal?: number | undefined) => voidCalled as the input is read, with the bytes read so far and the total. For a string or a Uint8Array the total is known from the first call. For a stream (which includes loadFromUrl() and loadFromFile()) it is undefined until the last call, which always has bytesDone === bytesTotal. Text counts its UTF-8 length.
encodingstringThe character encoding of byte input, as a label such as "utf-8", "windows-1252" or "utf-16le". Without it graph-io uses a byte order mark, then the encoding the file declares (an XML declaration, DOT's charset), then UTF-8, and reads bytes that are not UTF-8 as windows-1252 with a warning. A byte order mark wins over this option. A string input is already text: setting this option for one adds a W_OPTION_IGNORED warning, once per input (a CSV import with a nodes table has two inputs).

graphtyExport options:

OptionTypeDefaultMeaning
part"nodes" | "all" | "relationships""all""all" writes the node sections, then the relationship sections; "nodes" or "relationships" writes one kind.
delimiterstring","The field delimiter; one character.
arrayDelimiter"," | ";" | "|"";"The array delimiter of list values and :LABEL cells.
quotestringa double quoteThe quote character; one character.
weightColumnstring"weight"The property that receives the edge weights (<name>:double); null writes no weights.
idColumnstringThe property name of the :ID column (<name>:ID) for nodes that have no id property of their own; null writes a bare :ID.
sanitizeIds"error" | "mangle"What to do with node ids the format cannot hold. "error": the export throws (E_INVALID_ID) and no node is renamed. "mangle": such ids are rewritten and the originals are written to the file too, so an import with restoreMangledIds (on by default) reads the original ids back. Pajek is the exception: it always numbers nodes 1 to N and keeps the old ids as labels.
onMixedDirection"directed" | "error" | "undirected"What a format with one direction per file does with a graph that has both directed and undirected edges: "error" throws (E_DIRECTED), "directed" writes every edge as directed (an undirected edge once, as one directed edge), "undirected" writes the whole graph undirected. A format that keeps each edge's own direction (GraphML, GEXF, CSV, Pajek, XGMML, Cytoscape sessions, and the JGF and graphology JSON dialects) ignores it and writes both kinds; to make such a graph all one direction, read it with the import option onMixedDirection.

xgmml ​

graphtyImport options:

OptionTypeDefaultMeaning
labelAliasesbooleanon for files that use Cytoscape's (cy) namespaceFind an edge end that is missing, or names no node, from Cytoscape's "source (interaction) target" edge label, and fill a missing interaction from it. The default is on for files that use Cytoscape's (cy) namespace, off for others.
cytoscapeEscapesbooleanon for files that use Cytoscape's namespaceDecode Cytoscape's two-character \n and \t escapes in text values. The default is on for files that use Cytoscape's namespace, off for others.
repairBareAmpersandsbooleanRead an & that is not followed by ; within 7 characters as &amp;, with a warning for each, instead of failing on the invalid XML.
pairSurrogateReferencesbooleanJoin two character references that each hold half of a character (&#xD83D;&#xDE00;) into that character, with a warning for each pair, instead of failing.
zAs"column" | "position"Where Cytoscape's z value (a drawing order, not a depth) goes: "column" keeps it as a node attribute named z; "position" makes it the third coordinate of the position.
graphIndexnumberWhich graph of the file to read, 0-based in file order. When a file holds more than one graph, report.issues has a W_MULTIPLE_GRAPHS issue whose message gives the count.
graphNamestringWhich graph of the file to read, by the name the file gives it; a name two graphs share is refused.
ids"string" | "number" | "keep" | "canonical""keep" for JSONHow id text becomes a node id. "canonical": integer text such as "42" becomes the number 42 and everything else ("042", "4.2", "a") stays text. "string": every id stays text. "number": every id is read as a number, so "042" and "42" become one node (with a warning) and text that is not a number is an error. "keep": ids keep the type the file gives them. The default is "keep" for JSON, OBO, XGMML, CX, CX2 and Cytoscape sessions, and "canonical" for the other formats.
nodeIdFrom"id" | "label" | "index"Which value becomes the node id: the file's own id ("id"), the node's label ("label"), or its position among the nodes, counting from 0 ("index"). Use it when a file's ids are meaningless numbers and the labels are the real names. In d3 JSON, "index" also reads edges whose ends are node positions. In GML and Pajek it only renames: every node still needs its id key or vertex number, because edges refer to nodes by it, and a GML node without an id key is skipped with E_MISSING_ID. CSV reads this option only when there is a node table, and it does not just rename: with "label" the node table's label column (label, or the labelColumn option) gives the ids, so the edge table must name its nodes by those labels.
addMissingNodesbooleanfalse for GEXFWhether an edge may name a node the file never declares; that node is then created. When false, such an edge is skipped as an error. The default is false for GEXF, XGMML, CX, CX2 and Cytoscape sessions, whose files must declare every node, and true for the other formats.
duplicateEdges"max" | "keep" | "error" | "first" | "last" | "sum" | "min"What to do with a second edge between the same two nodes: "keep" keeps both, "first" / "last" keep one, "sum" / "min" / "max" keep one with the weights combined, and "error" stops the import. Merged edges are reported once as W_EDGES_MERGED.
selfLoops"keep" | "error" | "drop"What to do with an edge from a node to itself: "keep", "drop" (reported once as W_SELF_LOOPS_DROPPED with the number removed), or "error" to stop the import.
onMixedDirection"directed" | "error" | "expand" | "undirected"How edge direction is read. "expand" (the default) keeps the file's direction, and for a file that has both directed and undirected edges makes a directed graph in which each undirected edge is two edges, marked so an export can write them back as one. "directed" / "undirected" read every edge of any file that way, including a file whose edges all have the other direction, with a W_DIRECTION_FORCED warning. "error" stops the import at the first edge whose direction differs from the file's.
defaultDirectedbooleanundirected for GraphMLWhether the graph is directed when the file does not say. The default is undirected for GraphML, GEXF, GML, JSON and XGMML, and directed for CSV, Pajek and Cytoscape sessions. DOT, Neo4j, CX, CX2 and OBO files always settle the direction themselves (DOT by graph or digraph; the others are always directed), so those formats do not read this option and report it as W_OPTION_IGNORED.
weightFromstring"weight"The edge attribute read as the edge weight. The default is "weight", except "value" for GML and Pajek and none for OBO. Pass null to read every attribute as a plain attribute and leave the graph unweighted. A name no edge has leaves the graph unweighted, with a W_WEIGHT_NOT_FOUND warning: one options object with weightFrom: "weight" shared across formats reads GML and Pajek files, which keep their weights in value, without weights. An edge whose weight cell is empty or missing gets the default weight 1, and an export writes no weight for it.
weightDtype"f32" | "f64"Whether weights a 32-bit float cannot hold exactly are also kept exactly. "f64" keeps them in an edge column that snapshot.edges.byRole("weight") finds, so 0.1 and 16777217 stay exact. "f32" keeps no such column and uses less memory: the 32-bit weight arrays snapshot.weights and snapshot.edgeList().weights, which every import fills, are then the only weights.
long"string" | "f64"How a column the file declares as a 64-bit integer is stored: "f64" (a number, exact up to 2^53) or "string" (every digit kept, as text). GML declares no types, so there it applies to a key whose integer values go beyond 2^53.
restoreMangledIdsbooleanWhether to give back the original ids that an export with sanitizeIds: "mangle" had to rewrite. The export writes them to the file in an attribute whose name each format page gives. When false, the rewritten ids stay the ids and the originals are an ordinary node attribute, named after the format's spelling: graphty.originalId in GraphML, graphty_originalId in GML and Pajek, graphty:originalId in CX, CX2 and Cytoscape sessions, and a graphty:originalId entry of the property_value attribute in OBO.
hyperedges"error" | "skip" | "star" | "clique"What to do with a GraphML or JGF hyperedge (an edge with more than two ends): "skip" leaves it out with a warning, "error" stops the import, and "star" and "clique" turn it into ordinary edges. "clique" joins every pair of ends. "star" works differently per format: GraphML adds a new hub node joined to every end, while JGF makes the hyperedge's first node the hub, so no node is added. A directed JGF hyperedge (source and target arrays) becomes one edge from every source to every target under both. In JGF every edge made from a hyperedge carries the hyperedge's id, label, relation and metadata; GraphML drops a hyperedge's <data> and its <desc>, with a warning.
errorLimitnumberHow many errors an import tolerates. Each error skips one node, edge or value and is listed in the report; one error more than this stops the import with an ImportError. Pass 0 to stop at the first error.
signalAbortSignalCancels the import. When it aborts, the import stops and rejects with the signal's reason (an AbortError, or a TimeoutError from AbortSignal.timeout()).
onProgress(bytesDone: number, bytesTotal?: number | undefined) => voidCalled as the input is read, with the bytes read so far and the total. For a string or a Uint8Array the total is known from the first call. For a stream (which includes loadFromUrl() and loadFromFile()) it is undefined until the last call, which always has bytesDone === bytesTotal. Text counts its UTF-8 length.
encodingstringThe character encoding of byte input, as a label such as "utf-8", "windows-1252" or "utf-16le". Without it graph-io uses a byte order mark, then the encoding the file declares (an XML declaration, DOT's charset), then UTF-8, and reads bytes that are not UTF-8 as windows-1252 with a warning. A byte order mark wins over this option. A string input is already text: setting this option for one adds a W_OPTION_IGNORED warning, once per input (a CSV import with a nodes table has two inputs).

graphtyExport options:

OptionTypeDefaultMeaning
cytoscapeEscapesbooleanfalseWrite line breaks and tabs in text values as Cytoscape's two-character \n and \t, as Cytoscape does, instead of the XML character references &#10; and &#9;.
sanitizeIds"error" | "mangle"What to do with node ids the format cannot hold. "error": the export throws (E_INVALID_ID) and no node is renamed. "mangle": such ids are rewritten and the originals are written to the file too, so an import with restoreMangledIds (on by default) reads the original ids back. Pajek is the exception: it always numbers nodes 1 to N and keeps the old ids as labels.
onMixedDirection"directed" | "error" | "undirected"What a format with one direction per file does with a graph that has both directed and undirected edges: "error" throws (E_DIRECTED), "directed" writes every edge as directed (an undirected edge once, as one directed edge), "undirected" writes the whole graph undirected. A format that keeps each edge's own direction (GraphML, GEXF, CSV, Pajek, XGMML, Cytoscape sessions, and the JGF and graphology JSON dialects) ignores it and writes both kinds; to make such a graph all one direction, read it with the import option onMixedDirection.

cx2 ​

graphtyImport options:

OptionTypeDefaultMeaning
zAs"column" | "position""column" keeps a node's z as the data field z, where Cytoscape stores a stacking order. "position" reads it as a third coordinate, and since a Cytoscape position has no z, it is dropped with no warning.
ids"string" | "number" | "keep" | "canonical""keep" for JSONHow id text becomes a node id. "canonical": integer text such as "42" becomes the number 42 and everything else ("042", "4.2", "a") stays text. "string": every id stays text. "number": every id is read as a number, so "042" and "42" become one node (with a warning) and text that is not a number is an error. "keep": ids keep the type the file gives them. The default is "keep" for JSON, OBO, XGMML, CX, CX2 and Cytoscape sessions, and "canonical" for the other formats.
nodeIdFrom"id" | "label" | "index"Which value becomes the node id: the file's own id ("id"), the node's label ("label"), or its position among the nodes, counting from 0 ("index"). Use it when a file's ids are meaningless numbers and the labels are the real names. In d3 JSON, "index" also reads edges whose ends are node positions. In GML and Pajek it only renames: every node still needs its id key or vertex number, because edges refer to nodes by it, and a GML node without an id key is skipped with E_MISSING_ID. CSV reads this option only when there is a node table, and it does not just rename: with "label" the node table's label column (label, or the labelColumn option) gives the ids, so the edge table must name its nodes by those labels.
addMissingNodesbooleanfalse for GEXFWhether an edge may name a node the file never declares; that node is then created. When false, such an edge is skipped as an error. The default is false for GEXF, XGMML, CX, CX2 and Cytoscape sessions, whose files must declare every node, and true for the other formats.
duplicateEdges"max" | "keep" | "error" | "first" | "last" | "sum" | "min"What to do with a second edge between the same two nodes: "keep" keeps both, "first" / "last" keep one, "sum" / "min" / "max" keep one with the weights combined, and "error" stops the import. Merged edges are reported once as W_EDGES_MERGED.
selfLoops"keep" | "error" | "drop"What to do with an edge from a node to itself: "keep", "drop" (reported once as W_SELF_LOOPS_DROPPED with the number removed), or "error" to stop the import.
onMixedDirection"directed" | "error" | "expand" | "undirected"How edge direction is read. "expand" (the default) keeps the file's direction, and for a file that has both directed and undirected edges makes a directed graph in which each undirected edge is two edges, marked so an export can write them back as one. "directed" / "undirected" read every edge of any file that way, including a file whose edges all have the other direction, with a W_DIRECTION_FORCED warning. "error" stops the import at the first edge whose direction differs from the file's.
defaultDirectedbooleanundirected for GraphMLWhether the graph is directed when the file does not say. The default is undirected for GraphML, GEXF, GML, JSON and XGMML, and directed for CSV, Pajek and Cytoscape sessions. DOT, Neo4j, CX, CX2 and OBO files always settle the direction themselves (DOT by graph or digraph; the others are always directed), so those formats do not read this option and report it as W_OPTION_IGNORED.
weightFromstring"weight"The edge attribute read as the edge weight. The default is "weight", except "value" for GML and Pajek and none for OBO. Pass null to read every attribute as a plain attribute and leave the graph unweighted. A name no edge has leaves the graph unweighted, with a W_WEIGHT_NOT_FOUND warning: one options object with weightFrom: "weight" shared across formats reads GML and Pajek files, which keep their weights in value, without weights. An edge whose weight cell is empty or missing gets the default weight 1, and an export writes no weight for it.
weightDtype"f32" | "f64"Whether weights a 32-bit float cannot hold exactly are also kept exactly. "f64" keeps them in an edge column that snapshot.edges.byRole("weight") finds, so 0.1 and 16777217 stay exact. "f32" keeps no such column and uses less memory: the 32-bit weight arrays snapshot.weights and snapshot.edgeList().weights, which every import fills, are then the only weights.
long"string" | "f64"How a column the file declares as a 64-bit integer is stored: "f64" (a number, exact up to 2^53) or "string" (every digit kept, as text). GML declares no types, so there it applies to a key whose integer values go beyond 2^53.
restoreMangledIdsbooleanWhether to give back the original ids that an export with sanitizeIds: "mangle" had to rewrite. The export writes them to the file in an attribute whose name each format page gives. When false, the rewritten ids stay the ids and the originals are an ordinary node attribute, named after the format's spelling: graphty.originalId in GraphML, graphty_originalId in GML and Pajek, graphty:originalId in CX, CX2 and Cytoscape sessions, and a graphty:originalId entry of the property_value attribute in OBO.
hyperedges"error" | "skip" | "star" | "clique"What to do with a GraphML or JGF hyperedge (an edge with more than two ends): "skip" leaves it out with a warning, "error" stops the import, and "star" and "clique" turn it into ordinary edges. "clique" joins every pair of ends. "star" works differently per format: GraphML adds a new hub node joined to every end, while JGF makes the hyperedge's first node the hub, so no node is added. A directed JGF hyperedge (source and target arrays) becomes one edge from every source to every target under both. In JGF every edge made from a hyperedge carries the hyperedge's id, label, relation and metadata; GraphML drops a hyperedge's <data> and its <desc>, with a warning.
errorLimitnumberHow many errors an import tolerates. Each error skips one node, edge or value and is listed in the report; one error more than this stops the import with an ImportError. Pass 0 to stop at the first error.
signalAbortSignalCancels the import. When it aborts, the import stops and rejects with the signal's reason (an AbortError, or a TimeoutError from AbortSignal.timeout()).
onProgress(bytesDone: number, bytesTotal?: number | undefined) => voidCalled as the input is read, with the bytes read so far and the total. For a string or a Uint8Array the total is known from the first call. For a stream (which includes loadFromUrl() and loadFromFile()) it is undefined until the last call, which always has bytesDone === bytesTotal. Text counts its UTF-8 length.
encodingstringThe character encoding of byte input, as a label such as "utf-8", "windows-1252" or "utf-16le". Without it graph-io uses a byte order mark, then the encoding the file declares (an XML declaration, DOT's charset), then UTF-8, and reads bytes that are not UTF-8 as windows-1252 with a warning. A byte order mark wins over this option. A string input is already text: setting this option for one adds a W_OPTION_IGNORED warning, once per input (a CSV import with a nodes table has two inputs).

graphtyExport options:

OptionTypeDefaultMeaning
sanitizeIds"error" | "mangle"What to do with node ids the format cannot hold. "error": the export throws (E_INVALID_ID) and no node is renamed. "mangle": such ids are rewritten and the originals are written to the file too, so an import with restoreMangledIds (on by default) reads the original ids back. Pajek is the exception: it always numbers nodes 1 to N and keeps the old ids as labels.
onMixedDirection"directed" | "error" | "undirected"What a format with one direction per file does with a graph that has both directed and undirected edges: "error" throws (E_DIRECTED), "directed" writes every edge as directed (an undirected edge once, as one directed edge), "undirected" writes the whole graph undirected. A format that keeps each edge's own direction (GraphML, GEXF, CSV, Pajek, XGMML, Cytoscape sessions, and the JGF and graphology JSON dialects) ignores it and writes both kinds; to make such a graph all one direction, read it with the import option onMixedDirection.

cx ​

graphtyImport options:

OptionTypeDefaultMeaning
zAs"column" | "position""column" keeps a node's z as the data field z, where Cytoscape stores a stacking order. "position" reads it as a third coordinate, and since a Cytoscape position has no z, it is dropped with no warning.
graphIndexnumberWhich graph of the file to read, 0-based in file order. When a file holds more than one graph, report.issues has a W_MULTIPLE_GRAPHS issue whose message gives the count.
graphNamestringWhich graph of the file to read, by the name the file gives it; a name two graphs share is refused.
ids"string" | "number" | "keep" | "canonical""keep" for JSONHow id text becomes a node id. "canonical": integer text such as "42" becomes the number 42 and everything else ("042", "4.2", "a") stays text. "string": every id stays text. "number": every id is read as a number, so "042" and "42" become one node (with a warning) and text that is not a number is an error. "keep": ids keep the type the file gives them. The default is "keep" for JSON, OBO, XGMML, CX, CX2 and Cytoscape sessions, and "canonical" for the other formats.
nodeIdFrom"id" | "label" | "index"Which value becomes the node id: the file's own id ("id"), the node's label ("label"), or its position among the nodes, counting from 0 ("index"). Use it when a file's ids are meaningless numbers and the labels are the real names. In d3 JSON, "index" also reads edges whose ends are node positions. In GML and Pajek it only renames: every node still needs its id key or vertex number, because edges refer to nodes by it, and a GML node without an id key is skipped with E_MISSING_ID. CSV reads this option only when there is a node table, and it does not just rename: with "label" the node table's label column (label, or the labelColumn option) gives the ids, so the edge table must name its nodes by those labels.
addMissingNodesbooleanfalse for GEXFWhether an edge may name a node the file never declares; that node is then created. When false, such an edge is skipped as an error. The default is false for GEXF, XGMML, CX, CX2 and Cytoscape sessions, whose files must declare every node, and true for the other formats.
duplicateEdges"max" | "keep" | "error" | "first" | "last" | "sum" | "min"What to do with a second edge between the same two nodes: "keep" keeps both, "first" / "last" keep one, "sum" / "min" / "max" keep one with the weights combined, and "error" stops the import. Merged edges are reported once as W_EDGES_MERGED.
selfLoops"keep" | "error" | "drop"What to do with an edge from a node to itself: "keep", "drop" (reported once as W_SELF_LOOPS_DROPPED with the number removed), or "error" to stop the import.
onMixedDirection"directed" | "error" | "expand" | "undirected"How edge direction is read. "expand" (the default) keeps the file's direction, and for a file that has both directed and undirected edges makes a directed graph in which each undirected edge is two edges, marked so an export can write them back as one. "directed" / "undirected" read every edge of any file that way, including a file whose edges all have the other direction, with a W_DIRECTION_FORCED warning. "error" stops the import at the first edge whose direction differs from the file's.
defaultDirectedbooleanundirected for GraphMLWhether the graph is directed when the file does not say. The default is undirected for GraphML, GEXF, GML, JSON and XGMML, and directed for CSV, Pajek and Cytoscape sessions. DOT, Neo4j, CX, CX2 and OBO files always settle the direction themselves (DOT by graph or digraph; the others are always directed), so those formats do not read this option and report it as W_OPTION_IGNORED.
weightFromstring"weight"The edge attribute read as the edge weight. The default is "weight", except "value" for GML and Pajek and none for OBO. Pass null to read every attribute as a plain attribute and leave the graph unweighted. A name no edge has leaves the graph unweighted, with a W_WEIGHT_NOT_FOUND warning: one options object with weightFrom: "weight" shared across formats reads GML and Pajek files, which keep their weights in value, without weights. An edge whose weight cell is empty or missing gets the default weight 1, and an export writes no weight for it.
weightDtype"f32" | "f64"Whether weights a 32-bit float cannot hold exactly are also kept exactly. "f64" keeps them in an edge column that snapshot.edges.byRole("weight") finds, so 0.1 and 16777217 stay exact. "f32" keeps no such column and uses less memory: the 32-bit weight arrays snapshot.weights and snapshot.edgeList().weights, which every import fills, are then the only weights.
long"string" | "f64"How a column the file declares as a 64-bit integer is stored: "f64" (a number, exact up to 2^53) or "string" (every digit kept, as text). GML declares no types, so there it applies to a key whose integer values go beyond 2^53.
restoreMangledIdsbooleanWhether to give back the original ids that an export with sanitizeIds: "mangle" had to rewrite. The export writes them to the file in an attribute whose name each format page gives. When false, the rewritten ids stay the ids and the originals are an ordinary node attribute, named after the format's spelling: graphty.originalId in GraphML, graphty_originalId in GML and Pajek, graphty:originalId in CX, CX2 and Cytoscape sessions, and a graphty:originalId entry of the property_value attribute in OBO.
hyperedges"error" | "skip" | "star" | "clique"What to do with a GraphML or JGF hyperedge (an edge with more than two ends): "skip" leaves it out with a warning, "error" stops the import, and "star" and "clique" turn it into ordinary edges. "clique" joins every pair of ends. "star" works differently per format: GraphML adds a new hub node joined to every end, while JGF makes the hyperedge's first node the hub, so no node is added. A directed JGF hyperedge (source and target arrays) becomes one edge from every source to every target under both. In JGF every edge made from a hyperedge carries the hyperedge's id, label, relation and metadata; GraphML drops a hyperedge's <data> and its <desc>, with a warning.
errorLimitnumberHow many errors an import tolerates. Each error skips one node, edge or value and is listed in the report; one error more than this stops the import with an ImportError. Pass 0 to stop at the first error.
signalAbortSignalCancels the import. When it aborts, the import stops and rejects with the signal's reason (an AbortError, or a TimeoutError from AbortSignal.timeout()).
onProgress(bytesDone: number, bytesTotal?: number | undefined) => voidCalled as the input is read, with the bytes read so far and the total. For a string or a Uint8Array the total is known from the first call. For a stream (which includes loadFromUrl() and loadFromFile()) it is undefined until the last call, which always has bytesDone === bytesTotal. Text counts its UTF-8 length.
encodingstringThe character encoding of byte input, as a label such as "utf-8", "windows-1252" or "utf-16le". Without it graph-io uses a byte order mark, then the encoding the file declares (an XML declaration, DOT's charset), then UTF-8, and reads bytes that are not UTF-8 as windows-1252 with a warning. A byte order mark wins over this option. A string input is already text: setting this option for one adds a W_OPTION_IGNORED warning, once per input (a CSV import with a nodes table has two inputs).

graphtyExport options:

OptionTypeDefaultMeaning
sanitizeIds"error" | "mangle"What to do with node ids the format cannot hold. "error": the export throws (E_INVALID_ID) and no node is renamed. "mangle": such ids are rewritten and the originals are written to the file too, so an import with restoreMangledIds (on by default) reads the original ids back. Pajek is the exception: it always numbers nodes 1 to N and keeps the old ids as labels.
onMixedDirection"directed" | "error" | "undirected"What a format with one direction per file does with a graph that has both directed and undirected edges: "error" throws (E_DIRECTED), "directed" writes every edge as directed (an undirected edge once, as one directed edge), "undirected" writes the whole graph undirected. A format that keeps each edge's own direction (GraphML, GEXF, CSV, Pajek, XGMML, Cytoscape sessions, and the JGF and graphology JSON dialects) ignores it and writes both kinds; to make such a graph all one direction, read it with the import option onMixedDirection.

obo ​

graphtyImport options:

OptionTypeDefaultMeaning
obsolete"keep" | "drop""keep" reads obsolete terms as nodes with is_obsolete set to true; "drop" leaves them and their edges out.
typedefs"nodes" | "metadata""metadata" keeps the [Typedef] frames (relation definitions) in snapshot.meta.extra.obo.typedefs; "nodes" makes them nodes too, with their is_a edges.
ids"string" | "number" | "keep" | "canonical""keep" for JSONHow id text becomes a node id. "canonical": integer text such as "42" becomes the number 42 and everything else ("042", "4.2", "a") stays text. "string": every id stays text. "number": every id is read as a number, so "042" and "42" become one node (with a warning) and text that is not a number is an error. "keep": ids keep the type the file gives them. The default is "keep" for JSON, OBO, XGMML, CX, CX2 and Cytoscape sessions, and "canonical" for the other formats.
nodeIdFrom"id" | "label" | "index"Which value becomes the node id: the file's own id ("id"), the node's label ("label"), or its position among the nodes, counting from 0 ("index"). Use it when a file's ids are meaningless numbers and the labels are the real names. In d3 JSON, "index" also reads edges whose ends are node positions. In GML and Pajek it only renames: every node still needs its id key or vertex number, because edges refer to nodes by it, and a GML node without an id key is skipped with E_MISSING_ID. CSV reads this option only when there is a node table, and it does not just rename: with "label" the node table's label column (label, or the labelColumn option) gives the ids, so the edge table must name its nodes by those labels.
addMissingNodesbooleanfalse for GEXFWhether an edge may name a node the file never declares; that node is then created. When false, such an edge is skipped as an error. The default is false for GEXF, XGMML, CX, CX2 and Cytoscape sessions, whose files must declare every node, and true for the other formats.
duplicateEdges"max" | "keep" | "error" | "first" | "last" | "sum" | "min"What to do with a second edge between the same two nodes: "keep" keeps both, "first" / "last" keep one, "sum" / "min" / "max" keep one with the weights combined, and "error" stops the import. Merged edges are reported once as W_EDGES_MERGED.
selfLoops"keep" | "error" | "drop"What to do with an edge from a node to itself: "keep", "drop" (reported once as W_SELF_LOOPS_DROPPED with the number removed), or "error" to stop the import.
onMixedDirection"directed" | "error" | "expand" | "undirected"How edge direction is read. "expand" (the default) keeps the file's direction, and for a file that has both directed and undirected edges makes a directed graph in which each undirected edge is two edges, marked so an export can write them back as one. "directed" / "undirected" read every edge of any file that way, including a file whose edges all have the other direction, with a W_DIRECTION_FORCED warning. "error" stops the import at the first edge whose direction differs from the file's.
defaultDirectedbooleanundirected for GraphMLWhether the graph is directed when the file does not say. The default is undirected for GraphML, GEXF, GML, JSON and XGMML, and directed for CSV, Pajek and Cytoscape sessions. DOT, Neo4j, CX, CX2 and OBO files always settle the direction themselves (DOT by graph or digraph; the others are always directed), so those formats do not read this option and report it as W_OPTION_IGNORED.
weightFromstring"weight"The edge attribute read as the edge weight. The default is "weight", except "value" for GML and Pajek and none for OBO. Pass null to read every attribute as a plain attribute and leave the graph unweighted. A name no edge has leaves the graph unweighted, with a W_WEIGHT_NOT_FOUND warning: one options object with weightFrom: "weight" shared across formats reads GML and Pajek files, which keep their weights in value, without weights. An edge whose weight cell is empty or missing gets the default weight 1, and an export writes no weight for it.
weightDtype"f32" | "f64"Whether weights a 32-bit float cannot hold exactly are also kept exactly. "f64" keeps them in an edge column that snapshot.edges.byRole("weight") finds, so 0.1 and 16777217 stay exact. "f32" keeps no such column and uses less memory: the 32-bit weight arrays snapshot.weights and snapshot.edgeList().weights, which every import fills, are then the only weights.
long"string" | "f64"How a column the file declares as a 64-bit integer is stored: "f64" (a number, exact up to 2^53) or "string" (every digit kept, as text). GML declares no types, so there it applies to a key whose integer values go beyond 2^53.
restoreMangledIdsbooleanWhether to give back the original ids that an export with sanitizeIds: "mangle" had to rewrite. The export writes them to the file in an attribute whose name each format page gives. When false, the rewritten ids stay the ids and the originals are an ordinary node attribute, named after the format's spelling: graphty.originalId in GraphML, graphty_originalId in GML and Pajek, graphty:originalId in CX, CX2 and Cytoscape sessions, and a graphty:originalId entry of the property_value attribute in OBO.
hyperedges"error" | "skip" | "star" | "clique"What to do with a GraphML or JGF hyperedge (an edge with more than two ends): "skip" leaves it out with a warning, "error" stops the import, and "star" and "clique" turn it into ordinary edges. "clique" joins every pair of ends. "star" works differently per format: GraphML adds a new hub node joined to every end, while JGF makes the hyperedge's first node the hub, so no node is added. A directed JGF hyperedge (source and target arrays) becomes one edge from every source to every target under both. In JGF every edge made from a hyperedge carries the hyperedge's id, label, relation and metadata; GraphML drops a hyperedge's <data> and its <desc>, with a warning.
errorLimitnumberHow many errors an import tolerates. Each error skips one node, edge or value and is listed in the report; one error more than this stops the import with an ImportError. Pass 0 to stop at the first error.
signalAbortSignalCancels the import. When it aborts, the import stops and rejects with the signal's reason (an AbortError, or a TimeoutError from AbortSignal.timeout()).
onProgress(bytesDone: number, bytesTotal?: number | undefined) => voidCalled as the input is read, with the bytes read so far and the total. For a string or a Uint8Array the total is known from the first call. For a stream (which includes loadFromUrl() and loadFromFile()) it is undefined until the last call, which always has bytesDone === bytesTotal. Text counts its UTF-8 length.
encodingstringThe character encoding of byte input, as a label such as "utf-8", "windows-1252" or "utf-16le". Without it graph-io uses a byte order mark, then the encoding the file declares (an XML declaration, DOT's charset), then UTF-8, and reads bytes that are not UTF-8 as windows-1252 with a warning. A byte order mark wins over this option. A string input is already text: setting this option for one adds a W_OPTION_IGNORED warning, once per input (a CSV import with a nodes table has two inputs).

graphtyExport options:

OptionTypeDefaultMeaning
relationstringThe relation written for an edge that has none of its own (no relation value): an OBO id such as is_a or part_of. Reasoners and ROBOT read is_a as subclassing.
ontologystringthe id an OBO import readThe ontology id written in the header, such as go or uberon. It may hold letters, digits and _ . - /; any other character makes checkExport() and the save throw E_UNSUPPORTED. The default is the id an OBO import read, else the graph name with every other character replaced by _, else no ontology line.
sanitizeIds"error" | "mangle"What to do with node ids the format cannot hold. "error": the export throws (E_INVALID_ID) and no node is renamed. "mangle": such ids are rewritten and the originals are written to the file too, so an import with restoreMangledIds (on by default) reads the original ids back. Pajek is the exception: it always numbers nodes 1 to N and keeps the old ids as labels.
onMixedDirection"directed" | "error" | "undirected"What a format with one direction per file does with a graph that has both directed and undirected edges: "error" throws (E_DIRECTED), "directed" writes every edge as directed (an undirected edge once, as one directed edge), "undirected" writes the whole graph undirected. A format that keeps each edge's own direction (GraphML, GEXF, CSV, Pajek, XGMML, Cytoscape sessions, and the JGF and graphology JSON dialects) ignores it and writes both kinds; to make such a graph all one direction, read it with the import option onMixedDirection.

cys ​

graphtyImport options:

OptionTypeDefaultMeaning
zAs"column" | "position"Where Cytoscape's z value (a drawing order, not a depth) goes: "column" keeps it as a node attribute named z; "position" makes it the third coordinate of the position.
maxUncompressedBytesnumberThe most bytes one import may unpack from the session archive, in total (2 GiB). A file that would unpack to more, or one compressed more than 1000 to 1, fails with E_TOO_LARGE.
graphIndexnumberWhich graph of the file to read, 0-based in file order. When a file holds more than one graph, report.issues has a W_MULTIPLE_GRAPHS issue whose message gives the count.
graphNamestringWhich graph of the file to read, by the name the file gives it; a name two graphs share is refused.
ids"string" | "number" | "keep" | "canonical""keep" for JSONHow id text becomes a node id. "canonical": integer text such as "42" becomes the number 42 and everything else ("042", "4.2", "a") stays text. "string": every id stays text. "number": every id is read as a number, so "042" and "42" become one node (with a warning) and text that is not a number is an error. "keep": ids keep the type the file gives them. The default is "keep" for JSON, OBO, XGMML, CX, CX2 and Cytoscape sessions, and "canonical" for the other formats.
nodeIdFrom"id" | "label" | "index"Which value becomes the node id: the file's own id ("id"), the node's label ("label"), or its position among the nodes, counting from 0 ("index"). Use it when a file's ids are meaningless numbers and the labels are the real names. In d3 JSON, "index" also reads edges whose ends are node positions. In GML and Pajek it only renames: every node still needs its id key or vertex number, because edges refer to nodes by it, and a GML node without an id key is skipped with E_MISSING_ID. CSV reads this option only when there is a node table, and it does not just rename: with "label" the node table's label column (label, or the labelColumn option) gives the ids, so the edge table must name its nodes by those labels.
addMissingNodesbooleanfalse for GEXFWhether an edge may name a node the file never declares; that node is then created. When false, such an edge is skipped as an error. The default is false for GEXF, XGMML, CX, CX2 and Cytoscape sessions, whose files must declare every node, and true for the other formats.
duplicateEdges"max" | "keep" | "error" | "first" | "last" | "sum" | "min"What to do with a second edge between the same two nodes: "keep" keeps both, "first" / "last" keep one, "sum" / "min" / "max" keep one with the weights combined, and "error" stops the import. Merged edges are reported once as W_EDGES_MERGED.
selfLoops"keep" | "error" | "drop"What to do with an edge from a node to itself: "keep", "drop" (reported once as W_SELF_LOOPS_DROPPED with the number removed), or "error" to stop the import.
onMixedDirection"directed" | "error" | "expand" | "undirected"How edge direction is read. "expand" (the default) keeps the file's direction, and for a file that has both directed and undirected edges makes a directed graph in which each undirected edge is two edges, marked so an export can write them back as one. "directed" / "undirected" read every edge of any file that way, including a file whose edges all have the other direction, with a W_DIRECTION_FORCED warning. "error" stops the import at the first edge whose direction differs from the file's.
defaultDirectedbooleanundirected for GraphMLWhether the graph is directed when the file does not say. The default is undirected for GraphML, GEXF, GML, JSON and XGMML, and directed for CSV, Pajek and Cytoscape sessions. DOT, Neo4j, CX, CX2 and OBO files always settle the direction themselves (DOT by graph or digraph; the others are always directed), so those formats do not read this option and report it as W_OPTION_IGNORED.
weightFromstring"weight"The edge attribute read as the edge weight. The default is "weight", except "value" for GML and Pajek and none for OBO. Pass null to read every attribute as a plain attribute and leave the graph unweighted. A name no edge has leaves the graph unweighted, with a W_WEIGHT_NOT_FOUND warning: one options object with weightFrom: "weight" shared across formats reads GML and Pajek files, which keep their weights in value, without weights. An edge whose weight cell is empty or missing gets the default weight 1, and an export writes no weight for it.
weightDtype"f32" | "f64"Whether weights a 32-bit float cannot hold exactly are also kept exactly. "f64" keeps them in an edge column that snapshot.edges.byRole("weight") finds, so 0.1 and 16777217 stay exact. "f32" keeps no such column and uses less memory: the 32-bit weight arrays snapshot.weights and snapshot.edgeList().weights, which every import fills, are then the only weights.
long"string" | "f64"How a column the file declares as a 64-bit integer is stored: "f64" (a number, exact up to 2^53) or "string" (every digit kept, as text). GML declares no types, so there it applies to a key whose integer values go beyond 2^53.
restoreMangledIdsbooleanWhether to give back the original ids that an export with sanitizeIds: "mangle" had to rewrite. The export writes them to the file in an attribute whose name each format page gives. When false, the rewritten ids stay the ids and the originals are an ordinary node attribute, named after the format's spelling: graphty.originalId in GraphML, graphty_originalId in GML and Pajek, graphty:originalId in CX, CX2 and Cytoscape sessions, and a graphty:originalId entry of the property_value attribute in OBO.
hyperedges"error" | "skip" | "star" | "clique"What to do with a GraphML or JGF hyperedge (an edge with more than two ends): "skip" leaves it out with a warning, "error" stops the import, and "star" and "clique" turn it into ordinary edges. "clique" joins every pair of ends. "star" works differently per format: GraphML adds a new hub node joined to every end, while JGF makes the hyperedge's first node the hub, so no node is added. A directed JGF hyperedge (source and target arrays) becomes one edge from every source to every target under both. In JGF every edge made from a hyperedge carries the hyperedge's id, label, relation and metadata; GraphML drops a hyperedge's <data> and its <desc>, with a warning.
errorLimitnumberHow many errors an import tolerates. Each error skips one node, edge or value and is listed in the report; one error more than this stops the import with an ImportError. Pass 0 to stop at the first error.
signalAbortSignalCancels the import. When it aborts, the import stops and rejects with the signal's reason (an AbortError, or a TimeoutError from AbortSignal.timeout()).
onProgress(bytesDone: number, bytesTotal?: number | undefined) => voidCalled as the input is read, with the bytes read so far and the total. For a string or a Uint8Array the total is known from the first call. For a stream (which includes loadFromUrl() and loadFromFile()) it is undefined until the last call, which always has bytesDone === bytesTotal. Text counts its UTF-8 length.
encodingstringThe character encoding of byte input, as a label such as "utf-8", "windows-1252" or "utf-16le". Without it graph-io uses a byte order mark, then the encoding the file declares (an XML declaration, DOT's charset), then UTF-8, and reads bytes that are not UTF-8 as windows-1252 with a warning. A byte order mark wins over this option. A string input is already text: setting this option for one adds a W_OPTION_IGNORED warning, once per input (a CSV import with a nodes table has two inputs).

graphtyExport options:

OptionTypeDefaultMeaning
sanitizeIds"error" | "mangle"What to do with node ids the format cannot hold. "error": the export throws (E_INVALID_ID) and no node is renamed. "mangle": such ids are rewritten and the originals are written to the file too, so an import with restoreMangledIds (on by default) reads the original ids back. Pajek is the exception: it always numbers nodes 1 to N and keeps the old ids as labels.
onMixedDirection"directed" | "error" | "undirected"What a format with one direction per file does with a graph that has both directed and undirected edges: "error" throws (E_DIRECTED), "directed" writes every edge as directed (an undirected edge once, as one directed edge), "undirected" writes the whole graph undirected. A format that keeps each edge's own direction (GraphML, GEXF, CSV, Pajek, XGMML, Cytoscape sessions, and the JGF and graphology JSON dialects) ignores it and writes both kinds; to make such a graph all one direction, read it with the import option onMixedDirection.

Try it ​

See also ​