Giter VIP home page Giter VIP logo

yhat-client's Introduction

Yhat Python Client

This is the connection to the Yhat API. If you'd like to read more, visit our docs.

Table of Contents:

Installation

Using pip:

$ pip install --upgrade yhat

From source:

$ git clone [email protected]:yhat/yhat-client.git
$ cd yhat-client
$ python setup.py install

Quickstart

You can download the example here , or clone the git repo.

$ git clone [email protected]:yhat/yhat-examples.git
$ cd beer-recommender

Insert your APIKEY and USERNAME and run the script.

$ python recommender.py
Deploy? (y/N): y
# {"status": "success"}

Analytics

yhat-client's People

Contributors

bajh avatar coristig avatar emches avatar ericchiang avatar ericox avatar glamp avatar hernamesbarbara avatar jessfraz avatar leetrout avatar rosskipp avatar ryanjoneil avatar yhat-enterprise 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  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

yhat-client's Issues

Deprecate `Yhat.run()`

x = YhatModel

In [6]: x.run(ReturnSentData(),testcase='{"key":"val"}')
Paste your test data here
Data should be formatted as valid JSON.
Hit <ENTER> to execute your model
Press <CTRL + C> or type 'quit' to exit
========================================
[In] {"key":"val"}
[Out]
{'data_sent': {u'key': u'val'}}
[In] {"blah":"foofoofoo"}
[Out]
{'data_sent': {u'blah': u'foofoofoo'}}

It works, but I don't really see any value in this. Its identical to running an execute statement.

Python client misrepresents certain errors

This error will be thrown if the server address is mispelled, or if the network is down, etc.

  File "/tmp/monitor/py_test_model_Iceman.py", line 6, in <module>
    yh = Yhat("USER", "APIKEY", "SERVER")
  File "/usr/local/lib/python2.7/dist-packages/yhat/api.py", line 174, in __init__
    raise Exception("Incorrect username/apikey!")
Exception: Incorrect username/apikey!

Here's where the error is given: https://github.com/yhat/yhat-client/blob/master/yhat/api.py#L230

But the _authenticate method swallows the real error: https://github.com/yhat/yhat-client/blob/master/yhat/api.py#L265-L266

Handle relative imports for users

We don't seem to handle relative imports very well. This can lead to confusion and frustration.

Currently, if someone does this, we won't get the import (TODO - not sure this is exactly right) :

from package.something.whatever import NewInstance

class MyObject(param1, param2)
    ...
    ...

NewInstance = MyObject(param1, param2)

They have to do this instead:

from package.something.wahtever import MyObject

NewInstance = MyObject(param1, param2)

preprocess decorator: null_handler does not work

from yhat import Yhat, YhatModel , preprocess
import pandas as pd

class ReturnSentData(YhatModel):
    @preprocess(in_type=pd.DataFrame, out_type=dict, null_handler=[{"name":"key_2","na_filler":"No_value"}])
    def execute(self, data):
        return { "data_sent": data }

ReturnSentData().execute({"key_1": "value_1","key_2": ""})
Out[83]:
{'data_sent':      key_1 key_2
 0  value_1      }

It works below, but this is invalid json

ReturnSentData().execute({"key_1": "value_1","key_2": None})
Out[83]:
{'data_sent':      key_1     key_2
 0  value_1  No_value}

Issue w/ open file

Not sure what this is exactly, will update as I learn more.

Note that this is on a Windows Machine:

image

Can't deploy after pasting into ipython console

>>> from yhat import Yhat, YhatModel, preprocess
>>> class HelloWorld(YhatModel):
...     @preprocess(in_type=dict, out_type=dict)
...     def execute(self, data):
...         me = data['name']
...         greeting = "Hello %s!" % me
...         return { "greeting": greeting }
... 
>>> yh.deploy("HelloWorld", HelloWorld, globals())
Are you sure you want to deploy? (y/N): y
extracting model
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/site-packages/yhat/api.py", line 436, in deploy
    bundle = self._extract_model(name, model, session, verbose=verbose, autodetect=autodetect, is_tensorflow=is_tensorflow)
  File "/usr/local/lib/python2.7/site-packages/yhat/api.py", line 342, in _extract_model
    bundle = save_function(model, session)
  File "/usr/local/lib/python2.7/site-packages/yhat/deployment/save_session.py", line 402, in save_function
    imports, source_code, pickles, modules = _spider_function(function, session)
  File "/usr/local/lib/python2.7/site-packages/yhat/deployment/save_session.py", line 289, in _spider_function
    source += _get_source(function) + '\n'
  File "/usr/local/lib/python2.7/site-packages/yhat/deployment/save_session.py", line 80, in _get_source
    return reindent(_get_source_no_reindent(func))
  File "/usr/local/lib/python2.7/site-packages/yhat/deployment/save_session.py", line 97, in _get_source_no_reindent
    wrapped_source = "\n" + reindent(wrapped_source) + "\n"
  File "/usr/local/lib/python2.7/site-packages/yhat/deployment/save_session.py", line 30, in reindent
    r.run()
  File "/usr/local/lib/python2.7/site-packages/yhat/deployment/reindenter.py", line 148, in run
    for _token in tokens:
  File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/tokenize.py", line 374, in generate_tokens
    ("<tokenize>", lnum, pos, line))
  File "<tokenize>", line 2
    def execute(self, data):
    ^
IndentationError: unindent does not match any outer indentation level

Cant deploy with python 3.5

HelloWorld works fine with python 2.7, yhat 1.9.12

Below it fails using python 3.5, yhat 1.9.12

from yhat import Yhat, YhatModel
class HelloWorld(YhatModel):
   def execute(self, data):
       me = data['name']
       greeting = "Hello %s!" % me
       return { "greeting": greeting }
yh = Yhat("colin",  "d325fc5bcb83fc197ee01edb58b4b396", "https://sandbox.c.yhat.com")
yh.deploy("HelloWorld", HelloWorld, globals())
Are you sure you want to deploy? (y/N): y

extracting model
  File "<unknown>", line 1
    class HelloWorld(YhatModel):
                                ^
SyntaxError: unexpected EOF while parsing

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.