clams.restify package

Module contents

class clams.restify.ClamsHTTPApi(cla_instance: clams.app.ClamsApp)[source]

Bases: flask_restful.Resource

ClamsHTTPApi provides mapping from HTTP verbs to Python API defined in ClamsApp.

Constructor takes an instance of ClamsApp.

get() → flask.wrappers.Response[source]

Maps HTTP GET verb to appmetadata().

Returns

Returns app metadata in a HTTP response.

static json_to_response(json_str: str, status=200) → flask.wrappers.Response[source]

Helper method to convert JSON output from a ClamsApp to a HTTP response.

Parameters
  • json_str – a serialized JSON .

  • status – a numerical HTTP code to respond.

Returns

A HTTP response ready to send.

methods = {'GET', 'POST', 'PUT'}[source]
post() → flask.wrappers.Response[source]

Maps HTTP POST verb to annotate(). Note that for now HTTP PUT verbs is also mapped to annotate().

Returns

Returns MMIF output from a ClamsApp in a HTTP response.

put() → flask.wrappers.Response[source]

Maps HTTP POST verb to annotate(). Note that for now HTTP PUT verbs is also mapped to annotate().

Returns

Returns MMIF output from a ClamsApp in a HTTP response.

class clams.restify.ParameterCaster(param_spec: Dict)[source]

Bases: object

A helper class to convert parameters passed by HTTP query strings to proper python data types.

Parameters

param_spec – A specification of a data types of parameters

static bool_param(value)[source]

Helper function to convert string values to bool type.

cast(args)[source]

Given parameter specification, tries to cast values of args to specified Python data types. If the parameter key is not specified in the app metadata, a ``TypeError` is raised.

Parameters

args – k-v pairs

Returns

A new dictionary of type-casted args

Raises

KeyError: when parameter is unknown

static float_param(value)[source]

Helper function to convert string values to float type.

static int_param(value)[source]

Helper function to convert string values to int type.

static str_param(value)[source]

Helper function to convert string values to string type.

class clams.restify.Restifier(app_instance: clams.app.ClamsApp, loopback: bool = False, port: int = 5000, debug: bool = True)[source]

Bases: object

Resitifier is a simple wrapper that takes a ClamsApp object and turn it into a flaks-based HTTP server. For mapping between Python API and HTTP API, it relies on ClamsHTTPApi class.

Constructor takes a ClamsApp instance and some options for flask configuration.

Parameters
  • app_instance – A ClamsApp to wrap.

  • loopback – when True, the flask wrapper only listens to requests from localhost (used for debugging).

  • port – Port number for the flask app to listen (used for debugging).

  • debug – When True, the flask wrapper will run in debug mode.

run(**options)[source]

Starts a development server. See serve_development().

Parameters

options – any additional options to pass to the web server.

serve_development(**options)[source]

Runs the CLAMS app as a flask webapp, using flask built-in development server (https://werkzeug.palletsprojects.com/en/2.0.x/).

Parameters

options – any additional options to pass to the web server.

serve_production(**options)[source]

Runs the CLAMS app as a flask webapp, using a production-ready web server (gunicorn, https://docs.gunicorn.org/en/stable/#).

Parameters

options – any additional options to pass to the web server.

test_client()[source]

Returns flask test client.