troy aikman
troy aikman

Reputation: 3

py2neo, create a node ? two ways?

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

Upvotes: 0

Views: 2246

Answers (2)

guywiz
guywiz

Reputation: 31

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 ...).

Upvotes: 3

Nigel Small
Nigel Small

Reputation: 4495

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.

Upvotes: 0

Related Questions