ds_stoa.manager.client ====================== .. py:module:: ds_stoa.manager.client .. autoapi-nested-parse:: manager.client.py This module contains the Stoa class, which is a core component of our package. The Stoa class offers functionality for fetching, signing, authenticating, and ordering messages, which are essential operations for communication and data exchange within our system. Attributes ---------- .. autoapisummary:: ds_stoa.manager.client.LOGGER Classes ------- .. autoapisummary:: ds_stoa.manager.client.StoaClient Functions --------- .. autoapisummary:: ds_stoa.manager.client.oauth2 ds_stoa.manager.client.rest ds_stoa.manager.client.fetch ds_stoa.manager.client.order ds_stoa.manager.client.sign ds_stoa.manager.client.ensure_authenticated Module Contents --------------- .. py:function:: oauth2(client_id: str, client_secret: str) -> str Authenticates an application and retrieves an access token. :param client_id: The Client ID. :type client_id: str :param client_secret: The Client Secret. :type client_secret: str :returns: An access token indicating successful authentication. :rtype: str **Example**:: >>> oauth2('client_id', 'client_secret') 'access_token_value' .. py:function:: rest(email: str, password: str) -> str Authenticates a user and retrieves an access token. :param email: The email of the user. :type email: str :param password: The password of the user. :type password: str :returns: An access token indicating successful authentication. :rtype: str **Example**:: >>> rest('user@example.com', 'secret') 'access_token_value' .. py:function:: fetch(pre_signed_urls: Dict) -> pandas.DataFrame Fetch data from a collection of pre-signed URLs in parallel and consolidate into a single DataFrame. :param pre_signed_urls: A dictionary where keys are identifiers and values are pre-signed URLs. :type pre_signed_urls: Dict[str, str] :return: A consolidated Pandas DataFrame containing data from all fetched URLs. :rtype: pd.DataFrame **Example**:: pre_signed_urls = { "file1": "http://example.com/data1.parquet", "file2": "http://example.com/data2.parquet", } dataframe = fetch(pre_signed_urls) .. py:function:: order(token: str, params: Dict) -> List[str] Send order request to Stoa API. :param token: Authentication token required for the API request. :param params: Parameters for the order request, such as product ID and quantity. :return: A dictionary containing the response from the Stoa API. **Example**:: >>> order(token=token, params=params) ["12345.snappy.parquet", "67890.snappy.parquet"] .. py:function:: sign(token: str, params: Dict) -> str Generate a pre-signed URL for accessing data in the GraspDP datalake. :param token: Authentication token required for generating the pre-signed URL. :param params: Parameters for the request, typically including identifiers for the data to be accessed. :return: A string containing the pre-signed URL. :raises ValueError: If the pre-signed URL is not found. **Example**:: >>> sign(token=token, params=params) "https://fmdp.io/stoa-dev/sign/12345" .. py:data:: LOGGER .. py:function:: ensure_authenticated(method) -> Callable[Ellipsis, Any] .. py:class:: StoaClient(authentication: Literal['rest', 'oauth2'], product_group_name: str, product_name: str, workspace: Literal['apps', 'cart'], owner_id: str, version: str = '1.0', offset: int = 0, limit: int = 20, ascending: bool = False, email: Optional[str] = None, password: Optional[str] = None, client_id: Optional[str] = None, client_secret: Optional[str] = None) The Stoa class provides methods for handling messages within our system. These methods include operations for fetching, signing, authenticating, and ordering messages. .. py:property:: token :type: str Token getter that retrieves the current access token. :return: The access token. :raises ValueError: If the access token is missing. .. py:property:: order_ids :type: List[str] Order IDs getter that retrieves the current list of order IDs. :return: List of order IDs. :raises ValueError: If no order IDs are found. .. py:property:: signatures :type: Dict Signatures getter that retrieves the current dictionary of signatures. :return: Dictionary of signatures. :raises ValueError: If no signatures are found. .. py:method:: authenticate() -> None Authenticates a message to verify its origin. This method is used to check if a message came from a trusted source before it is processed by the system. :return: The access token for the authenticated request. :rtype: str :raises NotImplementedError: If the authentication method is invalid. **example**:: >>> stoa = StoaClient(**params) >>> stoa.authenticate() >>> assert stoa.token .. py:method:: is_authenticated() -> bool Checks if a message is authenticated. This method is used to verify that a message has been authenticated before it is processed by the system. :return: True if the message is authenticated, False otherwise. :rtype: bool **example**:: >>> stoa = StoaClient(**params) >>> stoa.authenticate() >>> assert stoa.is_authenticated() .. py:method:: order() -> List[str] Orders a message based on predefined rules. This method is used to sort or arrange messages according to certain criteria before they are processed by the system. :return: Ordered keys. :rtype: List :raises ValueError: If the workspace is invalid. **example**:: >>> stoa = StoaClient(**params) >>> stoa.order() >>> assert stoa.order_ids .. py:method:: sign() -> Dict Signs a message to ensure its integrity and authenticity. This method is used to add a layer of security to our messages, making sure they are not tampered with during transit. :return: The pre-signed URLs for the messages. :rtype: Dict :raises ValueError: If the order IDs are missing. **example**:: >>> stoa = StoaClient(**params) >>> stoa.order() >>> stoa.sign() >>> assert stoa.signatures .. py:method:: fetch(format: Literal['json', 'dataframe']) -> Union[List[Dict], pandas.DataFrame] Fetches a message from a predefined source. This method is responsible for retrieving messages that are to be processed by the system. :param format: The format in which to return the fetched data. :return: The fetched data in the specified format. :rtype: List[Dict] :raises ValueError: If the format is invalid. **example**:: >>> stoa = StoaClient(**params) >>> stoa.fetch(format="json")