Base API class
Module for the base class handling the access to the Database API.
- class owimetadatabase_preprocessor.io.API(api_root: str = 'https://owimetadatabase.owilab.be/api/v1', token: str | None = None, uname: str | None = None, password: str | None = None, **kwargs)
Bases:
object
Base API class handling user access information to the Database API.
- __init__(api_root: str = 'https://owimetadatabase.owilab.be/api/v1', token: str | None = None, uname: str | None = None, password: str | None = None, **kwargs) None
Create an instance of the API class with the required parameters.
- Parameters:
api_root – Optional: root URL of the API endpoint, the default working database url is provided.
token – Optional: token to access the API.
uname – Optional: username to access the API.
password – Optional: password to access the API.
kwargs – Additional parameters to pass to the API.
- Returns:
None
- send_request(url_data_type: str, url_params: Dict[str, str]) Response
Handle sending appropriate request according to the type of authentication.
- Parameters:
url_data_type – Type of the data we want to request (according to database model).
url_params – Parameters to send with the request to the database.
- Returns:
An instance of the Response object.
- static check_request_health(resp: Response) None
Check status code of the response to request and provide detials if unexpected.
- Parameters:
resp – Instance of the Response object.
- Returns:
None
- static output_to_df(response: Response) DataFrame
Transform output to Pandas dataframe.
- Parameters:
response – Raw output of the sent request.
- Returns:
Pandas dataframe of the data from the output.
- static postprocess_data(df: DataFrame, output_type: str) Dict[str, bool | int64 | None]
Process dataframe information to extarct the necessary additional data.
- Parameters:
df – Dataframe of the output data.
output_type – Expected type (amount) of the data extracted.
- Returns:
Dictionary of the additional data extracted.
- process_data(url_data_type: str, url_params: Dict[str, str], output_type: str) Tuple[DataFrame, Dict[str, bool | int64 | None]]
Process output data according to specified request parameters.
- Parameters:
url_data_type – Type of the data we want to request (according to database model).
url_params – Parameters to send with the request to the database.
output_type – Expected type (amount) of the data extracted.
- Returns:
A tuple of dataframe with the requested data and additional data from postprocessing.