I am trying to use Python on an Amazon EC2 instance, in the same VPC as an Amazon Neptune instance, to add a vertex (node) to Neptune. Using the example code for Amazon Neptune, I constructed the following code sample to add a vertex (node) and then print out all vertices in the graph.
from gremlin_python import statics
from gremlin_python.process.anonymous_traversal import traversal
from gremlin_python.driver.driver_remote_connection import DriverRemoteConnection
from gremlin_python.structure.graph import Graph
from pprint import pprint
target = 'zzzzzz-instance-1.zzzzzzzz.us-west-2.neptune.amazonaws.com'
port = '8182'
g = Graph()
remote = DriverRemoteConnection(f'wss://{target}:{port}/gremlin', 'g')
conn = g.traversal().withRemote(remote)
conn.addV('person').property(id, 5).property('firstname', 'Trevor')
print(conn.V().toList())
The invocation to conn.addV()
silently fails, and the following line with the print()
statement returns an empty Python list.
conn.addV()
throws an exception, or ...conn.addV()
succeeds, and the print()
line returns the vertexQuestion: How do I use the Gremlin module for Python to add a vertex to the graph, in Amazon Neptune?
Your addV() query needs a Terminal Step such as next() or iterate(). Otherwise, you get the bytecode representation of the query returned. http://www.kelvinlawrence.net/book/PracticalGremlin.html#var