provenaclient.clients.client_helpers
Created Date: Monday June 17th 2024 +1000 Author: Peter Baker —– Last Modified: Monday June 17th 2024 4:45:39 pm +1000 Modified By: Peter Baker —– Description: Helper methods for clients namely a standard interface ClientService along with reusable patterns to interact with the HTTPX L1 Layer —– HISTORY: Date By Comments ———- — ———————————————————
18-06-2024 | Peter Baker | Just noting I think we could streamline the helper functions a bit
Classes
This class interface just captures that the client has an instantiated auth |
Functions
High level helper function which |
|
|
High level helper function which |
|
High level helper function which |
High level helper function which |
|
High level helper function which |
|
High level helper function which |
|
|
High level helper function which |
High level helper function which |
|
High level helper function which |
|
A generic POST request method for endpoints where the response |
|
|
High level helper function which |
|
High level helper function which |
Module Contents
- class provenaclient.clients.client_helpers.ClientService[source]
Bases:
abc.ABC
This class interface just captures that the client has an instantiated auth manager which allows for helper functions abstracted for L2 clients.
- _config: provenaclient.utils.config.Config
- async provenaclient.clients.client_helpers.parsed_get_request_with_status(client: ClientService, params: Mapping[str, provenaclient.utils.helpers.ParamTypes | None] | None, url: str, error_message: str, model: provenaclient.utils.helpers.Type[provenaclient.utils.helpers.BaseModelType]) provenaclient.utils.helpers.BaseModelType [source]
High level helper function which
gets the auth
builds the filtered param list
makes get request
checks status/http codes
parses model etc
Returns the parsed validated, safe to use 200OK model result
- Parameters:
client (ClientService) – The client being used. Relies on client interface.
params (Optional[Mapping[str, Optional[ParamTypes]]]) – The params if any
url (str) – The url to make GET request to
error_message (str) – The error message to embed in other exceptions
model (Type[BaseModelType]) – Model to parse for response JSON
- Raises:
e – Exception depending on error
- Returns:
The specified parsed model
- Return type:
BaseModelType
- async provenaclient.clients.client_helpers.parsed_get_request(client: ClientService, params: Mapping[str, provenaclient.utils.helpers.ParamTypes | None] | None, url: str, error_message: str, model: provenaclient.utils.helpers.Type[provenaclient.utils.helpers.BaseModelType]) provenaclient.utils.helpers.BaseModelType [source]
High level helper function which
gets the auth
builds the filtered param list
makes get request
checks http codes
parses model etc
Returns the parsed validated, safe to use 200OK model result
- Parameters:
client (ClientService) – The client being used. Relies on client interface.
params (Optional[Mapping[str, Optional[ParamTypes]]]) – The params if any
url (str) – The url to make GET request to
error_message (str) – The error message to embed in other exceptions
model (Type[BaseModelType]) – Model to parse for response JSON
- Raises:
e – Exception depending on error
- Returns:
The specified parsed model
- Return type:
BaseModelType
- async provenaclient.clients.client_helpers.parsed_post_request(client: ClientService, params: Mapping[str, provenaclient.utils.helpers.ParamTypes | None] | None, json_body: provenaclient.utils.helpers.JsonData | None, url: str, error_message: str, model: provenaclient.utils.helpers.Type[provenaclient.utils.helpers.BaseModelType]) provenaclient.utils.helpers.BaseModelType [source]
High level helper function which
gets the auth
builds the filtered param list
makes POST request
checks http codes
parses model etc
Returns the parsed validated, safe to use 200OK model result
- Parameters:
client (ClientService) – The client being used. Relies on client interface.
params (Optional[Mapping[str, Optional[ParamTypes]]]) – The params if any
url (str) – The url to make POST request to
error_message (str) – The error message to embed in other exceptions
model (Type[BaseModelType]) – Model to parse for response JSON
json_body – Optional[JsonData]: JSON data to post if any
- Raises:
e – Exception depending on error
- Returns:
The specified parsed model
- Return type:
BaseModelType
- async provenaclient.clients.client_helpers.parsed_post_request_with_status(client: ClientService, params: Mapping[str, provenaclient.utils.helpers.ParamTypes | None] | None, json_body: provenaclient.utils.helpers.JsonData | None, url: str, error_message: str, model: provenaclient.utils.helpers.Type[provenaclient.utils.helpers.BaseModelType], files: provenaclient.utils.helpers.HttpxFileUpload | None = None) provenaclient.utils.helpers.BaseModelType [source]
High level helper function which
gets the auth
builds the filtered param list
makes POST request
checks http/status codes
parses model etc
Returns the parsed validated, safe to use 200OK model result
- Parameters:
client (ClientService) – The client being used. Relies on client interface.
params (Optional[Mapping[str, Optional[ParamTypes]]]) – The params if any
url (str) – The url to make POST request to
error_message (str) – The error message to embed in other exceptions
model (Type[BaseModelType]) – Model to parse for response JSON
json_body – Optional[JsonData]: JSON data to post if any
files – Optional[HttpxFileUpload]: A dictionary representing file(s) to be uploaded with the request. Each key in the dictionary is the name of the form field for the file according, to API specifications. For Provena it’s “csv_file” and and the value is a tuple of (filename, filedata, MIME type or media type).
- Raises:
e – Exception depending on error
- Returns:
The specified parsed model
- Return type:
BaseModelType
- async provenaclient.clients.client_helpers.parsed_delete_request_with_status(client: ClientService, params: Mapping[str, provenaclient.utils.helpers.ParamTypes | None] | None, url: str, error_message: str, model: provenaclient.utils.helpers.Type[provenaclient.utils.helpers.BaseModelType]) provenaclient.utils.helpers.BaseModelType [source]
High level helper function which
gets the auth
builds the filtered param list
makes DELETE request
checks http/status codes
parses model etc
Returns the parsed validated, safe to use 200OK model result
- Parameters:
client (ClientService) – The client being used. Relies on client interface.
params (Optional[Mapping[str, Optional[ParamTypes]]]) – The params if any
url (str) – The url to make POST request to
error_message (str) – The error message to embed in other exceptions
model (Type[BaseModelType]) – Model to parse for response JSON
json_body – Optional[JsonData]: JSON data to post if any
- Raises:
e – Exception depending on error
- Returns:
The specified parsed model
- Return type:
BaseModelType
- async provenaclient.clients.client_helpers.parsed_delete_request(client: ClientService, params: Mapping[str, provenaclient.utils.helpers.ParamTypes | None] | None, url: str, error_message: str, model: provenaclient.utils.helpers.Type[provenaclient.utils.helpers.BaseModelType]) provenaclient.utils.helpers.BaseModelType [source]
High level helper function which
gets the auth
builds the filtered param list
makes DELETE request
checks http/status codes
parses model etc
Returns the parsed validated, safe to use 200OK model result
- Parameters:
client (ClientService) – The client being used. Relies on client interface.
params (Optional[Mapping[str, Optional[ParamTypes]]]) – The params if any
url (str) – The url to make POST request to
error_message (str) – The error message to embed in other exceptions
model (Type[BaseModelType]) – Model to parse for response JSON
json_body – Optional[JsonData]: JSON data to post if any
- Raises:
e – Exception depending on error
- Returns:
The specified parsed model
- Return type:
BaseModelType
- async provenaclient.clients.client_helpers.parsed_put_request(client: ClientService, params: Mapping[str, provenaclient.utils.helpers.ParamTypes | None] | None, json_body: provenaclient.utils.helpers.JsonData | None, url: str, error_message: str, model: provenaclient.utils.helpers.Type[provenaclient.utils.helpers.BaseModelType]) provenaclient.utils.helpers.BaseModelType [source]
High level helper function which
gets the auth
builds the filtered param list
makes put request
checks http codes
parses model etc
Returns the parsed validated, safe to use 200OK model result
- Parameters:
client (ClientService) – The client being used. Relies on client interface.
params (Optional[Mapping[str, Optional[ParamTypes]]]) – The params if any
url (str) – The url to make put request to
error_message (str) – The error message to embed in other exceptions
model (Type[BaseModelType]) – Model to parse for response JSON
json_body – Optional[JsonData]: JSON data to put if any
- Raises:
e – Exception depending on error
- Returns:
The specified parsed model
- Return type:
BaseModelType
- async provenaclient.clients.client_helpers.parsed_put_request_with_status(client: ClientService, params: Mapping[str, provenaclient.utils.helpers.ParamTypes | None] | None, json_body: provenaclient.utils.helpers.JsonData | None, url: str, error_message: str, model: provenaclient.utils.helpers.Type[provenaclient.utils.helpers.BaseModelType]) provenaclient.utils.helpers.BaseModelType [source]
High level helper function which
gets the auth
builds the filtered param list
makes put request
checks http/status codes
parses model etc
Returns the parsed validated, safe to use 200OK model result
- Parameters:
client (ClientService) – The client being used. Relies on client interface.
params (Optional[Mapping[str, Optional[ParamTypes]]]) – The params if any
url (str) – The url to make put request to
error_message (str) – The error message to embed in other exceptions
model (Type[BaseModelType]) – Model to parse for response JSON
json_body – Optional[JsonData]: JSON data to put if any
- Raises:
e – Exception depending on error
- Returns:
The specified parsed model
- Return type:
BaseModelType
- async provenaclient.clients.client_helpers.validated_get_request(client: ClientService, params: Mapping[str, provenaclient.utils.helpers.ParamTypes | None] | None, url: str, error_message: str) provenaclient.utils.helpers.Response [source]
High level helper function which
gets the auth
builds the filtered param list
makes get request
checks http codes
This method does not do any base model parsing and only checks HTTP status codes.
- Parameters:
client (ClientService) – The client being used. Relies on client interface.
params (Optional[Mapping[str, Optional[ParamTypes]]]) – The params if any
url (str) – The url to make GET request to
error_message (str) – The error message to embed in other exceptions
- Raises:
e – Exception depending on error
- Returns:
None
- async provenaclient.clients.client_helpers.validated_post_request(client: ClientService, params: Mapping[str, provenaclient.utils.helpers.ParamTypes | None] | None, json_body: provenaclient.utils.helpers.JsonData | None, url: str, error_message: str, headers: Dict[str, provenaclient.utils.helpers.Any] | None = None) provenaclient.utils.helpers.Response [source]
A generic POST request method for endpoints where the response does not parse into a Pydantic model. This method handles cases like file downloads or when raw data is expected.
- Parameters:
client (ClientService) – The client being used. Relies on client interface.
params (Optional[Mapping[str, Optional[ParamTypes]]]) – The params if any.
json_body (Optional[JsonData]) – JSON data to send with the request, if any.
url (str) – The URL to make the POST request to.
error_message (str) – The error message to embed in other exceptions.
headers – The headers to include in hte POST request, if any.
- Raises:
e – Exception depending on the error.
- Returns:
The raw HTTP response object for further processing.
- Return type:
Response
- async provenaclient.clients.client_helpers.parsed_post_request_none_return(client: ClientService, params: Mapping[str, provenaclient.utils.helpers.ParamTypes | None] | None, json_body: provenaclient.utils.helpers.JsonData | None, url: str, error_message: str) None [source]
High level helper function which
gets the auth
builds the filtered param list
makes POST request
checks http codes
This method does not do any base model parsing and only checks HTTP status codes.
- Parameters:
client (ClientService) – The client being used. Relies on client interface.
params (Optional[Mapping[str, Optional[ParamTypes]]]) – The params if any
url (str) – The url to make POST request to
error_message (str) – The error message to embed in other exceptions
json_body – Optional[JsonData]: JSON data to post if any
- Raises:
e – Exception depending on error
- Returns:
None
- async provenaclient.clients.client_helpers.parsed_delete_request_non_return(client: ClientService, params: Mapping[str, provenaclient.utils.helpers.ParamTypes | None] | None, url: str, error_message: str) None [source]
High level helper function which
gets the auth
builds the filtered param list
makes DELETE request
checks http/status codes
This method does not do any base model parsing and only checks HTTP status codes.
- Parameters:
client (ClientService) – The client being used. Relies on client interface.
params (Optional[Mapping[str, Optional[ParamTypes]]]) – The params if any
url (str) – The url to make POST request to
error_message (str) – The error message to embed in other exceptions
- Raises:
e – Exception depending on error
- Returns:
None