Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Amazon Neptune: How to create custom vertex id in Python using tinkerpop/gremlinpython package?

As outlined here https://docs.aws.amazon.com/neptune/latest/userguide/access-graph-gremlin-differences.html custom vertex ids can only be set with the unquoted id property, i.e., g.addV('label1').property(id, 'customid'). How can one accomplish this using the gremlinpython package? I see an id function in gremlin_python.process.graph_traversal, but I get an UnsupportedOperationException (as expected) when attempting to use that.

like image 547
JTW Avatar asked Oct 18 '25 17:10

JTW


1 Answers

You should just have to import T which is the class that hold the id and label members:

from gremlin_python.process.traversal import T

then use it as:

g.addV('label1').property(T.id, 'customid').iterate()

You can of course choose to import id from T so as to make the syntax synonymous with the example Gremlin in your question such that you may omit the T - some folks prefer that style.

It may be worth looking at the reference documentation for other common imports that Gremlin uses.

like image 189
stephen mallette Avatar answered Oct 21 '25 19:10

stephen mallette