| |
- builtins.object
-
- RestClient
class RestClient(builtins.object) |
|
RestClient(base_url: str, get_token: Callable[[], str], resource_group: str = None, client_type: str = None, read_timeout=60, connect_timeout=60, num_request_retries=3)
RestClient is the class implemented for sending the requests to the server.
:param base_url: Base URL of the server. Should include the base path as well. (i.e., "<base_url>/scenarios" should
work)
:type base_url: str
:param get_token: the function which returns the Bearer token, when called
:type get_token: Callable[[], str]
:param resource_group: The default resource group which will be used while sending the requests to the server,
defaults to None
:type resource_group: str
:param client_type: Used for Metering to distinguish eg AI Launchpad python SDKs etc,
defaults to None
:type client_type: str
:param read_timeout: Read timeout for requests in seconds, defaults to 60s
:type read_timeout: int
:param connect_timeout: Connect timeout for requests in seconds, defaults to 60s
:type connect_timeout: int
:param num_request_retries: Number of retries for failing requests with http status code 429, 500, 502, 503 or 504,
defaults to 60s
:type num_request_retries: int |
|
Methods defined here:
- __init__(self, base_url: str, get_token: Callable[[], str], resource_group: str = None, client_type: str = None, read_timeout=60, connect_timeout=60, num_request_retries=3)
- Initialize self. See help(type(self)) for accurate signature.
- delete(self, path: str, params: Dict[str, str] = None, headers: Dict[str, str] = None, resource_group: str = None, **kwargs) -> dict
- Sends a DELETE request to the server.
:param path: path of the endpoint the request should be sent to
:type path: str
:param params: parameters of the request, defaults to None
:type params: Dict[str, str], optional
:param headers: headers of the request, defaults to None
:type headers: Dict[str, str], optional
:param resource_group: Resource Group which the request should be sent on behalf. Either this, or the
resource_group property of this class should be set.
:type resource_group: str
:param kwargs: additional keyword arguments to be passed to the request e.g. files, stream, etc.
:type kwargs: dict
:raises: class:`ai_api_client_sdk.exception.AIAPIInvalidRequestException` if a 400 response is received from the
server
:raises: class:`ai_api_client_sdk.exception.AIAPIAuthorizationException` if a 401 response is received from the
server
:raises: class:`ai_api_client_sdk.exception.AIAPINotFoundException` if a 404 response is received from the
server
:raises: class:`ai_api_client_sdk.exception.AIAPIPreconditionFailedException` if a 412 response is received from
the server
:raises: class:`ai_api_client_sdk.exception.AIAPIServerException` if a non-2XX response is received from the
server
:return: The JSON response from the server (The keys decamelized)
:rtype: dict
- get(self, path: str, params: Dict[str, str] = None, headers: Dict[str, str] = None, resource_group: str = None, return_bytes_content: bool = False, **kwargs) -> Union[dict, int]
- Sends a GET request to the server.
:param path: path of the endpoint the request should be sent to
:type path: str
:param params: parameters of the request, defaults to None
:type params: Dict[str, str], optional
:param headers: headers of the request, defaults to None
:type headers: Dict[str, str], optional
:param resource_group: Resource Group which the request should be sent on behalf. Either this, or the
resource_group property of this class should be set.
:type resource_group: str
:param return_bytes_content: expected response.content is bytes
:type return_bytes_content: bool
:param kwargs: additional keyword arguments to be passed to the request e.g. files, stream, etc.
:type kwargs: dict
:raises: class:`ai_api_client_sdk.exception.AIAPIInvalidRequestException` if a 400 response is received from the
server
:raises: class:`ai_api_client_sdk.exception.AIAPIAuthorizationException` if a 401 response is received from the
server
:raises: class:`ai_api_client_sdk.exception.AIAPINotFoundException` if a 404 response is received from the
server
:raises: class:`ai_api_client_sdk.exception.AIAPIPreconditionFailedException` if a 412 response is received from
the server
:raises: class:`ai_api_client_sdk.exception.AIAPIServerException` if a non-2XX response is received from the
server
:return: The JSON response from the server (The keys decamelized)
:rtype: Union[dict, int]
- patch(self, path: str, body: Dict[str, Union[str, dict, list]], headers: Dict[str, str] = None, resource_group: str = None, **kwargs) -> dict
- Sends a PATCH request to the server.
:param path: path of the endpoint the request should be sent to
:type path: str
:param body: body of the request
:type body: Dict[str, Union[str, dict, list]]
:param headers: headers of the request, defaults to None
:type headers: Dict[str, str], optional
:param resource_group: Resource Group which the request should be sent on behalf. Either this, or the
resource_group property of this class should be set.
:type resource_group: str
:param kwargs: additional keyword arguments to be passed to the request e.g. files, stream, etc.
:type kwargs: dict
:raises: class:`ai_api_client_sdk.exception.AIAPIInvalidRequestException` if a 400 response is received from the
server
:raises: class:`ai_api_client_sdk.exception.AIAPIAuthorizationException` if a 401 response is received from the
server
:raises: class:`ai_api_client_sdk.exception.AIAPINotFoundException` if a 404 response is received from the
server
:raises: class:`ai_api_client_sdk.exception.AIAPIPreconditionFailedException` if a 412 response is received from
the server
:raises: class:`ai_api_client_sdk.exception.AIAPIServerException` if a non-2XX response is received from the
server
:return: The JSON response from the server (The keys decamelized)
:rtype: dict
- post(self, path: str, body: Dict[str, Union[str, dict]] = None, headers: Dict[str, str] = None, resource_group: str = None, **kwargs) -> dict
- Sends a POST request to the server.
:param path: path of the endpoint the request should be sent to
:type path: str
:param body: body of the request, defaults to None
:type body: Dict[str, str], optional
:param headers: headers of the request, defaults to None
:type headers: Dict[str, str], optional
:param resource_group: Resource Group which the request should be sent on behalf. Either this, or the
resource_group property of this class should be set.
:type resource_group: str
:param kwargs: additional keyword arguments to be passed to the request e.g. files, stream, etc.
:type kwargs: dict
:raises: class:`ai_api_client_sdk.exception.AIAPIInvalidRequestException` if a 400 response is received from the
server
:raises: class:`ai_api_client_sdk.exception.AIAPIAuthorizationException` if a 401 response is received from the
server
:raises: class:`ai_api_client_sdk.exception.AIAPINotFoundException` if a 404 response is received from the
server
:raises: class:`ai_api_client_sdk.exception.AIAPIPreconditionFailedException` if a 412 response is received from
the server
:raises: class:`ai_api_client_sdk.exception.AIAPIServerException` if a non-2XX response is received from the
server
:return: The JSON response from the server (The keys decamelized)
:rtype: dict
Static methods defined here:
- raise_ai_api_exception(error_description, response, response_json)
Data descriptors defined here:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
Data and other attributes defined here:
- logger = <Logger ai-api-client-sdk (WARNING)>
| |