client.client#

This module provides the Python client to the HPS data transfer APIs.

Attributes#

Classes#

MonitorState

Monitor and track state of worker binary.

ClientBase

Provide the Python client to the HPS data transfer APIs.

AsyncClient

An async interface to the Python client to the HPS data transfer APIs.

Client

Provide the Python client to the HPS data transfer APIs.

Functions#

bin_in_use(bin_path)

Check if a binary is in use.

Module Contents#

client.client.logger#
client.client.log#
client.client.bin_in_use(bin_path)#

Check if a binary is in use.

class client.client.MonitorState#

Monitor and track state of worker binary.

_sleep_not_started = 2#
_sleep_while_running = 5#
property sleep_for#
reset()#
mark_ready(ready)#

Mark worker as ready or not ready.

mark_failed(exc=None, binary=None)#

Mark worker as failed.

report(binary)#

Report worker status.

class client.client.ClientBase(bin_config: ansys.hps.data_transfer.client.binary.BinaryConfig = None, download_dir: str = 'dt_download', clean=False, clean_dev=True, check_in_use=True, timeout=60.0, retries=10)#

Provide the Python client to the HPS data transfer APIs.

This class uses the provided credentials to create and store an authorized requests.Session object.

Parameters:
bin_config: BinaryConfig

BinaryConfig object, Default is None

download_dir: str

download dir path. Default is None

clean: bool

If True, cleans download_dir path. Default is False.

clean_dev: bool

If True, downloads binary from dev branch. Default is True.

check_in_use: bool

If True, checks if binary is in use and skips downloading new binary. Default is True.

timeout: float

Default is 60.0

retries: int

Default is 10

Examples

Create a client object and connect to HPS data transfer with a access_token.

>>> from ansys.hps.data_transfer.client import Client
>>> token = authenticate(username=username, password=password, verify=False, url=auth_url)
>>> token = token.get("access_token", None)
>>> client = Client(clean=True)
>>> client.binary_config.update(
        verbosity=3,
        debug=False,
        insecure=True,
        token=token,
        data_transfer_url=dt_url,
    )
>>> client.start()
class Meta#
is_async = False#
_bin_config#
_download_dir = 'dt_download'#
_clean = False#
_clean_dev = True#
_check_in_use = True#
_timeout = 60.0#
property retries#

Return the number of retries.

_session = None#
binary = None#
_monitor_stop = None#
_monitor_state#
__getstate__()#
__setstate__(state)#
property binary_config#

Return binary config.

property base_api_url#

Return api url from config.

property session#

Return a session object. Creates a new one if one is not already created.

property is_started#

Return True if binary is up and running.

property timeout#

Return the timeout for the session.

start()#

Start client session using binary config credentials.

stop(wait=5.0)#

Stop client session.

_platform()#
_prepare_bin_path(build_info)#
_check_binary(build_info, bin_path)#

Check if there is a need to download the binary.

_prepare_platform_binary()#
_create_session(url: str, *, sync: bool = True)#
_on_port_changed(port)#
_on_process_died(ret_code)#
class client.client.AsyncClient(*args, **kwargs)#

Bases: ClientBase

An async interface to the Python client to the HPS data transfer APIs.

class Meta#

Bases: ClientBase

is_async = True#
async start()#

Start async binary worker.

async stop(wait=5.0)#

Stop async binary worker.

async wait(timeout: float = 60.0, sleep=0.5)#

Wait on async binary worker.

_update_token()#
async _monitor()#
class client.client.Client(*args, **kwargs)#

Bases: ClientBase

Provide the Python client to the HPS data transfer APIs. This class uses the provided credentials to create and store an authorized requests.Session object.

class Meta#

Bases: ClientBase

is_async = False#
_monitor_thread = None#
__getstate__()#
__setstate__(state)#
start()#

Start client session using binary config credentials.

stop(wait=5.0)#

Stop client session.

wait(timeout: float = 60.0, sleep=0.5)#

Wait on worker binary to start.

_update_token()#
_monitor()#