python 操作gremlin
生活随笔
收集整理的這篇文章主要介紹了
python 操作gremlin
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
安裝 我這用的是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())以后慢慢補
總結
以上是生活随笔為你收集整理的python 操作gremlin的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 智慧零售数据可视化分析_零售行业大数据分
- 下一篇: 搭建Metasploitable靶机