Gremlin API for Python 2.7?

475 views
Skip to first unread message

Rich Burdon

unread,
May 29, 2016, 4:10:44 PM5/29/16
to Gremlin-users

Is there an official/stable/widely used API for python 2.7.


The docs (http://tinkerpop.apache.org) list a handful of mostly abandoned python implementation.


gremlinrestclient seems to be just a simple HTTP wrapper, with yet-another custom (non-standard) API.


The official docs (http://tinkerpop.apache.org/docs/3.2.1-SNAPSHOT/tutorials/gremlin-language-variants) suggest generating a python API, but the script under the "Using Python and GremlinServer" section generates an error:


javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: GraphTraversalSource for class: Script1


Seems quite odd to include a complicated -- easy to be out of date -- script in docs?; rather than, say, a source file with tests?


Marko Rodriguez

unread,
May 29, 2016, 5:47:18 PM5/29/16
to gremli...@googlegroups.com
Hello,

The official docs (http://tinkerpop.apache.org/docs/3.2.1-SNAPSHOT/tutorials/gremlin-language-variants) suggest generating a python API, but the script under the "Using Python and GremlinServer" section generates an error:

javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: GraphTraversalSource for class: Script1

Seems quite odd to include a complicated -- easy to be out of date -- script in docs?; rather than, say, a source file with tests?

Be sure to import all the libraries as discussed in the tutorial. Also, in the tutorial the source python files are provided as well -- read carefully and click the HREF.

Marko.

Rich Burdon

unread,
May 30, 2016, 2:49:15 PM5/30/16
to Gremlin-users
Marko, thanks for the response.

1). Just to be clear, I'm referring to the Groovy source starting with:

pythonClass = new StringBuilder() pythonClass.append("from tornado import gen\n") pythonClass.append("from tornado.ioloop import IOLoop\n") pythonClass.append("from gremlinclient.tornado_client import submit\n")

What do you mean "import" other than what is in the code above? I.e., copying the entire source block into a file and submitting this to the Gremlin console causes the error above.

2). The generated python code (in the tutorial), linked here: http://tinkerpop.apache.org/docs/3.2.1-SNAPSHOT/resources/gremlin-python.py

has errors; e.g., this following line fails:

      return self.range(indices,indices+1)

trivial to fix (I assume "indeces" == "index", but has this been tested? Is it used by anyone?

3). gremlin-python.py isn't a valid python filename (for the sake of imports). This is trivial to fix, but again, makes me think it hasn't been tested.

4). Why put source code in the tutorial's text (i.e., if it's useful/intended to be used, why not put it in the the source distribution, or upload to PyPl?); perhaps I missed this? As I mentioned, the python libs listed here (http://tinkerpop.apache.org/docs/3.2.1-SNAPSHOT/tutorials/gremlin-language-variants) don't seem to have much traction. Would it be useful for me to create another python lib and have this listed?

Again, thanks very much for your help.

RB

David Brown

unread,
May 30, 2016, 3:12:36 PM5/30/16
to Gremlin-users
The gremlinclient library is stable and maintained, works on Python 2.7 + and let's you choose between a Tornado/aiohttp client. But it is just a driver that allows you to submit a Gremlin script, not a Gremlin Language Variant. 

Stephen Mallette

unread,
May 31, 2016, 7:12:33 AM5/31/16
to Gremlin-users
> mostly abandoned python implementation.

We try to keep that provider listing well curated that generally complies with:


Note that lack of activity doesn't necessarily mean that a project is no longer maintained. This is especially true of the driver implementations as Gremlin Server's protocol doesn't change from release to release, so once it's built, there really is no need for additional code.



--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/1b5ee3fd-d34c-482d-b1ef-32339ed3d879%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Marko Rodriguez

unread,
May 31, 2016, 10:19:02 AM5/31/16
to gremli...@googlegroups.com
Hello,

1). Just to be clear, I'm referring to the Groovy source starting with:
What do you mean "import" other than what is in the code above? I.e., copying the entire source block into a file and submitting this to the Gremlin console causes the error above.

