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
Send an HTTP DELETE request
Send an HTTP GET request
Send an HTTP POST request
Send an HTTP POST request
Send an HTTP PUT request
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 URLheaders (
Optional
[Dict
[str
,str
]]) – headers to use for this request in addition to the client default headersreturn_raw_response (
bool
) – if true, return the requests.Response object received; otherwise attempt to parse the responseretries (
int
) – number of times to retry the request on failure. uses exponential backoffvalidate_response_status (
bool
) – if True, raise an ArthurException if the status code is not 2XX or does not match validation_response_codevalidation_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 URLheaders (
Optional
[Dict
[str
,str
]]) – headers to use for this request in addition to the client default headersparams (
Union
[Dict
,bytes
,None
]) – query parameters to add to the requestreturn_raw_response (
bool
) – if true, return the requests.Response object received; otherwise attempt to parse the responseretries (
int
) – number of times to retry the request on failure. uses exponential backoffvalidate_response_status (
bool
) – if True, raise an ArthurException if the status code is not 2XX or does not match validation_response_codevalidation_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 URLheaders (
Optional
[Dict
[str
,str
]]) – headers to use for this request in addition to the client default headersjson (
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 requestfiles (
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-dataparams (
Union
[Dict
,bytes
,None
]) – query parameters to add to the requestreturn_raw_response (
bool
) – if true, return the requests.Response object received; otherwise attempt to parse the responseretries (
int
) – number of times to retry the request on failure. uses exponential backoffvalidate_response_status (
bool
) – if True, raise an ArthurException if the status code is not 2XX or does not match validation_response_codevalidation_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 URLheaders (
Optional
[Dict
[str
,str
]]) – headers to use for this request in addition to the client default headersjson (
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 requestfiles (
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-dataparams (
Union
[Dict
,bytes
,None
]) – query parameters to add to the requestreturn_raw_response (
bool
) – if true, return the requests.Response object received; otherwise attempt to parse the responseretries (
int
) – number of times to retry the request on failure. uses exponential backoffvalidate_response_status (
bool
) – if True, raise an ArthurException if the status code is not 2XX or does not match validation_response_codevalidation_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 URLheaders (
Optional
[Dict
[str
,str
]]) – headers to use for this request in addition to the client default headersjson (
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 requestfiles (
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-dataparams (
Union
[Dict
,bytes
,None
]) – query parameters to add to the requestreturn_raw_response (
bool
) – if true, return the requests.Response object received; otherwise attempt to parse the responseretries (
int
) – number of times to retry the request on failure. uses exponential backoffvalidate_response_status (
bool
) – if True, raise an ArthurException if the status code is not 2XX or does not match validation_response_codevalidation_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 URLmethod (
str
) – the HTTP method to useheaders (
Optional
[Dict
[str
,str
]]) – headers to use for this request in addition to the client default headersjson (
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 requestfiles (
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-dataparams (
Union
[Dict
,bytes
,None
]) – query parameters to add to the requestreturn_raw_response (
bool
) – if true, return the requests.Response object received; otherwise attempt to parse the responseretries (
int
) – number of times to retry the request on failure. uses exponential backoffvalidate_response_status (
bool
) – if True, raise an ArthurException if the status code is not 2XX or does not match validation_response_codevalidation_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