arthurai.client.http.requests.HTTPClient#

class arthurai.client.http.requests.HTTPClient(base_url, path_prefix=None, default_headers=None, verify_ssl=True, timeout_sec=300.0, allow_insecure=True, header_refresh_func=None)#

Bases: arthurai.client.http.base.AbstractHTTPClient

A requests-based HTTP Client intended for interacting with JSON-based APIs. Supports response validation, retries, connection reuse, and multipart requests.

Methods

delete

Send an HTTP DELETE request

get

Send an HTTP GET request

patch

Send an HTTP POST request

post

Send an HTTP POST request

put

Send an HTTP PUT request

send

Send an HTTP request

delete(endpoint, headers=None, return_raw_response=False, retries=0, validate_response_status=True, validation_response_code=None)#

Send an HTTP DELETE request

Parameters
  • endpoint (str) – the specific endpoint to append to the client URL

  • headers (Optional[Dict[str, str]]) – headers to use for this request in addition to the client default headers

  • return_raw_response (bool) – if true, return the requests.Response object received; otherwise attempt to parse the response

  • retries (int) – number of times to retry the request on failure. uses exponential backoff

  • validate_response_status (bool) – if True, raise an ArthurException if the status code is not 2XX or does not match validation_response_code

  • validation_response_code (Optional[int]) – expected status code of the response to validate. if None, don’t validate

Return type

Union[Dict, List, bytes, BytesIO, Response]

Returns

if return_raw_response is true, return the requests.Response object received; otherwise attempt to parse the response

get(endpoint, headers=None, params=None, return_raw_response=False, retries=0, validate_response_status=True, validation_response_code=None)#

Send an HTTP GET request

Parameters
  • endpoint (str) – the specific endpoint to append to the client URL

  • headers (Optional[Dict[str, str]]) – headers to use for this request in addition to the client default headers

  • params (Union[Dict, bytes, None]) – query parameters to add to the request

  • return_raw_response (bool) – if true, return the requests.Response object received; otherwise attempt to parse the response

  • retries (int) – number of times to retry the request on failure. uses exponential backoff

  • validate_response_status (bool) – if True, raise an ArthurException if the status code is not 2XX or does not match validation_response_code

  • validation_response_code (Optional[int]) – expected status code of the response to validate. if None, allow any 2XX

Return type

Union[Dict, List, bytes, BytesIO, Response]

Returns

if return_raw_response is true, return the requests.Response object received; otherwise attempt to parse the response

Raises
  • ArthurUserError – failed due to user error

  • ArthurInternalError – failed due to an internal error

patch(endpoint, json=None, files=None, headers=None, params=None, return_raw_response=False, retries=0, validate_response_status=True, validation_response_code=None)#

Send an HTTP POST request

Parameters
  • endpoint (str) – the specific endpoint to append to the client URL

  • headers (Optional[Dict[str, str]]) – headers to use for this request in addition to the client default headers

  • json (Union[Dict, List, str, bytes, None]) – data to send as JSON, either a string/bytes to send directly or a dictionary/list to serialize. if files is also supplied, this should be a map from name to content, to be sent along with the files as a multipart request

  • files (Union[Dict[str, BinaryIO], List[Tuple], Dict[str, Tuple], None]) – a map from file names to file-like objects, to be sent as multipart/form-data

  • params (Union[Dict, bytes, None]) – query parameters to add to the request

  • return_raw_response (bool) – if true, return the requests.Response object received; otherwise attempt to parse the response

  • retries (int) – number of times to retry the request on failure. uses exponential backoff

  • validate_response_status (bool) – if True, raise an ArthurException if the status code is not 2XX or does not match validation_response_code

  • validation_response_code (Optional[int]) – expected status code of the response to validate. if None, don’t validate

Return type

Union[Dict, List, bytes, BytesIO, Response]

Returns

if return_raw_response is true, return the requests.Response object received; otherwise attempt to parse the response

post(endpoint, json=None, files=None, headers=None, params=None, return_raw_response=False, retries=0, validate_response_status=True, validation_response_code=None)#