Huh. What version of Gremlin are you running? I just copy pasted that code into 3.2.1-SNAPSHOT (where the tutorial is for) and there were no issues.

/tmp$ more gremlin-python.py
from tornado import gen
from tornado.ioloop import IOLoop
from gremlinclient.tornado_client import submit

class Helper(object):
  @staticmethod
  def stringOrObject(arg):
    if (type(arg) is str and
       not(arg.startswith("P.")) and
       not(arg.startswith("Order.")) and
       not(arg.startswith("T.")) and
       not(arg.startswith("Pop.")) and
...


2). The generated python code (in the tutorial), linked here: http://tinkerpop.apache.org/docs/3.2.1-SNAPSHOT/resources/gremlin-python.py

has errors; e.g., this following line fails:

      return self.range(indices,indices+1)

trivial to fix (I assume "indeces" == "index", but has this been tested? Is it used by anyone?

Huh. Again, I don't get an issue.

/tmp$ python
Python 2.7.2 (default, Oct 11 2012, 20:14:37)
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> execfile("/tmp/gremlin-python.py")
>>> g = PythonGraphTraversalSource("ws://localhost:8182/", "g")
>>> g.V().range(0,1)
g.V().range(0, 1)
>>> g.V().limit(2)
g.V().limit(2)
>>>

3). gremlin-python.py isn't a valid python filename (for the sake of imports). This is trivial to fix, but again, makes me think it hasn't been tested.

So this is the thing. With 3.2.1-SNAPSHOT (latest and greatest), we introduced the concept of Gremlin Language Variants. This is all very new. The tutorial is to help explain how to use reflection to "easily" build a language variant in any programming language. This is NOT tested and is NOT part of the distribution. There are lots of notes throughout the tutorial saying where my "slap dap" (express succinctly in a short tutorial) Gremlin-Python is awkward and should be made better. 

With that, we REALLY want to have at least 3 Gremlin language variants distributed with TinkerPop and tested against our process test suite. We are thinking:

Gremlin-Python
Gremlin-Ruby
Gremlin-PHP

I have not gotten around to figuring out a way to write a single "provider" by which any developed language variant can easily connect to our test suite. I DO NOT want to have a test suite for each and every variant as that will be a major overdose of code and will dissuade us from adding more languages moving forward.

In short, once we DO have a good test infrastructure for language variants, we will then release with a REAL Gremlin-Python and not just a "tutorial example." 

Make sense?

4). Why put source code in the tutorial's text (i.e., if it's useful/intended to be used, why not put it in the the source distribution, or upload to PyPl?); perhaps I missed this? As I mentioned, the python libs listed here (http://tinkerpop.apache.org/docs/3.2.1-SNAPSHOT/tutorials/gremlin-language-variants) don't seem to have much traction. Would it be useful for me to create another python lib and have this listed?

Yes -- we should really have Gremlin-Python distributed with TinkerPop. If you are interested in helping with this, we should collaborate. You being the Python expert and me being the guy who knows how to integrate everything into our test suite.

Again, thanks very much for your help.

Thank you Rich. Apologies if I got your hopes up on Twitter with "just use Gremlin-Python." Its a "tutorial for developing a variant," NOT "the official Python language variant." :(

Take care,
Marko.







On Sunday, May 29, 2016 at 5:47:18 PM UTC-4, Marko A. Rodriguez wrote:
Hello,

The official docs (http://tinkerpop.apache.org/docs/3.2.1-SNAPSHOT/tutorials/gremlin-language-variants) suggest generating a python API, but the script under the "Using Python and GremlinServer" section generates an error:

javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: GraphTraversalSource for class: Script1

Seems quite odd to include a complicated -- easy to be out of date -- script in docs?; rather than, say, a source file with tests?

Be sure to import all the libraries as discussed in the tutorial. Also, in the tutorial the source python files are provided as well -- read carefully and click the HREF.

Marko.


--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-user...@googlegroups.com.

Marko Rodriguez

unread,
May 31, 2016, 11:20:26 AM5/31/16
to gremli...@googlegroups.com
Hi,

has errors; e.g., this following line fails:

      return self.range(indices,indices+1)

trivial to fix (I assume "indeces" == "index", but has this been tested? Is it used by anyone?

Huh. Again, I don't get an issue.

Ah, I see what you mean. Fixed in the tutorial.

Thanks,
Marko.

Rich Burdon

unread,
May 31, 2016, 4:29:40 PM5/31/16
to Gremlin-users
Thanks Marco -- inline below:


Huh. What version of Gremlin are you running? I just copy pasted that code into 3.2.1-SNAPSHOT (where the tutorial is for) and there were no issues.


1). Here, I'm talking about the Groovy script you have in your tutorial (handy to have #links inside the doc?) starting with "pythonClass = new StringBuilder()". I've never used Groovy before so this is likely user error, but when I copy this script into, say "gen.groovy" then run "groovy gen.groovy" I get:

Caught: groovy.lang.MissingPropertyException: No such property: GraphTraversalSource for class: gen

groovy.lang.MissingPropertyException: No such property: GraphTraversalSource for class: gen

at gen.run(gen.groovy:43)

 
I can guess that GraphTraversalSource is part of the Java library for Gremlin, but no instructions here. Should this be on the classpath? Do I need to run Groovy from some special environment? Also -- why not put this script in github somewhere? Couldn't it change in the future? Is it useful to anyone?

2). Re gremlin-python.py I see your second respose but:
a) Again, why not put this in github if it's useful (same as above). Or better in PyPl.
b) Hyphenated files are legit in python -- fine for a standalone script but not for module imports.

