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 and client_secret parameters to obtain a new access token. (A refresh token is not included.)

Parameters:
urlstr

Base path for the server to call. The default is 'https://127.0.0.1:8443/hps'.

usernamestr, optional

Username.

passwordstr, optional

Password.

realmstr, optional

Keycloak realm. The default is 'rep'.

grant_typestr, optional

Authentication method. The default is 'password'.

scopestr, optional

String containing one or more requested scopes. The default is 'openid'.

client_idstr, optional

Client type. The default is 'rep-cli'.

client_secretstr, optional

Client secret. The default is None.

access_tokenstr, optional

Access token.

refresh_tokenstr, optional

Refresh token.

auth_urlstr, 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 is True.

verifyUnion[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.

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

Client.refresh_access_token()

Request a new access token

Attributes