aistore.sdk.request_client

View as MarkdownOpen in Claude

Module Contents

Classes

NameDescription
RequestClientInternal client for making requests to an AIS cluster or a specific proxy (e.g. AuthN).

Data

T

logger

API

class aistore.sdk.request_client.RequestClient(
endpoint: str,
session_manager: aistore.sdk.session_manager.SessionManager,
timeout: typing.Optional[typing.Union[float, typing.Tuple[float, float]]] = None,
token: str = None,
response_handler: aistore.sdk.response_handler.ResponseHandler = AISResponseHandler(),
retry_config: typing.Optional[aistore.sdk.retry_config.RetryConfig] = None
)

Internal client for making requests to an AIS cluster or a specific proxy (e.g. AuthN).

Parameters:

endpoint
str

Endpoint to either the AIS cluster or a specific proxy (e.g. AuthN).

session_manager
SessionManager

SessionManager for creating and accessing requests session.

timeout
Union[float, Tuple[float, float], None]Defaults to None

Request timeout in seconds; a single float. for both connect/read timeouts (e.g., 5.0), a tuple for separate connect/read timeouts (e.g., (3.0, 10.0)), or None to disable timeout.

token
strDefaults to None

Authorization token.

response_handler
ResponseHandlerDefaults to AISResponseHandler()

Handler for processing HTTP responses. Defaults to AISResponseHandler.

_base_url
= urljoin(endpoint, 'v1')
_retry_manager
base_url

Return the base URL.

session_manager
SessionManager

Return the SessionManager used to create sessions for this client.

timeout

Return the timeout for requests.

token
str

Return the token for authorization.

aistore.sdk.request_client.RequestClient._calculate_content_length(
data: typing.Union[bytes, str, typing.Any]
) -> typing.Optional[int]

Calculate the content length of data for HTTP requests.

Handles multiple data types including bytes, strings, and file-like objects.

Parameters:

data
Union[bytes, str, Any]

The data whose length needs to be calculated. Can be:

  • bytes or str: Direct length calculation
  • File-like object with fileno(): Uses fstat for efficiency
  • File-like object with seek(): Uses seek to determine size
  • Other types: Returns None with a warning

Returns: Optional[int]

The content length in bytes, or None if it cannot be determined

Raises:

  • IOError: If file operations fail during content length calculation
aistore.sdk.request_client.RequestClient._generate_headers(
headers: typing.Optional[typing.Dict[str, typing.Any]] = None
) -> typing.Dict[str, typing.Any]
aistore.sdk.request_client.RequestClient._make_session_request(
method: str,
url: str,
headers: typing.Any,
kwargs = {}
) -> requests.Response
aistore.sdk.request_client.RequestClient._prepare_proxy_request(
headers: typing.Dict[str, typing.Any],
kwargs: typing.Dict[str, typing.Any]
) -> typing.Dict[str, typing.Any]

Prepare the request parameters for the initial proxy request.

When data is present, the Content-Length header is calculated and set if possible, but the actual data is replaced with an empty byte string to avoid SSL EOF errors and improve efficiency.

Parameters:

headers
Dict[str, Any]

Request headers to be sent

kwargs
Dict[str, Any]

Additional request parameters including optional ‘data’

Returns: Dict[str, Any]

Dict containing the prepared request parameters for the proxy

Raises:

  • IOError: If file operations fail during content length calculation
aistore.sdk.request_client.RequestClient._request_with_manual_redirect(
method: str,
url: str,
headers: typing.Dict[str, typing.Any],
kwargs = {}
) -> requests.Response

Execute a request with manual redirect handling for HTTPS connections with data.

This method implements a two-phase request pattern:

  1. Send a request to the proxy to obtain the redirect URL
  2. Send the actual request with data to the redirected target

This workaround is necessary because the requests library does not properly handle 307 redirects from TLS-enabled servers when data is present in the request, resulting in SSL EOF errors: SSLEOFError(8, ‘EOF occurred in violation of protocol’)

When cluster authentication is enabled, the proxy requires the Content-Length header to compute the HMAC signature, but the actual data payload is not needed until the request reaches the target node.

Parameters:

method
str

HTTP method (e.g., ‘GET’, ‘POST’, ‘PUT’, ‘DELETE’)

url
str

Initial URL to the AIS proxy

headers
Dict[str, Any]

HTTP headers to be sent with the request

**kwargs
Defaults to {}

Additional request parameters (e.g., data, params, timeout)

Returns: Response

The HTTP response from the final target server

Raises:

  • ValueError: If the proxy does not return a redirect or the redirect URL is missing
  • TypeError: If data type is not supported
  • IOError: If file operations fail during content length calculation

Create a copy of the current RequestClient instance with an optional new base URL.

Parameters:

base_url
Optional[str]Defaults to None

New base URL for the cloned client. Defaults to the existing base URL.

Returns: RequestClient

A new instance with the same settings but an optional different base URL.

aistore.sdk.request_client.RequestClient.get_full_url(
path: str,
params: typing.Dict[str, typing.Any]
) -> str

Get the full URL to the path on the cluster with the given parameters.

Parameters:

path
str

Path on the cluster.

params
Dict[str, Any]

Query parameters to include.

Returns: str

URL including cluster base URL and parameters.

aistore.sdk.request_client.RequestClient.get_smap(
force_update: bool = False
) -> aistore.sdk.types.Smap

Return the smap.

aistore.sdk.request_client.RequestClient.request(
method: str,
path: str,
endpoint: str = None,
headers: typing.Dict[str, typing.Any] = None,
kwargs = {}
) -> requests.Response

Make a request with the request_client’s retry manager.

If the request is an HTTPS request with a payload (data), it uses _request_with_manual_redirect. Otherwise, it makes a direct call using the current session manager with _make_session_request.

Parameters:

method
str

HTTP method (e.g. POST, GET, PUT, DELETE).

path
str

URL path to call.

endpoint
strDefaults to None

Alternative endpoint for the AIS cluster (e.g. for connecting to a specific proxy).

headers
Dict[str, Any]Defaults to None

Extra headers to be passed with the request. Content-Type and User-Agent will be overridden.

**kwargs
optionalDefaults to {}

Optional keyword arguments to pass with the call to request.

Returns: Response

The HTTP response from the server.

aistore.sdk.request_client.RequestClient.request_deserialize(
method: str,
path: str,
res_model: typing.Type[aistore.sdk.request_client.T],
kwargs = {}
) -> aistore.sdk.request_client.T

Make a request and deserialize the response to a defined type.

Parameters:

method
str

HTTP method (e.g. POST, GET, PUT, DELETE).

path
str

URL path to call.

res_model
Type[T]

Resulting type to which the response should be deserialized.

**kwargs
optionalDefaults to {}

Optional keyword arguments to pass with the call to request.

Returns: T

Parsed result of the call to the API, as res_model.

aistore.sdk.request_client.T = TypeVar('T')
aistore.sdk.request_client.logger = get_logger(__name__)