3). gremlin-python.py isn't a valid python filename (for the sake of imports). This is trivial to fix, but again, makes me think it hasn't been tested.

So this is the thing. With 3.2.1-SNAPSHOT (latest and greatest), we introduced the concept of Gremlin Language Variants. This is all very new. The tutorial is to help explain how to use reflection to "easily" build a language variant in any programming language. This is NOT tested and is NOT part of the distribution. There are lots of notes throughout the tutorial saying where my "slap dap" (express succinctly in a short tutorial) Gremlin-Python is awkward and should be made better. 

With that, we REALLY want to have at least 3 Gremlin language variants distributed with TinkerPop and tested against our process test suite. We are thinking:

Gremlin-Python
Gremlin-Ruby
Gremlin-PHP

I have not gotten around to figuring out a way to write a single "provider" by which any developed language variant can easily connect to our test suite. I DO NOT want to have a test suite for each and every variant as that will be a major overdose of code and will dissuade us from adding more languages moving forward.

Got it -- but isn't this perfect validation for my point above -- i.e., check-in the (Groovy - literally :) tool for generating the python variant?
 
In short, once we DO have a good test infrastructure for language variants, we will then release with a REAL Gremlin-Python and not just a "tutorial example." 

Testing should be mitigated (less important) if it's generated, no? In any case if you have a standard gremlin test suite then knocking up a few nose tests, would be rather trivial (happy to help if this is useful).

Make sense?

Your goals -- absolutely, help me understand my objections above -- and LMK if I can help.

4). Why put source code in the tutorial's text (i.e., if it's useful/intended to be used, why not put it in the the source distribution, or upload to PyPl?); perhaps I missed this? As I mentioned, the python libs listed here (http://tinkerpop.apache.org/docs/3.2.1-SNAPSHOT/tutorials/gremlin-language-variants) don't seem to have much traction. Would it be useful for me to create another python lib and have this listed?
Yes -- we should really have Gremlin-Python distributed with TinkerPop. If you are interested in helping with this, we should collaborate. You being the Python expert and me being the guy who knows how to integrate everything into our test suite.

Happy to (help me get the Groovy working and I'll take the rest). Don't be so quick to use words like expert :).

Again, thanks very much for your help.
Thank you Rich. Apologies if I got your hopes up on Twitter with "just use Gremlin-Python." Its a "tutorial for developing a variant," NOT "the official Python language variant." :(

:)

Is there a gremlin-python user group you're aware of? Any idea of how many people are using TinkerPop in Python?

Stephen Mallette

unread,
May 31, 2016, 4:36:29 PM5/31/16
to Gremlin-users
>Any idea of how many people are using TinkerPop in Python?

given what i've seen in mailing list activity over the years, i'd guess that it's the most used language after java/groovy. 

Marko Rodriguez

unread,
May 31, 2016, 6:30:02 PM5/31/16
to gremli...@googlegroups.com
Hi,

1). Here, I'm talking about the Groovy script you have in your tutorial (handy to have #links inside the doc?) starting with "pythonClass = new StringBuilder()". I've never used Groovy before so this is likely user error, but when I copy this script into, say "gen.groovy" then run "groovy gen.groovy" I get:

