5

I have created a long Gremlin chained command as a string. What is the best way to execute it in NodeJS or Python?

g.addV("person").
  property(id, 1).
  property("name", "marko").
  property("age", 29).as("1").
  addV("person").
  property(id, 2).
  property("name", "vadas").
  property("age", 27).as("2").
  addV("software").
  property(id, 3).
  property("name", "lop").
  property("lang", "java").as("3").
  addV("person").
  property(id, 4).
  property("name", "josh").
  property("age", 32).as("4").
  addV("software").
  property(id, 5).
  property("name", "ripple").
  property("lang", "java").as("5").
  addV("person").
  property(id, 6).
  property("name", "peter").
  property("age", 35).as("6").
  addE("created").from("1").to("3").
  property(id, 9).
  property("weight", 0.4).
  addE("knows").from("1").to("2").
  property(id, 7).
  property("weight", 0.5).
  addE("knows").from("1").to("4").
  property(id, 8).
  property("weight", 1.0).
  addE("created").from("3").to("4").
  property(id, 11).
  property("weight", 0.4).
  addE("created").from("3").to("6").
  property(id, 12).
  property("weight", 0.2).
  addE("created").from("4").to("5").
  property(id, 10).
  property("weight", 1.0)

The command given above was executed on the Gremlin console and was successful, but I need to know how to achieve this in program of node or Python using TinkerPop drive.

Kelvin Lawrence
  • 14,674
  • 2
  • 16
  • 38

3 Answers3

3

Start with Gremlin Language Variants (GLV) and then head over to Gremlin-python.

The docs should be good enough for you to solve this yourself.

http://tinkerpop.apache.org/docs/current/tutorials/gremlin-language-variants/#using-python-and-gremlin-server

The-Big-K
  • 2,672
  • 16
  • 35
1
from gremlin_python.driver import client

client = client.Client('ws://localhost:8182/gremlin', 'g')

client.submit("your query")
Kelvin Lawrence
  • 14,674
  • 2
  • 16
  • 38
Ranjit Soni
  • 594
  • 6
  • 19
  • Hi, I am trying this code to execute the query from the lambda function and from my local as well machine, but getting a timeout error. instead of it, if using DriveRemoteConnection of gremlin_python, it working fine, but using this was, not getting the solution to execute dynamic query string. Thanks – Ranjit Soni Feb 01 '22 at 13:39
0

I found a workaround to use with any Gremlin driver, I used Python and used client.submit("you query"). And it worked.

Kelvin Lawrence
  • 14,674
  • 2
  • 16
  • 38