riverapi package

Submodules

riverapi.defaults module

riverapi.auth module

class riverapi.auth.authHeader(lookup)[source]

Bases: object

riverapi.auth.parse_auth_header(authHeaderRaw)[source]

Parse an authentication header into relevant pieces

riverapi.logger module

class riverapi.logger.ColorizingStreamHandler(nocolor=False, stream=<_io.TextIOWrapper name='<stderr>' mode='w' encoding='utf-8'>, use_threads=False)[source]

Bases: logging.StreamHandler

BLACK = 0
BLUE = 4
BOLD_SEQ = '\x1b[1m'
COLOR_SEQ = '\x1b[%dm'
CYAN = 6
GREEN = 2
MAGENTA = 5
RED = 1
RESET_SEQ = '\x1b[0m'
WHITE = 7
YELLOW = 3
can_color_tty()[source]
colors = {'CRITICAL': 1, 'DEBUG': 4, 'ERROR': 1, 'INFO': 2, 'WARNING': 3}
decorate(record)[source]
emit(record)[source]

Emit a record.

If a formatter is specified, it is used to format the record. The record is then written to the stream with a trailing newline. If exception information is present, it is formatted using traceback.print_exception and appended to the stream. If the stream has an ‘encoding’ attribute, it is used to determine how to do the output to the stream.

property is_tty
class riverapi.logger.Logger[source]

Bases: object

cleanup()[source]
debug(msg)[source]
error(msg)[source]
exit(msg, return_code=1)[source]
handler(msg)[source]
info(msg)[source]
location(msg)[source]
progress(done=None, total=None)[source]
set_level(level)[source]
set_stream_handler(stream_handler)[source]
shellcmd(msg)[source]
text_handler(msg)[source]

The default snakemake log handler. Prints the output to the console. :param msg: the log message dictionary :type msg: dict

warning(msg)[source]
riverapi.logger.setup_logger(quiet=False, printshellcmds=False, nocolor=False, stdout=False, debug=False, use_threads=False, wms_monitor=None)[source]

riverapi.main module

class riverapi.main.Client(baseurl=None, quiet=False, prefix='api')[source]

Bases: object

Interact with a River Server

property apiroot

Combine the baseurl and prefix to get the complete root.

authenticate_request(originalResponse)[source]

Authenticate the request.

Given a response (an HTTPError 401), look for a Www-Authenticate header to parse. We return True/False to indicate if the request should be retried.

check()[source]

The user can run check to perform a service info, and update the prefix or baseurl if the server provides different ones.

check_flavor(flavor)[source]

Verify that the flavor is known

check_response(typ, r, return_json=True, stream=False, retry=True)[source]

Ensure the response status code is 20x

delete(url, data=None, json=None, headers=None, return_json=True)[source]

Perform a DELETE request

delete_model(model_name)[source]

Delete a model by name

do_request(typ, url, data=None, json=None, headers=None, return_json=True, stream=False)[source]

Do a request (get, post, etc)

download_model(model_name, dest=None)[source]

Download a model to file (e.g., pickle)

with open(“muffled-pancake-9439.pkl”, “rb”) as fd:
content=pickle.load(fd)
get(url, data=None, json=None, headers=None, return_json=True, stream=False)[source]

Perform a GET request

get_model_json(model_name)[source]

Get a json respresentation of a model.

getenv()[source]

Get any token / username set in the environment

info()[source]

Get basic server information

label(label, identifier, model_name)[source]

Given a label we know for a prediction after the fact (which we can look up with an identifier from the server), use the label endpoint to update the model metrics and call learn one. Note that the model_name is not technically required (it’s stored with the cached entry) however we require providing it to validate the association. If you have a label at the time of running predict you can use it then and should not need this endpoint. Also note that ground_truth of a prediction is synonymous with label here.

learn(model_name, x, y=None)[source]

Train on some data. You are required to provide at least the model name known to the server and x (data).

for x, y in datasets.TrumpApproval().take(100):
cli.train(x, y)
metrics(model_name)[source]

Get metrics for a model name

models()[source]

Get a listing of known models

post(url, data=None, json=None, headers=None, return_json=True)[source]

Perform a POST request

predict(model_name, x)[source]

Make a prediction

print_response(r)[source]

Print the result of a response

set_basic_auth(username, password)[source]

A wrapper to adding basic authentication to the Request

set_header(name, value)[source]

Set a header, name and value pair

stats(model_name)[source]

Get stats for a model name

stream(url)[source]

General stream endpoint

stream_events()[source]

Stream events

stream_metrics()[source]

Stream metrics

upload_model(model, flavor, model_name=None)[source]

Given a model / pipeline, upload to an online-ml server.

model = preprocessing.StandardScaler() | linear_model.LinearRegression()

riverapi.utils module

riverapi.utils.fileio module

riverapi.utils.fileio.print_json(json_obj)[source]

Print json pretty

riverapi.utils.fileio.read_file(filename, mode='r')[source]

Read a file.

riverapi.utils.fileio.read_json(filename, mode='r')[source]

Read a json file to a dictionary.

riverapi.utils.fileio.write_file(filename, content, mode='w', exec=False)[source]

Write content to a filename

riverapi.utils.fileio.write_json(json_obj, filename, mode='w')[source]

Write json to a filename

riverapi.utils.terminal module

riverapi.utils.terminal.confirm_action(question, force=False)[source]

confirm if the user wants to perform a certain action

Parameters:
  • question (the question that will be asked) –
  • force (if the user wants to skip the prompt) –
riverapi.utils.terminal.confirm_uninstall(filename, force=False)[source]

confirm if the user wants to uninstall a module

Parameters:
  • filename (the file that will be removed) –
  • force (if the user wants to skip the prompt) –
riverapi.utils.terminal.get_installdir()[source]

get_installdir returns the installation directory of the application

riverapi.utils.terminal.run_command(cmd, sudo=False, stream=False)[source]

run_command uses subprocess to send a command to the terminal.

Parameters:
  • cmd (the command to send, should be a list for subprocess) –
  • error_message (the error message to give to user if fails,) –
  • failed. (if none specified, will alert that command) –

riverapi.version module