A simple Python client for Myna.
This client uses the built-in httplib
to allow you to suggest and reward your Myna clients. It has no external dependencies. Tested in Python 2.7.
Just copy myna.py
somewhere that is accessible from your code. Then to create an experiment:
expt = Experiment('45923780-80ed-47c6-aa46-15e2ae7a0e8c')
Get a suggestion:
suggestion = expt.suggest()
Do something with the choice Myna has made:
doSomething(suggestion.choice)
Finally, reward the suggestion if the user did what you hoped they would.
suggestion.reward()
See the API reference below for complete details.
Better handle errors that aren't in the Myna format.
Run the tests with
python -m unittest test
Represents an experiment. Construct by passing in a string UUID.
expt = Experiment('45923780-80ed-47c6-aa46-15e2ae7a0e8c')
The UUID of this experiment. A string.
Retrieves a suggestion from the Myna server. Returns a Suggestion
object on success. On error a MynaError
exception is raised.
Represents a suggestion returned by an experiment.
The choice associated with this suggestion. A string.
The token associated with this suggestion. A string.
Rewards this suggestion. The optional amount defaults to 1.0, and must be a number between 0.0 and 1.0.
Returns True
on success. Otherwise raises an exception as follows:
MynaError
if the Myna server sent back a response containing a Problem (see the Myna API documentation on error handling)IOError
if some other error occurred
An exception raised when the Myna server returns a Problem. See the API documentation on error handling for a description.
A numeric code identifying the error.
Helpful messages associated with the error.