Skip to main content

Installation

Install @statelyai/graph using your preferred package manager.

Package Managers

npm install @statelyai/graph

Optional Peer Dependencies

Some format converters require additional peer dependencies. Install them only if you need the corresponding format:

XML Formats (GEXF, GraphML)

For GEXF and GraphML support:
npm install fast-xml-parser

DOT Format (Graphviz)

For DOT format support:
npm install dotparser

Validation (Zod)

For runtime schema validation:
npm install zod
All peer dependencies are optional. The core library works without any of them. Only install what you need for your specific use case.

Import Paths

The library uses subpath exports for tree-shaking. Import only what you need:

Core Functions

// Main graph operations
import { createGraph, addNode, addEdge } from '@statelyai/graph';

// Algorithms
import { bfs, dfs, getShortestPath } from '@statelyai/graph/algorithms';

// Queries
import { getNeighbors, getDegree } from '@statelyai/graph/queries';

Format Converters

Each format has its own import path:
// Cytoscape.js
import { toCytoscapeJSON, fromCytoscapeJSON } from '@statelyai/graph/cytoscape';

// D3.js
import { toD3Graph, fromD3Graph } from '@statelyai/graph/d3';

// DOT (Graphviz)
import { toDOT, fromDOT } from '@statelyai/graph/dot';

// GraphML
import { toGraphML, fromGraphML } from '@statelyai/graph/graphml';

// GEXF (Gephi)
import { toGEXF, fromGEXF } from '@statelyai/graph/gexf';

// JSON Graph Format
import { toJGF, fromJGF } from '@statelyai/graph/jgf';

// Mermaid diagrams
import { toMermaidFlowchart, fromMermaidFlowchart } from '@statelyai/graph/mermaid';

// Edge list / Adjacency list
import { toEdgeList, fromEdgeList } from '@statelyai/graph/edge-list';
import { toAdjacencyList, fromAdjacencyList } from '@statelyai/graph/adjacency-list';

TypeScript Configuration

The library is written in TypeScript and includes type definitions. No additional setup is required for TypeScript projects.
The library requires ES modules. If you’re using CommonJS, you may need to configure your build tool to handle ES module imports.

Version Support

  • Node.js: 18.x or higher recommended
  • TypeScript: 5.0 or higher
  • Package Manager: npm 7+, yarn 1.22+, or pnpm 8+

Next Steps

Quick Start

Create your first graph

Core Concepts

Learn about graph structure and types

Build docs developers (and LLMs) love