Client#
- class ansys.hps.client.client.Client(url='https://127.0.0.1:8443/hps', username=None, password=None, *, realm='rep', grant_type=None, scope='openid', client_id='rep-cli', client_secret=None, access_token=None, refresh_token=None, all_fields=True, verify=None, disable_security_warnings=True, **kwargs)#
Provides the Python client to the HPS APIs.
This class uses the provided credentials to create and store an authorized
requests.Session
object.The following alternative authentication workflows are supported and evaluated in the order listed:
Access token: No authentication is needed.
Username and password: The client connects to the OAuth server and requests access and refresh tokens.
Refresh token: The client connects to the OAuth server and requests a new access token.
Client credentials: The client authenticates with the
client_id
andclient_secret
parameters to obtain a new access token. (A refresh token is not included.)
- Parameters:
- url
str
Base path for the server to call. The default is
'https://127.0.0.1:8443/hps'
.- username
str
,optional
Username.
- password
str
,optional
Password.
- realm
str
,optional
Keycloak realm. The default is
'rep'
.- grant_type
str
,optional
Authentication method. The default is
'password'
.- scope
str
,optional
String containing one or more requested scopes. The default is
'openid'
.- client_id
str
,optional
Client type. The default is
'rep-cli'
.- client_secret
str
,optional
Client secret. The default is
None
.- access_token
str
,optional
Access token.
- refresh_token
str
,optional
Refresh token.
- auth_url
str
,optional
- all_fieldsbool,
optional
Whether to apply the
fields="all"
query parameter to all requests so that all available fields are returned for the requested resources. The default isTrue
.- verify
Union
[bool,str
],optional
If a Boolean, whether to verify the server’s TLS certificate. The default is ``None`, which disables certificate validation and warns the user about it. If a string, the path to the CA bundle to use. For more information, see the
requests.Session
documentation.- disable_security_warningsbool,
optional
Whether to disable urllib3 warnings about insecure HTTPS requests. The default is
True
. For more information, see urllib3 documentation about TLS warnings.
- url
Examples
Create a client object and connect to HPS with a username and password.
>>> from ansys.hps.client import Client >>> cl = Client( ... url="https://localhost:8443/hps", ... username="repuser", ... password="repuser" ... )
Create a client object and connect to HPS with a refresh token.
>>> cl = Client( ... url="https://localhost:8443/hps", ... username="repuser", ... refresh_token="eyJhbGciOiJIUzI1NiIsInR5cC..." >>> )
Methods
Request a new access token
Attributes