安装 我这用的是python3 ,但是python2跟这个差不多 我都试了
pip3 install gremlinpython
下面两种连接方式,看想用那种了,性能什么的都没测试
1.python代码请求
graph = Graph()
g = graph.traversal().withRemote(DriverRemoteConnection('ws://hosts:port/gremlin','g'))
g.addV('god').property('name', 'yuxj').property('age', 111).next()
a=g.V().has('name','yuxj').valueMap().toList()
print (a)
hosts:ip地址 port 端口号
2.提交sql
from gremlin_python.driver import client
client = client.Client('ws://192.168.1.15:8182/gremlin','g')
###
#sql添加边界得label
###
gsql="mgmt = graph.openManagement()\n"\
"create = mgmt.makeEdgeLabel('create').multiplicity(MULTI).make()\n" \
"mgmt.commit()\n"
client.submit(gsql)
sql就是gremlin的sql
3.自己用过的语句
###
#sql 查询添加的数据-id
###
# a=g.V().has("company_n","上海美都管理咨询有限公司第一分公司").valueMap().toList()
#g.V().has("company_n","上海美都管理咨询有限公司第一分公司").valueMap(True).toList()#查询所有数据
#g.V().has("company_n","上海美都管理咨询有限公司第一分公司").id()
# print(a)
###
#获取所有点的id list
###
# bs=g.V().toList()
# print(bs)
###
#遍历所有数据
###
# for b in bs:
# print(g.V(b).valueMap().toList())
# q=g.V(b).values('company_n').toList()
# if q:
# print (q)
# else:
# q = g.V(b).values('name').toList()
# print(q)
# c=g.V().has('name','yuxj9').valueMap().toList()
# print(c)
# d=g.V().hasLabel("1").count().toList()
# print (d)
# client.close()
###
#sql 添加边界
###
#esql="g.V().has('name','marko').as('m').V().has('name','lop').as('l').addE('create').from('m')"
#client.submit(esql)
###
#where 查看label 为company 和representative得数据
###
# A=g.V().where(hasLabel('company').or_().hasLabel('representative')).valueMap(True).toList()
# print (A)
#g.V().has('chair_id', within('%s')).as_('A').V().has('repren_id', within('%s')).addE('法人').from_('A');
# from gremlin_python.process.traversal import T
# from gremlin_python.process.traversal import Order
# from gremlin_python.process.traversal import Cardinality
# from gremlin_python.process.traversal import Column
# from gremlin_python.process.traversal import Direction
# from gremlin_python.process.traversal import Operator
# from gremlin_python.process.traversal import P
# from gremlin_python.process.traversal import Pop
# from gremlin_python.process.traversal import Scope
# from gremlin_python.process.traversal import Barrier
# a=g.V().has("company_n",P.textContent("分公司")).valueMap()
# print (a)
####
####
##查看边界和个数
####
#g.E().group().by(label).by(count())
以后慢慢补