Ah, you should run the script from the Gremlin Console as that has all the TinkerPop imports loaded.

Is there a gremlin-python user group you're aware of? Any idea of how many people are using TinkerPop in Python?

No. Just use gremlin-users@ mailing list.

I'm working on https://github.com/apache/incubator-tinkerpop/tree/TINKERPOP-1278 which is for the ticket https://issues.apache.org/jira/browse/TINKERPOP-1278. You can see what I've been up to…

Rich Burdon

unread,
May 31, 2016, 6:52:56 PM5/31/16
to Gremlin-users
Hi David,

Probably a stupid error on my part, but when I run your example against my Titan instance, I get:

tornado.httpclient.HTTPError: HTTP 400: Bad Request


I don't see anything useful on the client or server logs. Still working on it.

Rich

Rich Burdon

unread,
May 31, 2016, 8:04:38 PM5/31/16
to Gremlin-users
Thanks Marko, will try this -- but how to automate -- would be ideal to build from a build script rather than insert a human into the process?

Also, what's the best way to submit issues:
http://github.com/apache/incubator-tinkerpop has no public issues list.

E.g., google search still returns the old site? below:
https://github.com/tinkerpop/gremlin/wiki/Getting-Started

But this repo doesn't build any more.
I'm guessing the new (supported) stack is http://github.com/apache/incubator-tinkerpop?

Sorry for the barrage of questions. Still getting started.

Marko Rodriguez

unread,
May 31, 2016, 8:12:02 PM5/31/16
to gremli...@googlegroups.com
Hello,

Thanks Marko, will try this -- but how to automate -- would be ideal to build from a build script rather than insert a human into the process?

Automate what? Building the source? "mvn clean install -Dmaven.test.skip=true". See:

Also, what's the best way to submit issues:
http://github.com/apache/incubator-tinkerpop has no public issues list.


But this repo doesn't build any more.
I'm guessing the new (supported) stack is http://github.com/apache/incubator-tinkerpop?

TinkerPop2 was pre-Apache. Use TinkerPop3.

Sorry for the barrage of questions. Still getting started.

No problem. Good luck.

Marko.




On Tuesday, May 31, 2016 at 6:30:02 PM UTC-4, Marko A. Rodriguez wrote:
Hi,

1). Here, I'm talking about the Groovy script you have in your tutorial (handy to have #links inside the doc?) starting with "pythonClass = new StringBuilder()". I've never used Groovy before so this is likely user error, but when I copy this script into, say "gen.groovy" then run "groovy gen.groovy" I get:

Ah, you should run the script from the Gremlin Console as that has all the TinkerPop imports loaded.

Is there a gremlin-python user group you're aware of? Any idea of how many people are using TinkerPop in Python?

No. Just use gremlin-users@ mailing list.

I'm working on https://github.com/apache/incubator-tinkerpop/tree/TINKERPOP-1278 which is for the ticket https://issues.apache.org/jira/browse/TINKERPOP-1278. You can see what I've been up to…

Take care,
Marko.


--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-user...@googlegroups.com.

Rich Burdon

unread,
May 31, 2016, 8:26:48 PM5/31/16
to Gremlin-users
OK got it -- thanks:

a) the tests were failing (-Dmaven.test.skip=true" wasn't obvious)
b) I hadn't discovered -e to run scripts against the console.

Good now.

Rich Burdon

unread,
May 31, 2016, 8:48:06 PM5/31/16
to Gremlin-users

David Brown

