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:
bin/gremlin-server.sh -i org.apache.tinkerpop gremlin-python 3.2.3
Next modify the conf/gremlin-server/gremlin-server.yaml
to add the gremlin-python
script engine:
scriptEngines: {
gremlin-groovy: {
imports: [java.lang.Math],
staticImports: [java.lang.Math.PI],
scripts: [scripts/empty-sample.groovy]},
gremlin-jython: {},
gremlin-python: {}
}
To use Gremlin Python, you need to go through a Gremlin Server, so start the JanusGraph pre-packaged distribution:
bin/janusgraph.sh start
From the Gremlin Console:
gremlin> graph = JanusGraphFactory.open('conf/janusgraph-cassandra-es.properties')
==>standardjanusgraph[cassandrathrift:[127.0.0.1]]
gremlin> GraphOfTheGodsFactory.load(graph)
==>null
gremlin> g = graph.traversal()
==>graphtraversalsource[standardjanusgraph[cassandrathrift:[127.0.0.1]], standard]
gremlin> g.V().count()
14:51:58 WARN org.janusgraph.graphdb.transaction.StandardJanusGraphTx - Query requires iterating over all vertices [()]. For better performance, use indexes
==>12
Install the Gremlin-Python driver, again matching on the TinkerPop version:
pip install gremlinpython==3.2.3
From the Python 3 shell:
>>> from gremlin_python import statics
>>> from gremlin_python.structure.graph import Graph
>>> from gremlin_python.process.graph_traversal import __
>>> from gremlin_python.process.strategies import *
>>> from gremlin_python.driver.driver_remote_connection import DriverRemoteConnection
>>> graph = Graph()
>>> g = graph.traversal().withRemote(DriverRemoteConnection('ws://localhost:8182/gremlin','g'))
>>> print(graph)
graph[empty]
>>> print(g)
graphtraversalsource[graph[empty]]
>>> g.V().count().next()
12
>>> g.addV('god').property('name', 'mars').property('age', 3500).next()
v[4280]
>>> g.V().count().next()
13
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()
or next()
or toList()
.
bin/janusgraph.sh start
Its able to connect to cassandra & es, but timeout on gremlin-server. I went though logs but there was no stacktrace to point out what exactly was error, just that I'm getting time out. I increased the wait time from default 60 to 120 but still same issue. Is that expected? Thanks – Spokeswoman