Python API Wrapper - Client
IBM PAIRS RESTful API wrapper: A Python module to access PAIRS’s core API to load data into Python compatible data formats.
Copyright 2019-2021 Physical Analytics, IBM Research All Rights Reserved.
SPDX-License-Identifier: BSD-3-Clause
- class client.Client(host: Optional[str] = None, headers: Optional[dict] = None, authentication=None, body: Optional[str] = None, client_id: Optional[str] = None, tenant_id: Optional[str] = None, legacy: Optional[bool] = None)
A client wrapper for interaction with IBM PAIRS.
- Parameters
host (str) – IBM PAIRS host.
headers (dict) – A dictionary of request headers.
authentication (ibmpairs.authentication.Oauth2 or ibmpairs.authentication.Basic) – An authentication object.
body (str) – A message body.
client_id (str) – A client id for the authentication system, defaults to ‘ibm-pairs’ if legacy.
tenant_id (str) – IBM EIS GA API Connect Tenant Id
legacy (bool) – IBM EIS GA Legacy Environment selector override
- async async_get(url, session: Optional[ClientSession] = None, authentication=None, headers=None, verify=None, response_type='json')
A wrapper method around aiohttp.ClientSession.get.
- Parameters
url (str) – A URL to GET.
session (aiohttp.ClientSession) – An aiohttp.ClientSession to use for a GET request.
authentication (ibmpairs.authentication.Basic or ibmpairs.authentication.OAuth2) – A username for the user.
headers (dict) – A dictionary of request headers.
verify (bool) – Verify SSL.
response_type (str) – A response type, defaults to json.
- Returns
An ibmpairs.client.ClientResponse object.
- Return type
ibmpairs.client.ClientResponse
- async async_post(url, body, session: Optional[ClientSession] = None, authentication=None, headers=None, verify=None)
A wrapper method around aiohttp.ClientSession.post.
- Parameters
url (str) – A URL to POST.
body (Any) – A body for the POST request.
session (aiohttp.ClientSession) – An aiohttp.ClientSession to use for a get request.
authentication (ibmpairs.authentication.Basic or ibmpairs.authentication.OAuth2) – A username for the user.
headers (dict) – A dictionary of request headers.
verify (bool) – Verify SSL.
- Returns
An ibmpairs.client.ClientResponse object.
- Return type
ibmpairs.client.ClientResponse
- static authentication_mode(a)
A wrapper method to determine authentication type.
- Parameters
a (Any) – authentication
- Returns
An authentication type string.
- Return type
str
- delete(url, headers=None, verify=True)
A wrapper method around requests.delete.
- Parameters
url (str) – A URL to DELETE.
headers (dict) – A dictionary of request headers.
verify (bool) – Verify SSL.
- Returns
A requests.Response object.
- Return type
requests.Response
- get(url, headers=None, verify=True)
A wrapper method around requests.get.
- Parameters
url (str) – A URL to GET.
headers (dict) – A dictionary of request headers.
verify (bool) – Verify SSL.
- Returns
A requests.Response object.
- Return type
requests.Response
- post(url, body, headers=None, verify=True)
A wrapper method around requests.post.
- Parameters
url (str) – A URL to POST.
body (Any) – A body for the POST request.
headers (dict) – A dictionary of request headers.
verify (bool) – Verify SSL.
- Returns
A requests.Response object.
- Return type
requests.Response
- put(url, body=None, headers=None, verify=True)
A wrapper method around requests.put.
- Parameters
url (str) – A URL to PUT.
body (Any) – A body for the PUT request.
headers (dict) – A dictionary of request headers.
verify (bool) – Verify SSL.
- Returns
A requests.Response object.
- Return type
requests.Response
- session(authentication=None, headers=None, verify=None)
A wrapper method around aiohttp.ClientSession.
- Parameters
authentication (ibmpairs.authentication.Basic or ibmpairs.authentication.OAuth2) – A username for the user.
headers (dict) – A dictionary of request headers.
verify (bool) – Verify SSL.
- Returns
A aiohttp.ClientSession using the attributes provided.
- Return type
aiohttp.ClientSession
- class client.ClientResponse(status: Optional[int] = None, body: Optional[str] = None)
A representation of a client response.
- Parameters
status – A response status.
body (str or bytes) – A response body.
- client.get_client(host: Optional[str] = None, username: Optional[str] = None, api_key: Optional[str] = None, api_key_file: str = 'auth/oauth2.txt', client_id: Optional[str] = None, endpoint: Optional[str] = None, jwt_token: Optional[str] = None, iam_endpoint: str = 'iam.cloud.ibm.com', org_id: Optional[str] = None, tenant_id: Optional[str] = None, headers: Optional[dict] = None, body: Optional[str] = None, password: Optional[str] = None, password_file: Optional[str] = None, legacy: Optional[bool] = None)
Gets either a authentication.Basic or authentication.OAuth2 from authentication credentials.
- Parameters
host (str) – IBM PAIRS host
username (str) – IBM PAIRS username
api_key (str) – IBM PAIRS API key
api_key_file (str) – IBM PAIRS API key file, defaults to auth/oauth2.txt
client_id (str) – A client id for the authentication system, defaults to ‘ibm-pairs’ if legacy.
endpoint (str) – The authentication endpoint.
jwt_token (str) – A jwt token for authentication.
iam_endpoint (str) – IBM Cloud IAM Endpoint
org_id (str) – IBM EIS GA API Connect Org Id
tenant_id (str) – IBM EIS GA API Connect Tenant Id
password (str) – IBM PAIRS password
password_file (str) – IBM PAIRS password file, defaults to auth/basic.txt
legacy (bool) – IBM EIS GA Legacy Environment selector override
- Return type
- Raises
Exception – if authentication.Basic or authentication.OAuth2 raise an error