unread,
May 31, 2016, 8:56:50 PM5/31/16
to Gremlin-users
Thanks Rich, I responded there, but I think you may be using the REST
interface config., whereas gremlinclient communicates with the server
via the WebSocket protocol.
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Gremlin-users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/gremlin-users/R9-lFCX_2G0/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> gremlin-user...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/gremlin-users/3aefeeac-58b3-4d42-9a2d-e28d84ca9e29%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.



--
David M. Brown
R.A. CulturePlex Lab, Western University

Rich Burdon

unread,
Jun 1, 2016, 6:18:08 PM6/1/16
to Gremlin-users
Marko,

I'm using the python API generated from my local Groovy script and it's working against Titan.

1). commit is missing so g.addV().tx().commit() doesn't work, which makes the API read-only? Is this as simple as adding the parsing of the Transaction.java class to the Groovy script -- or more involved?

2). I recommend, changing gremlin-python.py to gremlin_python.py in the docs and source (so that this can easily be used as a lib and not just imported into the console). Also recommend moving the groovy script into source.

3). Have asked Dave if gremlin-python.py (and the script) should live in a separate repo -- or be an optional add-on to the gremlinclient repo. Do you have thoughts about how you'd like the python variants to be exposed/developed?

Thanks.

RB

Mark Henderson

unread,
Jun 1, 2016, 6:36:35 PM6/1/16
to Gremlin-users
Another option is to use Gremlinpy(https://github.com/emehrkay/gremlinpy) to write the Gremlin/Groovy and send it to the server with Gremlinclient or Gremlinrestclient. Gremlinpy doesnt adhere to the interfaces defined in the the language variants doc, but it does allow you to easily bind params and build really complex queries easily. 

Let me know if you decided to look at it.

Marko Rodriguez

unread,
Jun 1, 2016, 6:47:43 PM6/1/16
to gremli...@googlegroups.com
Hi Rich,

I've been working on Gremlin-Python as a distribution with Apache TinkerPop all day today in TINKERPOP-1278/.

Here is how it works.

1. GremlinPythonGenerator.groovy generates the Python file.
2. The Gremlin-Python file.
3. To test, that is loaded into Jython (ScriptEngine) and then a mapper transforms the test suite traversals into Gremlin-Python traversals.
4. Here are the test cases that I can't get to work -- most are odd ball.

Thus, I know that the entire ProcessStandardSuite works with Gremlin-Python. What does Gremlin-Python do? Well, it currently juste generates a Gremlin-Groovy traversal to ultimately be submitted to GremlinServer.

>>> execfile("/Users/marko/software/tinkerpop/tinkerpop3/gremlin-variant/variants/python/gremlin-python-3.2.1-SNAPSHOT.py")
>>> g = PythonGraphTraversalSource("g")
>>> g.V()
g.V()
>>> g.V().out()
g.V().out()
>>> g.V().out()[0:1]
g.V().out().range(0, 1)
>>> g.V().out()[0:1].name
g.V().out().range(0, 1).values("name")
>>> type(g.V().out()[0:1].name)
<class '__main__.PythonGraphTraversal'>
>>> g.V().out()[0:1].repeat(__.out("knows")).times(10).name
g.V().out().range(0, 1).repeat(__.out("knows")).times(10).values("name")
>>> g.V().out()[0:1].repeat(__.out("knows")).times(10).name[2]
g.V().out().range(0, 1).repeat(__.out("knows")).times(10).values("name").range(2, 3)
>>> g.V().out()[0:1].repeat(__.out("knows")).times(10).name[2].groupCount().by("age")._as("a")
g.V().out().range(0, 1).repeat(__.out("knows")).times(10).values("name").range(2, 3).groupCount().by("age").as("a")

I don't know how to package stuff for Python, so any input would be most appreciated.

Stephen Mallette is going to work on a Python-based RemoteConnection interface so that different drivers can be plug-and-played into Gremlin-Python. Your input there would be appreciated as well.

Hope you like it!,
Marko.

Stephen Mallette

unread,
Jun 1, 2016, 7:42:02 PM6/1/16
to Gremlin-users
Hi Rich,

> 1). commit is missing so g.addV().tx().commit() doesn't work, which makes the API read-only? Is this as simple as adding the parsing of the Transaction.java class to the Groovy script -- or more involved?

