Importing nodes and edges

Raphtory allows you to import Node and Edge objects from one graph into another. The import functions support:

  • Single or bulk imports – import individual entities or entire collections
  • Lists or iterables – pass lists, Nodes, or Edges directly
  • Views – import from any GraphView including temporal windows, layer filters, and subgraphs
  • Renaming – import with new IDs using the _as variants
  • Merging – combine histories when importing into existing entities

The following sections provide worked examples of each capability.

Setup

First, let's create a source Graph to import from:

Importing individual nodes and edges

The simplest case is importing a single Node or Edge. Use import_node() and import_edge() to copy entities with all their history and properties:

Importing from lists or iterables

For bulk imports, pass a list of Node/Edge objects, or use Nodes and Edges iterables directly. This is efficient for copying large portions of a graph:

Importing from views

Import works with any GraphView, letting you copy filtered subsets of your graph. This includes temporal windows, layer filters, subgraphs, and any combination of these. Importantly, when importing from a view, only the updates visible within that view are copied – not the full history of each node/edge.

For more on creating and using views, see the Views & Windows section.

Renaming on import

Use the _as variants to import nodes and edges with new IDs. This works for both single entities and bulk imports:

Copying within the same graph

You can also use import functions on the same Graph to copy a node or edge with a new ID. This is useful for creating duplicates or versioned copies:

Merging histories

By default, importing a node or edge that already exists raises an error. Set merge=True to combine the histories instead, preserving all temporal data from both sources:

Function reference

Node functions

FunctionDescription
import_node()Import a single Node
import_nodes()Import multiple nodes from a list or Nodes iterable
import_node_as()Import a Node with a new ID
import_nodes_as()Import multiple nodes with new IDs

Edge functions

FunctionDescription
import_edge()Import a single Edge
import_edges()Import multiple edges from a list or Edges iterable
import_edge_as()Import an Edge with new source/destination IDs
import_edges_as()Import multiple edges with new IDs