/
basic-client.py
38 lines (30 loc) · 1.05 KB
/
basic-client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# basic-client.py
#
# Connect to a Gremlin Server using a client connection.
#
# Note that in this case the Gremlin queries are sent to the server as text strings.
# To see an example of using Gremlin byte code instead see the glv-client.py example.
#
# This example code assumes that the GremlinPython library has been installed using:
#
# pip install gremlinpython
#
# Import some classes we will need to talk to our graph
from gremlin_python.driver import client
# Path to our graph (this assumes a locally running Gremlin Server)
# Note how the path is a Web Socket (ws) connection.
client = client.Client('ws://localhost:8182/gremlin','g')
query = """
g.V().hasLabel('airport').
sample(30).
order().by('code').
local(__.values('code','city').fold()).
toList()
"""
result = client.submit(query)
future_results = result.all()
results = future_results.result()
client.close()
# Print the results in a tabular form with a row index
for i,c in enumerate(results,1):
print("%3d %4s %s" % (i,c[0],c[1]))