如何使用 Python 连接到 AWS Neptune(图形数据库)?

How to connect to AWS Neptune (graph database) with Python?

我正在学习本教程:

https://docs.aws.amazon.com/neptune/latest/userguide/access-graph-gremlin-python.html

如何添加节点然后检索相同的节点?[​​=13=]

from __future__  import print_function  # Python 2/3 compatibility

from gremlin_python import statics
from gremlin_python.structure.graph import Graph
from gremlin_python.process.graph_traversal import __
from gremlin_python.process.strategies import *
from gremlin_python.driver.driver_remote_connection import DriverRemoteConnection

graph = Graph()

remoteConn = DriverRemoteConnection('wss://your-neptune-endpoint:8182/gremlin','g')
g = graph.traversal().withRemote(remoteConn)

print(g.V().limit(2).toList())
remoteConn.close()

以上所有现在正在做的是检索 2 个节点吗?

如果你想添加一个顶点,然后 return 关于顶点的信息(假设你没有提供自己的 ID),你可以这样做

newId = g.addV("mylabel").id().next()