When submitting a traversal to gremlin server, there are two options: 

a. the transaction is managed which means your request to have a traversal/script is executed represents the entirety of the transaction and is auto-committed/rolledback depending on the success/fail of the traversal/script. 
b. the transaction is not managed because you opened a "session" with your client and it is up to you to manage it yourself with your own calls to commit()/rollback(). we've not discussed what this means yet in the context of a GLV like gremlin-python.

> 2). I recommend, changing gremlin-python.py to gremlin_python.py in the docs and source (so that this can easily be used as a lib and not just imported into the console). Also recommend moving the groovy script into source.

i'd like to see this built more as a lib myself and deployed to pypi as part of our standard build/release. the trick is to do all this without creating tons of new overhead for ourselves. i'm gong to take a swipe at that soon.

> 3). Have asked Dave if gremlin-python.py (and the script) should live in a separate repo -- or be an optional add-on to the gremlinclient repo. Do you have thoughts about how you'd like the python variants to be exposed/developed?

TinkerPop's gremlin-python should not be an add-on to external drivers imo. We should figure out how to expose an "interface" for each GLV that is similar to what RemoteGraph and RemoteConnection do for Java:


Then a driver like David's would implement that "interface" so that users then just needed to choose a GLV and a driver that plugs into it so that when you use the GLV it transparently sends the traversal to Gremlin Server and gets back results. The user doesn't need to spend a lot of time with figuring out the intricacies of the driver as those will be disparate across implementations. They would only need that detail if they had to write some more low-level code, had some script that needed to be executed outside of a Traversal context, or had some complex transactional scenario that needed to be represented. While TinkerPop's gremlin-python shouldn't live with a driver, i don't see why driver libraries (or others) wouldn't consider extending upon the classes we provide in this regard. I'm not sure what that would mean at this point, as we are still early in this process and exploring, but I think that sounds like a possibility at some point.




Message has been deleted

Rich Burdon

unread,
Jun 2, 2016, 9:37:37 PM6/2/16
to Gremlin-users
Thanks very much Stephen

I think the toList() part was the final piece of the puzzle.

I appreciate the details also.

RB

Marko Rodriguez

unread,
Jun 3, 2016, 11:47:15 AM6/3/16
to gremli...@googlegroups.com
Hello Rich,

Note that what we are discussing here is all 3.2.1-SNAPSHOT. That is, we are currently developing Gremlin-Python for distribution with TinkerPop. Apologies if I led you to believe that all this "just worked." I thought you would be interested in tinkering along… Once this all gets merged to master/ and documented, then it will "just work."

Anywho, in TINKERPOP-1278, I got Gremlin-Python as such:

1. We are using modules now (thanks for the tip!).
* gremlin_driver is the abstract interface that driver developers should extend to provide an iterator of Traverser results to the respective language variant.
* gremlin_python is TinkerPop's Gremlin-Python language. Given that driver and language are decoupled, other people can create their own language variants (even other DSLs).
* gremlin_rest_driver is TinkerPop's simple driver implementation that uses GremlinServer's REST interface.
** it would be good if David Brown's Websockets-based gremlinclient/ implemented the abstract gremlin_driver interface.
** first it would be good if a Python expert helped to make that interface solid.

2. Together, we can now using TinkerPop's Gremlin-Python to talk to Gremlin Server. Watch:

FIRST: START UP GREMLIN SERVER

~/software/tinkerpop/tinkerpop3/gremlin-server/target/apache-gremlin-server-3.2.1-SNAPSHOT-standalone$ bin/gremlin-server.sh conf/gremlin-server-rest-modern.yaml
[INFO] GremlinServer -
         \,,,/
         (o o)
-----oOOo-(3)-oOOo-----

