Passing Vertex as parameters in session.execute_graph()

16 views
Skip to first unread message

Jérôme Fuselier

unread,
Apr 20, 2017, 8:57:07 AM4/20/17
to DataStax Python Driver for Apache Cassandra User Mailing List
Hello,

I'm trying to use the DSE Graph API to interact with the Graph store but I find it quite challenging to understand the syntax of the Graph API using Gremlin statements from a Python script.

This works correctly:

res = session.execute_graph('''A = g.addV(label, 'A')[0]
                                            B = g.addV(label, 'B')[0]
                                            A.addEdge('edge', B)''')


But it's not very "Pythonic", if I want to create more complex queries I will end up working on building on the fly strings which is error-prone.

I'm trying to do something like that but it fails:

A = session.execute_graph('''g.addV(label, 'A')''')[0]
B = session.execute_graph('''g.addV(label, 'B')''')[0]
res = session.execute_graph('''A.addEdge('edge', B)''', {'A': A, 'B': B})

-> TypeError: Vertex({u'community_id': 516547968, u'~label': u'A', u'member_id': 512}, u'A', u'vertex', {}) is not JSON serializable


I don't know if that's a problem with the API or a problem with my vision on the usage of the API.

Thanks
Jerome

Alan Boudreault

unread,
Apr 20, 2017, 9:55:50 AM4/20/17
to python-dr...@lists.datastax.com
Hello Jérome,

It seems that what you are looking for is the dse-graph package, which executes graph queries in a more Pythonic way using a Fluent API (with TinkerPop Gremlin).


Regards,
Alan

--
You received this message because you are subscribed to the Google Groups "DataStax Python Driver for Apache Cassandra User Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python-driver-user+unsub...@lists.datastax.com.



--

Alan Boudreault
Software Engineer (Drivers) | alan.bo...@datastax.com


Jérôme Fuselier

unread,
Apr 20, 2017, 5:06:35 PM4/20/17
to DataStax Python Driver for Apache Cassandra User Mailing List
Hi Alan,

Thanks for the information. I was a bit lost with what the different API provide. I will investigate the dse-graph package but the documentation seems pretty short. Can I find real world example somewhere ?

Best
Jerome

Alan Boudreault

unread,
Apr 21, 2017, 8:29:42 AM4/21/17
to python-dr...@lists.datastax.com
Indeed, the dse-graph is only a connector to execute gremlin requests on a dse cluster. Here are some more complete graph documentation:


Alan

--
You received this message because you are subscribed to the Google Groups "DataStax Python Driver for Apache Cassandra User Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python-driver-user+unsub...@lists.datastax.com.
Reply all
Reply to author
Forward
0 new messages