wallaroo.wallaroo_ml_ops_api_client.client API documentation

# wallaroo.wallaroo_ml_ops_api_client.client

View Source

     1import ssl
     2from typing import Dict, Union
     3
     4import attr
     5
     6
     7@attr.s(auto_attribs=True)
     8class Client:
     9    """ A class for keeping track of data related to the API """
    10
    11    base_url: str
    12    cookies: Dict[str, str] = attr.ib(factory=dict, kw_only=True)
    13    headers: Dict[str, str] = attr.ib(factory=dict, kw_only=True)
    14    timeout: float = attr.ib(5.0, kw_only=True)
    15    verify_ssl: Union[str, bool, ssl.SSLContext] = attr.ib(True, kw_only=True)
    16
    17    def get_headers(self) -> Dict[str, str]:
    18        """ Get headers to be used in all endpoints """
    19        return {**self.headers}
    20
    21    def with_headers(self, headers: Dict[str, str]) -> "Client":
    22        """ Get a new client matching this one with additional headers """
    23        return attr.evolve(self, headers={**self.headers, **headers})
    24
    25    def get_cookies(self) -> Dict[str, str]:
    26        return {**self.cookies}
    27
    28    def with_cookies(self, cookies: Dict[str, str]) -> "Client":
    29        """ Get a new client matching this one with additional cookies """
    30        return attr.evolve(self, cookies={**self.cookies, **cookies})
    31
    32    def get_timeout(self) -> float:
    33        return self.timeout
    34
    35    def with_timeout(self, timeout: float) -> "Client":
    36        """ Get a new client matching this one with a new timeout (in seconds) """
    37        return attr.evolve(self, timeout=timeout)
    38
    39@attr.s(auto_attribs=True)
    40class AuthenticatedClient(Client):
    41    """ A Client which has been authenticated for use on secured endpoints """
    42
    43    token: str
    44
    45    def get_headers(self) -> Dict[str, str]:
    46        """ Get headers to be used in authenticated endpoints """
    47        return {"Authorization": f"Bearer {self.token}", **self.headers}

@attr.s(auto_attribs=True)
class Client: View Source

     8@attr.s(auto_attribs=True)
     9class Client:
    10    """ A class for keeping track of data related to the API """
    11
    12    base_url: str
    13    cookies: Dict[str, str] = attr.ib(factory=dict, kw_only=True)
    14    headers: Dict[str, str] = attr.ib(factory=dict, kw_only=True)
    15    timeout: float = attr.ib(5.0, kw_only=True)
    16    verify_ssl: Union[str, bool, ssl.SSLContext] = attr.ib(True, kw_only=True)
    17
    18    def get_headers(self) -> Dict[str, str]:
    19        """ Get headers to be used in all endpoints """
    20        return {**self.headers}
    21
    22    def with_headers(self, headers: Dict[str, str]) -> "Client":
    23        """ Get a new client matching this one with additional headers """
    24        return attr.evolve(self, headers={**self.headers, **headers})
    25
    26    def get_cookies(self) -> Dict[str, str]:
    27        return {**self.cookies}
    28
    29    def with_cookies(self, cookies: Dict[str, str]) -> "Client":
    30        """ Get a new client matching this one with additional cookies """
    31        return attr.evolve(self, cookies={**self.cookies, **cookies})
    32
    33    def get_timeout(self) -> float:
    34        return self.timeout
    35
    36    def with_timeout(self, timeout: float) -> "Client":
    37        """ Get a new client matching this one with a new timeout (in seconds) """
    38        return attr.evolve(self, timeout=timeout)

A class for keeping track of data related to the API

