graph-io ​
graph-io reads and writes graph files. It turns a GraphML, GEXF, CSV or other graph file into a @graphty/graph-format snapshot, and writes a snapshot back out in any of the same formats. It runs in browsers and in Node, and streams large files. Its one dependency, graph-format, is installed with it.
When a file holds something graph-io cannot represent, or a format cannot hold part of your graph, graph-io tells you: an import returns a report that lists every skipped or changed element, and checkExport() lists what a save would lose before you write a byte.
npm install @graphty/graph-ioStart with the Quick start.
Formats ​
| Format | What it is |
|---|---|
| JSON | NetworkX, d3, JSON Graph Format, Cytoscape.js, graphology, vis.js and OBO Graphs documents |
| GraphML | The XML format of yEd, NetworkX, igraph and Gephi |
| GEXF | Gephi's XML format, with visual attributes and dynamic graphs |
| CSV and TSV | Edge lists, node tables and adjacency lists from spreadsheets and scripts |
| GML | The Graph Modelling Language, as NetworkX and igraph write it |
| DOT | Graphviz graphs |
| Pajek | Pajek .net networks and .paj projects |
| Neo4j CSV | The CSV files neo4j-admin import reads |
| XGMML | Cytoscape's XML network format |
| CX2 | The JSON exchange format of NDEx and Cytoscape 3.10 and later |
| CX | Version 1 of the same exchange format |
| OBO | The ontology format of the Gene Ontology and the OBO Foundry |
| Cytoscape session | Cytoscape Desktop .cys files |
graph-io reads and writes all of them. All formats compares what each one keeps.
Where to go next ​
- Loading graphs: every kind of input, format options, files with several graphs, cancelling, keeping a browser bundle small.
- Reading the graph: nodes, attributes, labels, edges, weights.
- Saving graphs: checking a save, streaming, downloads, ids a format cannot hold.
- The import report and errors: what went wrong, and where.
- Format detection: how graph-io tells formats apart, and when to name one.
- Options reference: every option, with its default.
- Issue and loss codes: every code an import or a save can report.
- Writing a format plugin: teach graph-io a format of your own.
- Extending an existing format: change how a built-in format reads or writes.
- API reference: every export, grouped by task.
If you display graphs with graphty-element, you already use graph-io: element.loadFromUrl() and element.loadFromFile() read files through it. Use graph-io directly when you want the graph data yourself, for example to convert files, analyze a graph, or draw it with your own renderer.