Skip to content

Commit afff092

Browse files
committed
Script to bootstrap the Python console ready to talk to a Gremlin Server #138
1 parent c09ac8e commit afff092

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

sample-code/bootstrap-console.py

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Configure the environment so the Python Console can connect to
2+
# a Gremlin Server using gremlin-python and a web socket connection.
3+
#
4+
# To use this script start Python using:
5+
# python3 -i bootstrap-console.py
6+
7+
from gremlin_python import statics
8+
from gremlin_python.structure.graph import Graph
9+
from gremlin_python.process.graph_traversal import __
10+
from gremlin_python.process.strategies import *
11+
from gremlin_python.driver.driver_remote_connection import DriverRemoteConnection
12+
from gremlin_python.process.traversal import *
13+
import os
14+
15+
# This script assumes that two environment variables have been defined
16+
# containing the DNS name of the Gremlin Server and the port it is listening on.
17+
# If the environment variables are not found, defaults will be used.
18+
skey = "GREMLIN_SERVER_NAME"
19+
pkey = "GREMLIN_SERVER_PORT"
20+
21+
server = os.environ[skey] if skey in os.environ else 'localhost'
22+
port = os.environ[pkey] if pkey in os.environ else '8182'
23+
24+
endpoint = 'ws://' + server + ':' + port + '/gremlin'
25+
print(endpoint)
26+
27+
graph=Graph()
28+
connection = DriverRemoteConnection(endpoint,'g')
29+
g = graph.traversal().withRemote(connection)

0 commit comments

Comments
 (0)