0

I am confused as what is the difference between below two ways to create a node ? It seems like the result is the same;

from py2neo import Graph
graph = Graph()

graph.cypher.execute("CREATE (a:Person {name:{N}})", {"N": "Alice"})  # a
graph.create( Node("Person",name="Alice"))  # b
Remi Guan
  • 21,506
  • 17
  • 64
  • 87

2 Answers2

3

Looking at the py2neo v3 documentation, it seems there's yet a third way to create a node.

First instantiate a Node object, as in

a = Node("Person",name="Alice")

then insert it in a subgraph (see py2neo types),

sg = Subgraph(a)

then create elements of this subgraph (Graph.create method):

graph.create(sg)

I understand that subgraph creation should however be preferred when creating numerous nodes and edges (a subgraph ...).

guywiz
  • 31
  • 4
0

You're right, the result is exactly the same. Py2neo exposes two levels of API: a pure Cypher API (execute) and a simpler object-based API (Node). The latter is generally easier to get up and running with, the former is more comprehensive.

Nigel Small
  • 4,475
  • 1
  • 17
  • 15