I've started playing around with gremlin-python wrapper to interact with my gremlin server.
I did the following steps:
./bin/gremlin.sh
Once the Gremlin console opens up, I loaded configurations using:
graph = JanusGraphFactory.open('conf/gremlin-server/janusgraph-cassandra-es.properties')
g = graph.traversal()
saturn = g.V().has('name', 'saturn')
And the above set of codes in gremlin shell works fine, and I can see verteces listed down, but when I try to do same in python I get an empty graph. The following is my code for python:
graph = Graph()
g = graph.traversal().withRemote(DriverRemoteConnection('ws://localhost:8182/gremlin','g'))
print(g)
It returns : graphtraversalsource[graph[empty]]
Why am I getting empty graph? As far as I feel, it is unable to connect to same Graph source. Is there somthing I'm missing?
Note that in:
JanusGraphFactory.open('conf/gremlin-server/janusgraph-cassandra-es.properties')
the config filename provided is one used to start gremlin server.
Any help is really appreciated.
Thanks
The reason you are seeing graph[empty] is because that's the actual string representation of the Python graph object -- see the code here. The graph may actually contain data though, so it would be better if it was something like graph[remote] or graph[] instead. I've opened up an issue to address this.
Out of the box, JanusGraph isn't configured for Python. You can find docs on how do this in the Apache TinkerPop docs. First install
gremlin-python
. Here's the command assuming you're using JanusGraph 0.1.1 which uses TinkerPop 3.2.3:Next modify the
conf/gremlin-server/gremlin-server.yaml
to add thegremlin-python
script engine:To use Gremlin Python, you need to go through a Gremlin Server, so start the JanusGraph pre-packaged distribution:
From the Gremlin Console:
Install the Gremlin-Python driver, again matching on the TinkerPop version:
From the Python 3 shell:
Keep in mind when you are working in the Python shell, the graph traversals are not automatically iterated, so you need to make sure to iterate the traversal with
iterate()
ornext()
ortoList()
.Your local "g" in the Gremlin Console is an embedded instance of a graph. It therefore "contains" something and is not empty. For your "g" in Python, it is "empty" in the sense that on its own there are no vertices/edges that within it - the vertices/edges are in the remote graph on Gremlin Server that it reflects. I assume that if you were to do a
g.V().count()
in python you would get the same vertex count back as you would if you did the same in java. If not, then there is some other problem, but do not expect a "remote" graph instance to show vertex/edges of any sort (unless a day comes where gremlin-python is written as a Gremlin virtual machine that has it's own Python native graph databases attached to it - in such a case, "g" would be embedded and thus own vertices/edges and would likely no longer print as "empty").