Send an HTTP POST request

Parameters
  • endpoint (str) – the specific endpoint to append to the client URL

  • headers (Optional[Dict[str, str]]) – headers to use for this request in addition to the client default headers

  • json (Union[Dict, List, str, bytes, None]) – data to send as JSON, either a string/bytes to send directly or a dictionary/list to serialize. if files is also supplied, this should be a map from name to content, to be sent along with the files as a multipart request

  • files (Union[Dict[str, BinaryIO], List[Tuple], Dict[str, Tuple], None]) – a map from file names to file-like objects, to be sent as multipart/form-data

  • params (Union[Dict, bytes, None]) – query parameters to add to the request

  • return_raw_response (bool) – if true, return the requests.Response object received; otherwise attempt to parse the response

  • retries (int) – number of times to retry the request on failure. uses exponential backoff

  • validate_response_status (bool) – if True, raise an ArthurException if the status code is not 2XX or does not match validation_response_code

  • validation_response_code (Optional[int]) – expected status code of the response to validate. if None, don’t validate

Return type

Union[Dict, List, bytes, BytesIO, Response]

Returns

if return_raw_response is true, return the requests.Response object received; otherwise attempt to parse the response

put(endpoint, json=None, files=None, headers=None, params=None, return_raw_response=False, retries=0, validate_response_status=True, validation_response_code=None)#

Send an HTTP PUT request

Parameters
  • endpoint (str) – the specific endpoint to append to the client URL

  • headers (Optional[Dict[str, str]]) – headers to use for this request in addition to the client default headers

  • json (Union[Dict, List, str, bytes, None]) – data to send as JSON, either a string/bytes to send directly or a dictionary/list to serialize. if files is also supplied, this should be a map from name to content, to be sent along with the files as a multipart request

  • files (Union[Dict[str, BinaryIO], List[Tuple], Dict[str, Tuple], None]) – a map from file names to file-like objects, to be sent as multipart/form-data

  • params (Union[Dict, bytes, None]) – query parameters to add to the request

  • return_raw_response (bool) – if true, return the requests.Response object received; otherwise attempt to parse the response

  • retries (int) – number of times to retry the request on failure. uses exponential backoff

  • validate_response_status (bool) – if True, raise an ArthurException if the status code is not 2XX or does not match validation_response_code

  • validation_response_code (Optional[int]) – expected status code of the response to validate. if None, don’t validate

Return type

Union[Dict, List, bytes, BytesIO, Response]

Returns

if return_raw_response is true, return the requests.Response object received; otherwise attempt to parse the response

send(endpoint, method='GET', json=None, files=None, headers=None, params=None, return_raw_response=False, retries=0, validate_response_status=True, validation_response_code=None)#

Send an HTTP request

Parameters
  • endpoint (str) – the specific endpoint to append to the client URL

  • method (str) – the HTTP method to use

  • headers (Optional[Dict[str, str]]) – headers to use for this request in addition to the client default headers

  • json (Union[Dict, List, str, bytes, None]) – data to send as JSON, either a string/bytes to send directly or a dictionary/list to serialize. if files is also supplied, this should be a map from name to content, to be sent along with the files as a multipart request

  • files (Union[Dict[str, BinaryIO], List[Tuple], Dict[str, Tuple], None]) – a map from file names to file-like objects, to be sent as multipart/form-data

  • params (Union[Dict, bytes, None]) – query parameters to add to the request

  • return_raw_response (bool) – if true, return the requests.Response object received; otherwise attempt to parse the response

  • retries (int) – number of times to retry the request on failure. uses exponential backoff

  • validate_response_status (bool) – if True, raise an ArthurException if the status code is not 2XX or does not match validation_response_code

  • validation_response_code (Optional[int]) – expected status code of the response to validate. if None, allow any 2XX

Return type

Union[Dict, List, bytes, BytesIO, Response]

Returns

if return_raw_response is true, return the requests.Response object received; otherwise attempt to parse the response

Raises
  • ArthurUserError – failed due to user error

  • ArthurInternalError – failed due to an internal error