Models Runtime :ask_sdk_model_runtime package¶
The Models Runtime classes contains the common models package by the Software Development Kit (SDK) team for Python that provides common implementations like Serializer, ApiClient BaseServiceClient, Authentication Configuration etc. that is used by the SDK models.
Subpackages¶
Submodules¶
Note
Canonical imports have been added in the __init__.py
of the package.
This helps in importing the class directly from the package, than
through the module.
For eg: if package a
has module b
with
class C
, you can do from a import C
instead of
from a.b import C
.
ask_sdk_model_runtime.api_client module¶
-
class
ask_sdk_model_runtime.api_client.
ApiClient
¶ Bases:
object
Represents a basic contract for API request invocation.
-
invoke
(request)¶ Dispatches a request to an API endpoint described in the request. The ApiClient is expected to resolve in the case an API returns a non-200 HTTP status code. The responsibility of translating a particular response code to an error lies with the caller. :param request: Request to dispatch to the ApiClient :type request: ApiClientRequest :return: Response from the client call :rtype: ApiClientResponse
-
-
class
ask_sdk_model_runtime.api_client.
DefaultApiClient
¶ Bases:
ask_sdk_model_runtime.api_client.ApiClient
Default ApiClient implementation of
ask_sdk_model_runtime.api_client.ApiClient
using the requests library.-
invoke
(request)¶ Dispatches a request to an API endpoint described in the request. Resolves the method from input request object, converts the list of header tuples to the required format (dict) for the requests lib call and invokes the method with corresponding parameters on requests library. The response from the call is wrapped under the ApiClientResponse object and the responsibility of translating a response code and response/ error lies with the caller. :param request: Request to dispatch to the ApiClient :type request: ApiClientRequest :return: Response from the client call :rtype: ApiClientResponse :raises:
ask_sdk_model_runtime.exceptions.ApiClientException
-
ask_sdk_model_runtime.api_client_message module¶
-
class
ask_sdk_model_runtime.api_client_message.
ApiClientMessage
(headers=None, body=None)¶ Bases:
object
Represents the interface between
ask_sdk_model_runtime.api_client.ApiClient
implementation and a Service Client.Parameters:
ask_sdk_model_runtime.api_client_request module¶
-
class
ask_sdk_model_runtime.api_client_request.
ApiClientRequest
(headers=None, body=None, url=None, method=None)¶ Bases:
ask_sdk_model_runtime.api_client_message.ApiClientMessage
Represents a request sent from Service Clients to an
ask_sdk_model_runtime.api_client.ApiClient
implementation.Parameters:
ask_sdk_model_runtime.api_client_response module¶
-
class
ask_sdk_model_runtime.api_client_response.
ApiClientResponse
(headers=None, body=None, status_code=None)¶ Bases:
ask_sdk_model_runtime.api_client_message.ApiClientMessage
Represents a response returned by
ask_sdk_model_runtime.api_client.ApiClient
implementation to a Service Client.Parameters:
ask_sdk_model_runtime.api_configuration module¶
-
class
ask_sdk_model_runtime.api_configuration.
ApiConfiguration
(serializer=None, api_client=None, authorization_value=None, api_endpoint=None)¶ Bases:
object
Represents a class that provides API configuration options needed by service clients.
Parameters: - serializer ((optional) ask_sdk_model_runtime.serializer.Serializer) – serializer implementation for encoding/decoding JSON from/to Object models.
- api_client ((optional) ask_sdk_model_runtime.api_client.ApiClient) – API Client implementation
- authorization_value ((optional) str) – Authorization value to be used on any calls of the service client instance
- api_endpoint ((optional) str) – Endpoint to hit by the service client instance
ask_sdk_model_runtime.api_response module¶
ask_sdk_model_runtime.authentication_configuration module¶
ask_sdk_model_runtime.base_service_client module¶
-
class
ask_sdk_model_runtime.base_service_client.
BaseServiceClient
(api_configuration)¶ Bases:
object
Class to be used as the base class for the generated service clients.
The class has to be implemented by the service clients and this class instantiation is not supported
Parameters: api_configuration (ask_sdk_model_runtime.api_configuration.ApiConfiguration) – ApiConfiguration implementation -
invoke
(method, endpoint, path, query_params, header_params, path_params, response_definitions, body, response_type)¶ Calls the ApiClient based on the ServiceClient specific data provided as well as handles the well-known responses from the Api.
Parameters: - method (str) – Http method
- endpoint – Base endpoint to make the request to
- path (str) – Specific path to hit. It might contain variables to be interpolated with path_params
- query_params (list(tuple(str, str))) – Parameter values to be sent as part of query string
- header_params (list(tuple(str, str))) – Parameter values to be sent as headers
- path_params (dict(str, str)) – Parameter values to be interpolated in the path
- response_definitions (list(ask_sdk_model_runtime.service_client_response.ServiceClientResponse)) – Well-known expected responses by the ServiceClient
- body (object) – Request body
- response_type (class) – Type of the expected response if applicable
Returns: ApiResponse object.
Return type: ask_sdk_model_runtime.api_response.py
Raises: ask_sdk_model_runtime.exceptions.ServiceException
if service fails andValueError
if serializer or API Client is not configured in api_configuration # noqa: E501
-
ask_sdk_model_runtime.exceptions module¶
-
exception
ask_sdk_model_runtime.exceptions.
ApiClientException
¶ Bases:
Exception
Exception class for ApiClient Adapter processing.
-
exception
ask_sdk_model_runtime.exceptions.
SerializationException
¶ Bases:
Exception
Class for exceptions raised during serialization/deserialization.
ask_sdk_model_runtime.serializer module¶
-
class
ask_sdk_model_runtime.serializer.
DefaultSerializer
¶ Bases:
ask_sdk_model_runtime.serializer.Serializer
-
NATIVE_TYPES_MAPPING
= {'bool': <class 'bool'>, 'date': <class 'datetime.date'>, 'datetime': <class 'datetime.datetime'>, 'float': <class 'float'>, 'int': <class 'int'>, 'long': <class 'int'>, 'object': <class 'object'>, 'str': <class 'str'>}¶
-
PRIMITIVE_TYPES
= (<class 'float'>, <class 'bool'>, <class 'bytes'>, <class 'str'>, <class 'int'>)¶
-
deserialize
(payload, obj_type)¶ Deserializes payload into an instance of provided
obj_type
.The
obj_type
parameter can be a primitive type, a generic model object or a list / dict of model objects.The list or dict object type has to be provided as a string format. For eg:
'list[a.b.C]'
if the payload is a list of instances of classa.b.C
.'dict(str, a.b.C)'
if the payload is a dict containing mappings ofstr : a.b.C
class instance types.
The method looks for a
deserialized_types
dict in the model class, that mentions which payload values has to be deserialized. In case the payload key names are different than the model attribute names, the corresponding mapping can be provided in another special dictattribute_map
. The model class should also have the__init__
method with default values for arguments. Checkask_sdk_model.request_envelope.RequestEnvelope
source code for an example implementation.Parameters: Returns: deserialized object
Return type: Raises:
-
serialize
(obj)¶ Builds a serialized object.
- If obj is None, return None.
- If obj is str, int, long, float, bool, return directly.
- If obj is datetime.datetime, datetime.date convert to string in iso8601 format.
- If obj is list, serialize each element in the list.
- If obj is dict, return the dict with serialized values.
- If obj is ask sdk model, return the dict with keys resolved
from the union of model’s
attribute_map
anddeserialized_types
and values serialized based ondeserialized_types
. - If obj is a generic class instance, return the dict with keys
from instance’s
deserialized_types
and values serialized based ondeserialized_types
.
Parameters: obj (object) – The data to serialize. Returns: The serialized form of data. Return type: Union[Dict[str, Any], List, Tuple, str, int, float, bytes, None]
-