[INFO] GremlinServer - Configuring Gremlin Server from conf/gremlin-server-rest-modern.yaml
[INFO] GraphManager - Graph [graph] was successfully configured via [conf/tinkergraph-empty.properties].
[INFO] ScriptEngines - Loaded gremlin-groovy ScriptEngine
[INFO] GremlinExecutor - Initialized gremlin-groovy ScriptEngine with scripts/generate-modern.groovy
[INFO] ServerGremlinExecutor - A GraphTraversalSource is now bound to [g] with graphtraversalsource[tinkergraph[vertices:0 edges:0], standard]
[INFO] Logger$info - Loading 'modern' graph data.
[INFO] AbstractChannelizer - Configured application/vnd.gremlin-v1.0+json with org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV1d0
[INFO] AbstractChannelizer - Configured application/json with org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV1d0
[INFO] GremlinServer$1 - Channel started at port 8182.
SECOND: USE GREMLIN-PYTHON IN CPYTHON TO ISSUE GREMLIN TRAVERSALS
~$ python
Python 2.7.2 (default, Oct 11 2012, 20:14:37)
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>>
>>> import sys
>>> sys.path.append("/Users/marko/software/tinkerpop/tinkerpop3/gremlin-variant/src/main/jython/gremlin_python")
>>> sys.path.append("/Users/marko/software/tinkerpop/tinkerpop3/gremlin-variant/src/main/jython/gremlin_driver")
>>> sys.path.append("/Users/marko/software/tinkerpop/tinkerpop3/gremlin-variant/src/main/jython/gremlin_rest_driver")
>>>
>>> from gremlin_python import statics
>>> from gremlin_python import PythonGraphTraversal
>>> from gremlin_python import __
>>> from gremlin_rest_driver import RESTRemoteConnection
>>> # this allows us to do g.V().repeat(out()) instead of g.V().repeat(__.out())-type traversals
>>> for k in statics:
...   globals()[k] = statics[k]
...
>>> # create a remote connection (using REST) and pass it to PythonGraphTraversalSource
>>> conn = RESTRemoteConnection('http://localhost:8182','gremlin-groovy')
>>> g = PythonGraphTraversalSource("g",conn)
>>>
>>> # the __repr__ of PythonGraphTraversal is its Gremlin-Groovy compiled form
>>> g.V().repeat(out()).times(2).name
g.V().repeat(__.out()).times(2).values("name")
>>> # toList() does the magic
>>> g.V().repeat(out()).times(2).name.toList()
[u'ripple', u'lop']
>>>

PythonGraphTraversal implements __iter__ and thus, just like GraphTraversal in Gremlin-Java, its an iterator. You can see how next() works in the link below:


Anywho, any thoughts would be most appreciated.

Take care,
Marko.


On Jun 2, 2016, at 1:21 PM, Rich Burdon <rich....@gmail.com> wrote:

Hey Marko,

g.addV() doesn't seem to create a vertex so I really don't understand a) above.
 

Summary feedback :)

1). Neo4J Hello world (add node and retrieve it). 
Result: Achieved in 10 minutes.

2). TinkerPop Hello world (add node and retrieve it) via python-gremlin variant.
Result: Still can't get working after 3 days (needing user group and your valuable time).

3). Giving up on drivers and variants (today).
Result: Achieved in 5 minutes:

import json
import requests
import easydict from EasyDict

def request(gremlin):
    return requests.post('http://192.168.99.100:8182', headers={
'content-type': 'application/json'
}, data=json.dumps(dict(
gremlin=gremlin
)))

data = EasyDict(request('g.addV("name", "Hello")').json())
vid = data.result.data[0].id
print 'Created: %s' % vid

data = EasyDict(request('g.V(%s)' % vid).json())
print 'Retrieved: %s' % data.result.data[0].properties.name[0].value


Again, I appreciate you help. I think we'll move forward with the no-deps approach above for now.


--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-user...@googlegroups.com.

Debasish Kanhar

unread,
Sep 7, 2017, 11:55:52 AM9/7/17
to Gremlin-users
Hi Rich,

So were you able to make commit() work? For some reason, its not getting commited in my case. I do count().next() followed by addV() and then count().next() and the count remains same.
Reply all
Reply to author
Forward
0 new messages