The client.py module#

Summary#

MonitorState

Provides for monitoring and tracking the state of the worker binary.

ClientBase

Provides the Python client to the HPS data transfer APIs.

AsyncClient

Provides an async interface to the Python client to the HPS data transfer APIs.

Client

Provides the Python client to the HPS data transfer APIs.

bin_in_use

Check if a binary is in use.

logger

log

Description#

Provides the Python client to the HPS data transfer APIs.

Module detail#

class client.MonitorState#

Provides for monitoring and tracking the state of the worker binary.

Overview#

reset

Reset the monitor state to the initial values.

mark_ready

Mark the worker as ready or not ready.

mark_failed

Mark the worker as failed.

report

Report the worker status.

sleep_for

Sleep time based on the worker state.

Import detail#

from ansys.hps.data_transfer.client.client import MonitorState

Property detail#

property MonitorState.sleep_for#

Sleep time based on the worker state.

Method detail#

MonitorState.reset()#

Reset the monitor state to the initial values.

MonitorState.mark_ready(ready)#

Mark the worker as ready or not ready.

MonitorState.mark_failed(exc=None, binary=None)#

Mark the worker as failed.

MonitorState.report(binary)#

Report the worker status.

class MonitorState.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)#

Provides 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, default: None

Binary configuration. If no configuration is provided, a default BinaryConfig object is created.

download_dir: str, default: “dt_download”

Path to the download directory.

clean: bool, default: False

Whether to clean the path to the download directory.

clean_dev: bool, default: True

Whether to clean the path to the download directory if the binary is from the development branch.

check_in_use: bool, default: True

Whether to check if the binary is in use and skip downloading a new binary.

timeout: float, default: 60.0

Timeout for the session. This is the maximum time to wait for a response from the server.

retries: int, default: 1

Number of times to retry the operation.

Examples:
——–
Create a client object and connect to HPS data transfer with an 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()

Overview#

start

Start the client session using the binary configuration credentials.

stop

Stop the client session.

retries

Number of retries.

binary_config

Binary configuration.

base_api_url

API URL from the configuration.

session

Session object. If one does not exist, a new one is created.

is_started

Flag indicating if the binary is up and running.

timeout

Timeout for the session.

Import detail#

from ansys.hps.data_transfer.client.client import ClientBase

Property detail#

property ClientBase.retries#

Number of retries.

property ClientBase.binary_config#

Binary configuration.

property ClientBase.base_api_url#

API URL from the configuration.

property ClientBase.session#

Session object. If one does not exist, a new one is created.

property ClientBase.is_started#

Flag indicating if the binary is up and running.

property ClientBase.timeout#

Timeout for the session.

Attribute detail#

ClientBase.binary = None#

Method detail#

ClientBase.start()#

Start the client session using the binary configuration credentials.

ClientBase.stop(wait=5.0)#

Stop the client session.

class ClientBase.AsyncClient(*args, **kwargs)#

Provides an async interface to the Python client to the HPS data transfer APIs.

Overview#

start

Start the async binary worker.

stop

Stop the async binary worker.

wait

Wait on the async binary worker.

Import detail#

from ansys.hps.data_transfer.client.client import AsyncClient

Method detail#

async AsyncClient.start()#

Start the async binary worker.

async AsyncClient.stop(wait=5.0)#

Stop the async binary worker.

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

Wait on the async binary worker.

class AsyncClient.Client(*args, **kwargs)#

Provides the Python client to the HPS data transfer APIs.

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

Overview#

start

Start the client session using the binary configuration credentials.

stop

Stop the client session.

wait

Wait on the worker binary to start.

Import detail#

from ansys.hps.data_transfer.client.client import Client

Method detail#

Client.start()#

Start the client session using the binary configuration credentials.

Client.stop(wait=5.0)#

Stop the client session.

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

Wait on the worker binary to start.

Client.bin_in_use(bin_path)#

Check if a binary is in use.

Client.logger#
Client.log#