I am aware of the graph-notebook project that allows Gremlin queries to be submitted using magic commands. However, sometimes I need to code in Python and connect to the server using code, from within a regular Jupyter notebook cell. If, using the Gremlin Python 3.5.2 client I try to do something like this:
server = '<your server endpoint goes here>'
port = 8182
endpoint = f'wss://{server}:{port}/gremlin'
connection = DriverRemoteConnection(endpoint,'g')
g = traversal().withRemote(connection)
an error is thrown because the Jupyter event loop is already running.
Is there a way around this?
There is an additional parameter that can be specified while creating the Remote Connection that tells the Python Client to nest the event loops. You just need to create the connection along these lines:
The key difference is that a custom
transport_factory
is provided that is actually just alambda
wrapper around the regularAiohttpTransport
, with thecall_from_event_loop
parameter set toTrue
.This extra configuration tells the Gremlin Python client to apply the appropriate internal changes to nest the event loops.