Giter VIP home page Giter VIP logo

gremlinclient's Introduction

gremlinclient

Build Status Coverage Status

Multi-platform Python client for the TinkerPop 3 Gremlin Server - Tornado, Asyncio, Trollius

Submit a script to the Gremlin Server with Python 2.7 or 3.3+ using Tornado

>>> from tornado import gen
>>> from tornado.ioloop import IOLoop
>>> from gremlinclient.tornado_client import submit


>>> loop = IOLoop.current()


>>> @gen.coroutine
... def go():
...     resp = yield submit("ws://localhost:8182/", "1 + 1")
...     while True:
...         msg = yield resp.read()
...         if msg is None:
...             break
...         print(msg)
>>> loop.run_sync(go)

Message(status_code=200, data=[2], message=u'', metadata={})

gremlinclient's People

Contributors

davebshow avatar pmcfadden avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

gremlinclient's Issues

Example returns 400

The example script on the home page returns

tornado.httpclient.HTTPError: HTTP 400: Bad Request

With the following on the server:

titan_1 | 185142 [gremlin-server-worker-1] WARN org.apache.tinkerpop.gremlin.server.handler.HttpGremlinEndpointHandler - Invalid request - responding with 400 Bad Request and no gremlin script supplied

Against Titan (https://github.com/elubow/titan-gremlin/blob/master/Dockerfile)

Which depends on TinkerPop 3.0.1-incubating

Is this server supported?

response API use pattern

@platinummonkey - Which server response API do you prefer for the new client?

aiogremlin uses the following API to get a list of messages:

resp = yield from gc.submit("x + x", bindings={"x": 4})
result = yield from resp.get()

But for streaming responses, you do this:

resp = yield from gc.submit("x + x", bindings={"x": 1})
while True:
    result = yield from resp.stream.read()
    if result is None: break

For the new client, I was thinking about maintaining the response.get method while simplifying the streaming to something like this:

resp = yield from gc.submit("x + x", bindings={"x": 1})
while True:
    result = yield from resp.read()
    if result is None: break

Thoughts? Do you have a preference?

How to use library with existing Tornado web app

Do you know how to hook into an existing ioloop and retrieve results?

I've been playing around with adding futures via ioloop.add_future and many other, unsuccessful approaches. And you simply cannot run run_sync because it assumes it is the only loop running and throws an error. Any suggestions?

Thanks,
Mark

Some problems

  1. can't use it by reading README.md, could you please update it?
  2. in gremlinclient/gremlinclient/tornado_client/client.py, line 220, the arg 'bindings' is set to None, serious?

Provide easy helper methods that supports parameterized submission.

It took me a long time to realize to do this:

  @gen.coroutine
  def submit(gremlinServerURI, traversalString):
    response = yield submit(gremlinServerURI, traversalString)
    while True:
      result = yield response.read()
      if result is None:
        break
      raise gen.Return(result.data)

Where this is called via:

def toList(self):
  return IOLoop.current().run_sync(lambda: Helper.submit(self.gremlinServerURI, self.traversalString))

For the following tutorial: http://tinkerpop.apache.org/docs/3.2.1-SNAPSHOT/tutorials/gremlin-language-variants/

Be nice to provide such "easy" methods in gremlinclient.

Runtime Errors on non 2** response

Hey @davebshow first off, thanks for this client it's been really helpful in getting up and going with TP3/Titan1.0

We were having some issues handling the RuntimeError raised as part of GremlinResponse#parser. It might be we're going about it incorrectly, which I'm still looking into. However, in the meantime I made an update that will allow you to pass a flag for if you want gremlinclient to not raise the exception, and return the errors/status code in the Message tuple.

Also, it looked like there was a positioning mismatch of message and metadata on the response, so we weren't actually getting the error text from the server. So we swapped that as well. I didn't know if you preferred an issue before a pull request, but I'll open one as well.

Thoughts/Ideas/Issues?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.