Client( base_url: str, *, cookies: Dict[str, str] = NOTHING, headers: Dict[str, str] = NOTHING, timeout: float = 5.0, verify_ssl: Union[str, bool, ssl.SSLContext] = True) View Source

     2def __init__(self, base_url, *, cookies=NOTHING, headers=NOTHING, timeout=attr_dict['timeout'].default, verify_ssl=attr_dict['verify_ssl'].default):
     3    self.base_url = base_url
     4    if cookies is not NOTHING:
     5        self.cookies = cookies
     6    else:
     7        self.cookies = __attr_factory_cookies()
     8    if headers is not NOTHING:
     9        self.headers = headers
    10    else:
    11        self.headers = __attr_factory_headers()
    12    self.timeout = timeout
    13    self.verify_ssl = verify_ssl

Method generated by attrs for class Client.

def get_headers(self) -> Dict[str, str]: View Source

    18    def get_headers(self) -> Dict[str, str]:
    19        """ Get headers to be used in all endpoints """
    20        return {**self.headers}

Get headers to be used in all endpoints

def with_headers( self, headers: Dict[str, str]) -> wallaroo.wallaroo_ml_ops_api_client.client.Client: View Source

    22    def with_headers(self, headers: Dict[str, str]) -> "Client":
    23        """ Get a new client matching this one with additional headers """
    24        return attr.evolve(self, headers={**self.headers, **headers})

Get a new client matching this one with additional headers

def get_cookies(self) -> Dict[str, str]: View Source

    26    def get_cookies(self) -> Dict[str, str]:
    27        return {**self.cookies}

def with_cookies( self, cookies: Dict[str, str]) -> wallaroo.wallaroo_ml_ops_api_client.client.Client: View Source

    29    def with_cookies(self, cookies: Dict[str, str]) -> "Client":
    30        """ Get a new client matching this one with additional cookies """
    31        return attr.evolve(self, cookies={**self.cookies, **cookies})

Get a new client matching this one with additional cookies

def get_timeout(self) -> float: View Source

    33    def get_timeout(self) -> float:
    34        return self.timeout

def with_timeout( self, timeout: float) -> wallaroo.wallaroo_ml_ops_api_client.client.Client: View Source

    36    def with_timeout(self, timeout: float) -> "Client":
    37        """ Get a new client matching this one with a new timeout (in seconds) """
    38        return attr.evolve(self, timeout=timeout)

Get a new client matching this one with a new timeout (in seconds)

@attr.s(auto_attribs=True)
class AuthenticatedClient(Client): View Source

    40@attr.s(auto_attribs=True)
    41class AuthenticatedClient(Client):
    42    """ A Client which has been authenticated for use on secured endpoints """
    43
    44    token: str
    45
    46    def get_headers(self) -> Dict[str, str]:
    47        """ Get headers to be used in authenticated endpoints """
    48        return {"Authorization": f"Bearer {self.token}", **self.headers}

A Client which has been authenticated for use on secured endpoints

AuthenticatedClient( base_url: str, token: str, *, cookies: Dict[str, str] = NOTHING, headers: Dict[str, str] = NOTHING, timeout: float = 5.0, verify_ssl: Union[str, bool, ssl.SSLContext] = True) View Source

     2def __init__(self, base_url, token, *, cookies=NOTHING, headers=NOTHING, timeout=attr_dict['timeout'].default, verify_ssl=attr_dict['verify_ssl'].default):
     3    self.base_url = base_url
     4    if cookies is not NOTHING:
     5        self.cookies = cookies
     6    else:
     7        self.cookies = __attr_factory_cookies()
     8    if headers is not NOTHING:
     9        self.headers = headers
    10    else:
    11        self.headers = __attr_factory_headers()
    12    self.timeout = timeout
    13    self.verify_ssl = verify_ssl
    14    self.token = token

Method generated by attrs for class AuthenticatedClient.

def get_headers(self) -> Dict[str, str]: View Source

    46    def get_headers(self) -> Dict[str, str]:
    47        """ Get headers to be used in authenticated endpoints """
    48        return {"Authorization": f"Bearer {self.token}", **self.headers}

Get headers to be used in authenticated endpoints

##### Inherited Members

Client
  with_headers
  get_cookies
  with_cookies
  get_timeout
  with_timeout