Python output to mgmt queries


dimi
 
Edited

Hi! I am trying to parse some basic info from the schema via Python but I am probably doing something wrong. 

I can request the management info with the Client object in python:

from gremlin_python.driver.client import Client
client = Client('ws://localhost:8182/gremlin', 'mygraph')
mgmt = "mygraph.openManagement()"
get_v_labels = mgmt + ".getVertexLabels()"
tt = client.submit(get_v_labels).all().result()

I have 16 labels, and if I run it in the gremlin console I obtain a list of labels. In python, instead, 
I get
[v[74253], v[74765], v[75277], v[75789], v[76301], v[76813], v[77325], v[77837], v[78349], v[78861], v[79373], v[79885], v[80397], v[80909], v[81421], v[81933]]

If I do
for t in tt:
    for p in g.V(t.id).properties():
         print("key:",p.label, "| value: " ,p.value)
I do not get any output. How can I get the list of labels from the schema?


hadoopmarc@...
 

I am not sure what you are up to and the API changes in remote connections may have confused you.

If you want to see the labels of all vertices in the graph (for janusgraph-0.6.x with gremlin_python-3.5.1):
from gremlin_python.process.anonymous_traversal import traversal
g = traversal().withRemote(DriverRemoteConnection('ws://localhost:8182/gremlin','g'))
g.V().label().toList
If you want to see the vertex labels that you defined in the JanusgGraph schema:
from gremlin_python.driver.client import Client
client = Client('ws://localhost:8182/gremlin', 'graph')
for line in client.submit("graph.openManagement().printSchema()").next():
    print(line)
Best wishes,    Marc




dimi
 

Hi Marc, 
Thank you for your reply. I would like to access this information only from the schema (my graph is empty now). Your second solution could work but it only prints the result. So to get the labels, I would need to extract them with some regex. 
However, I think I have found a solution.
It seems that python converts the object org.janusgraph.graphdb.types.VertexLabelVertex to gremlin_python.structure.graph.Vertex. I do not know if this is wanted or accidental  (for janusgraph-0.6.x with gremlin_python-3.5.1).
However, I can get a list of labels if I convert the labels to string before requesting the result to Python. 
For example
from gremlin_python.driver.client import Client
client = Client('ws://localhost:8182/gremlin', 'mygraph')
mgmt = "mygraph.openManagement()"
get_v_labels = mgmt + ".getVertexLabels().collect {a -> a.name()}"
client.submit(get_v_labels).all().result()

In this way, I can also get properties etc.

Thanks again and best wishes, 
Dimi