epyt_flow.rest_api

epyt_flow.rest_api.server

This module provides the EPyT-Flow REST API server.

class epyt_flow.rest_api.server.RestApiService(port: int = 8080)[source]

Bases: object

Class implementing the REST API server.

Parameters:

port (int, optional) –

Port of the server.

The default is 8080

make_server() WSGIServer[source]

Returns a new web server.

property port: int

Gets the port of the web server.

Returns:

Port.

Return type:

int

run() None[source]

Runs the REST service.

epyt_flow.rest_api.res_manager

This module contains a class for managing recourses such as scenarios or SCADA data.

class epyt_flow.rest_api.res_manager.ResourceManager[source]

Bases: object

Class implementing a simple resource manager where resources are associated with UUIDs.

close_item(item: Any)[source]

Closes a given resource item – i.e. all clean-up logic for an item should be called here.

Parameters:

item (Any) – Resource item.

create_new_item(item: Any) str[source]

Adds a new item to the resource manager.

Parameters:

item (Any) – Item to be added.

Returns:

UUID of the new item.

Return type:

str

get(item_uuid: str) Any[source]

Gets the item associated with a given UUID.

Parameters:

item_uuid (str) – UUID of the item.

Returns:

Resource item.

Return type:

Any

remove(item_uuid: str) None[source]

Removes the scenario associated with a given UUID

Parameters:

item_uuid (str) – UUID of the item.

validate_uuid(item_uuid: str) bool[source]

Validates a given UUID – i.e. checks if there is a resource associated with the given UUID.

Parameters:

item_uuid (str) – UUID of the item.

Returns:

True if the given UUID is valid, False otherwise.

Return type:

bool

epyt_flow.rest_api.base_handler

This module provides a base handler with some useful methods for all REST API handlers.

class epyt_flow.rest_api.base_handler.BaseHandler[source]

Bases: object

Base class for all REST API handlers.

load_json_data_from_request(req: falcon.Request) Any[source]

Loads/Parses an object from given JSON data.

Parameters:

req (falcon.Request) – Request instance.

Returns:

Loaded object.

Return type:

Any

send_error(resp: falcon.Response, error_msg: str) None[source]

Sends an error message back.

Parameters:
  • resp (falcon.Response) – Response instance.

  • error_msg (str) – Error message.

send_invalid_resource_id_error(resp: falcon.Response) None[source]

Sends an error that th given resource ID (e.g. scenario ID, or SCADA data ID) is invalid.

Parameters:

resp (falcon.Response) – Response instance.

send_json_parsing_error(resp: falcon.Response) None[source]

Sends an error that the JSON parsing failed.

Parameters:

resp – Response instance.

send_json_response(resp: falcon.Response, data: Any) None[source]

Sends a JSON response.

Parameters:
  • resp – Response instance.

  • data (Any) – Data to be sent.