Client API#
This section documents GLOW’s Client API which enable programs, including a Dash UI server, to access a remote GLOW server that provides the guided workflow service for a given GLOW solution (a guided workflow application).
- class ansys.saf.glow.client.AbstractStoragePath#
Bases:
objectA base class for representing paths to folders, directories, files or blobs in a hierarchical storage scheme, such as an OS Filesystem or cloud storage.
- as_uri() str#
Return a URI that refers to the entity referenced by the path.
- Returns:
strA URI that refers to the entity referenced by the path.
- copy(destination: AbstractStoragePath) None#
Copy the referenced entity to the given destination directory or folder. The destination directory and any missing parents will be created if they do not exist.
- Parameters:
- destination
AbstractStoragePath The directory or folder where the referenced entity will be copied.
- destination
- copyfileobj(fileobj) None#
Create or replace of the referenced entity with the contents of the file-like object
fileobj.- Parameters:
- fileobj
file like object The object that is the source of data to become the content of the referenced entity.
- fileobj
- property exists: bool#
Whether the entity referenced by the path exists.
- Returns:
- bool
Whether the entity referenced by the path exists.
- glob(pattern: str) list[AbstractStoragePath]#
Return the paths of entities with in the referenced fdirectory or folder that match the given pattern.
- Parameters:
- pattern
str The pattern that is used to match entities within the referenced directory. The pattern can include
*as a wild match and**which matches directories recursively.
- pattern
- Returns:
list of AbstractStoragePathThe paths of entities with in the referenced directory or folder that match the given pattern.
- is_dir() bool#
Return whether the path refers to a directory or folder.
- Returns:
- bool
Whether the path refers to a directory or folder.
- is_file() bool#
Return whether the path refers to a file or blob.
- Returns:
- bool
Whether the path refers to a file or blob.
- iterdir() Iterator[AbstractStoragePath]#
Return an iterator over the entities that exist on the directory or folder referenced by the path.
- Returns:
Iterator over AbstractStoragePathThe entities that exist on the directory or folder referenced by the path.
- property name: str#
The name of the entity referenced by the path.
- Returns:
strThe name of the entity referenced by the path.
- property parent: AbstractStoragePath#
The directory or folder that contains the entity referenced by the path.
- Returns:
AbstractStoragePathThe directory or folder that contains the entity referenced by the path.
- read_text() str#
Return the text content of the file or blob that the path refers to.
- Returns:
strThe text content of the file or blob that the path refers to.
- remove() None#
Remove recursively the entire directory, folder, file or blob referenced by the path.
- resolve() AbstractStoragePath#
Make the path absolute, resolving any symbolic links or
..components. A new path object is returned.- Returns:
AbstractStoragePathA new reference to the same entity but removing symbolic links and
..components.
- property stem: str#
The name of the entity referenced by the path with its suffix (file extension).
- Returns:
strThe name of the entity referenced by the path with its suffix (file extension).
- property suffix: str#
The suffix for file extension of the entity referenced by the path.
- Returns:
strThe suffix for file extension of the entity referenced by the path.
- write_bytes(data: bytes) None#
Replace the content of the file or blob that the path refers to or creates a new file or blob.
- Parameters:
- data
bytes The new content of the file or blob referenced by the path.
- data
- class ansys.saf.glow.client.AnalysisResultModel(*, valid: bool, error: str = '', stack_trace: str = '', uses_shared_product_instances: bool = False, solution_name: str = '', ui_module: str = '', solution_module: str = '')#
Bases:
BaseModelRepresents the result of a solution analysis.
- model_config = {}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- exception ansys.saf.glow.client.BadRequestException#
Bases:
SolutionClientErrorException raised when the GLOW client API is used incorrectly.
- class ansys.saf.glow.client.Client(solution_type: type[T], url: str, external_url: str | None = None, access_token: str | None = None, api_key: str | None = None)#
Bases:
Generic[T]Client for enabling access to a remote GLOW Solution.
- Parameters:
- solution_type: type[Solution]
The Solution that is being implemented remotely. Must be a class that has been derived from
Solution.- url: str
The URL of the remote Solution GLOW REST API
- external_url: optional[str]
The URL of the remote Solution GLOW REST API from outside the UI container (e.g. a browser) in on-premises deployments.
- access_token: optional[str]
An optional access token containing the security credentials for a login session.
- api_key: optional[str]
An optional API key sent via the
x-api-keyheader. Takes precedence overaccess_token.
- close()#
Close the transport and proxies.
- create_project(display_name: str, description: str = '') T#
Create a new project with the specified
display_name. Return a Solution instance with the same fields and methods as the Solution specified in theClientconstructor.- Parameters:
- Returns:
T derived from ansys.saf.glow.solution.SolutionA Solution instance with the same fields and methods as the Solution specified in the
Clientconstructor.
- delete_project(name: str) None#
Delete a project specified by its resource name (
projects/<project_id>).- Parameters:
- name
str Resource name of an existing project.
Has the form
projects/<project_id>.
- name
- property deployment_type: Deployment#
Return the deployment type derived from the value of the
GLOW_DEPLOYMENTenvironment variable which corresponds to how the server in which the client is running is deployed.- Returns:
DeploymentThe deployment type derived from the value of the
GLOW_DEPLOYMENTenvironment variable which corresponds to how the server in which the client is running is deployed.
- get_project(name: str) T#
Return the Solution instance for a project specified by its resource name (
projects/<project_id>).- Parameters:
- name
str Resource name of an existing project.
Has the form
projects/<project_id>.
- name
- Returns:
T derived from ansys.saf.glow.solution.SolutionSolution instance for the project referred to by
namewith the same fields and methods as the Solution specified in theClientconstructor.
- get_schema() Any#
Return the JSON schema structure (dictionary) for the Solution passed to the constructor.
- Returns:
AnyJSON schema structure (dictionary) for the Solution passed to the constructor.
- property http_client#
The http client used to communicate with the GLOW REST API.
- import_project(safx_path: Path, display_name: str) T#
Import the given
.safxproject archive with the specifieddisplay_nameand open it.- Parameters:
- safx_path
Path The path of to the safx project file.
(A
.safxproject file is an archive of a.sapproject with its associated project directory.)- display_name
str The project name displayed to the user.
- safx_path
- Returns:
T derived from ansys.saf.glow.solution.SolutionA Solution instance for the imported file with the same fields and methods as the Solution specified in the
Clientconstructor.
- list_projects(page_size: int | None = None, page: int | None = None, order_by: str | None = None, filter: str | None = None) Any#
List projects with pagination, ordering, and optional filtering. By default, returns the first page of results with a maximum of 100 projects per page.
- Parameters:
- page_size
optional,int The maximum number of projects to return in the response. If not specified, defaults to returning at most 100 projects. Values above 100 will be coerced to 100.
- page
optional,int The page number to return (1-indexed). If not specified, defaults to returning the first page.
- order_by
optional,str Comma-separated list of fields to order by. The default sorting order is ascending. To specify descending order for a field, append a “ desc” suffix; for example:
"date_modified desc, name".Supported fields are
display_name,description,date_created,date_modified, andname.- filter
optional,str A filter expression to narrow down the listed projects. Follows the syntax:
<field> <operator> <value> [AND <field> <operator> <value>]...- Supported fields:
display_name: Only supports=(case-insensitive, contains match).description: Only supports=(case-insensitive, contains match).date_created: Supports=,!=,<,>,<=,>=.date_modified: Supports=,!=,<,>,<=,>=.
Date values must be ISO 8601 strings (e.g.,
2024-01-15T00:00:00,2024-01-15).- Examples:
"display_name = Motor""description = benchmark""date_created >= 2024-01-01T00:00:00""display_name = Motor AND date_created >= 2024-01-01T00:00:00"
- page_size
- Returns:
- upgrade_project(name: str) T#
Upgrade the version of the Solution instance for a project specified by its resource name (
projects/<project_id>).- Parameters:
- name
str Resource name of an existing project.
Has the form
projects/<project_id>.
- name
- Returns:
T derived from ansys.saf.glow.solution.SolutionSolution instance for the project referred to by
namewith the same fields and methods as the Solution specified in theClientconstructor.
- exception ansys.saf.glow.client.ConflictException#
Bases:
SolutionClientErrorException raised when the GLOW client API is invoked making a request inconsistent with a given project state.
- class ansys.saf.glow.client.DashClient#
Bases:
Generic[T]Client for use in the Dash UI framework that enables access to remote GLOW Solution.
- static create_event_listener(step: StepModel, stream_name: str, id: str) WebSocket#
Return a WebSocket configured to receive data from transaction events on the
stream_namechannel.- Parameters:
- step: StepModel
The instance of the step used on the UI layout.
- stream_name: str
The name of the stream that the WebSocket will try to connect to. A step may have multiple streams.
- id
str The identifier used on the HTML element that contains the WebSocket.
- Returns:
WebSocketA WebSocket configured to receive events data on the
stream_namechannel.
Examples
>>> layout = html.Div([ >>> html.Button("Trigger Event", id="trigger_event", n_clicks=0), >>> html.Div(id="event_message", children="Not triggered yet"), >>> html.Div(id="ws_container"), >>> ]) >>> >>> @callback( >>> Input("trigger_event", "n_clicks"), >>> State("url", "pathname"), >>> prevent_initial_call=True, >>> ) >>> def trigger_transaction_event(n_clicks, project: MySolution): >>> if n_clicks > 0: >>> step = project.steps.my_step >>> step.trigger_event() >>> >>> @callback( >>> Output("event_message", "children"), >>> Input("my_ws", "message"), >>> prevent_initial_call=True, >>> ) >>> def message(message): >>> if message: >>> return f"Received message: {message['data']}" >>> else: >>> return "No message received yet."
- static get_deployment_type() Deployment#
Return the deployment type derived from the value of the
GLOW_DEPLOYMENTenvironment variable which corresponds to how the server in which the client is running is deployed. Normally this will be the UI server of the solution.- Returns:
DeploymentThe deployment type derived from the value of the
GLOW_DEPLOYMENTenvironment variable which corresponds to how the server in which the client is running is deployed. Normally this will be the UI server of the solution.
- class ansys.saf.glow.client.Deployment(*values)#
Bases:
EnumCategories of deployments for the GLOW server.
- exception ansys.saf.glow.client.InternalSolutionException#
Bases:
SolutionClientErrorException raised when the solution experienced a problem server-side.
- class ansys.saf.glow.client.LongRunning(step_model_type: type[StepModel], step_name: str, method_name: str, method_url: str, http_client: Client, return_type: T)#
Bases:
Generic[T]An object that monitors the execution of a call to a long-running transaction method.
A method that is decorated with
long_running()will return aLongRunningobject when called from aSolutioninstance returned by the GLOW client. The calling environment can use theLongRunningobject to monitor the method execution.It is not expected that the constructor will be called directly by a Solution client.
- Parameters:
- step_model_type
type of StepModel The step class that contains the method to be monitored.
- step_name
str The name of the step that contains the method to be monitored. The name of a step is the name of a field on a
StepsModelderived class. TheStepsModelderived class is the type of thestepsfield which defines the set of steps in aSolutionderived class.- method_name
str The name of the method that contains the method to be monitored.
- method_url
str The URL of the method to be monitored.
- step_model_type
Notes
For more detailed information on the concept of long-running methods, see the corresponding section of the User Guide.
- get_state() MethodState#
Get the state of the long running method.
- Returns:
MethodStateThe current state of the method execution
Notes
For instructions and an example on using this method, see the corresponding section in the User Guide.
- is_complete(raise_for_error: bool = True) bool#
Specify whether the long-running method is complete or not.
- Parameters:
- raise_for_errorbool
If specified, then an exception is raised if the method has failed.
- Returns:
- bool
Whether the long-running method is complete or not.
Notes
For instructions and an example of using this method, see the corresponding section in the User Guide.
- wait(timeout: int | None = None) T#
Wait for the long running method to terminate.
If the process does not terminate after timeout seconds, then raise a
TimeoutErrorexception. It is safe to catch this exception and retry the wait.- Parameters:
- timeout
int If specified, then the parameter can be used to control the maximum number of seconds to wait before returning.
- timeout
Notes
For a description of this method with an example of its use, see the corresponding section in the User Guide.
- exception ansys.saf.glow.client.NotFoundException#
Bases:
SolutionClientErrorException raised when the GLOW client API is invoked to access an object that does not exist.
- class ansys.saf.glow.client.OperatingSystemPath(path: str | Path)#
Bases:
AbstractStoragePathA path to a directory or file in a OS Filesystem which may or may not actually exist.
- Parameters:
- path
strorpathlib.Path A path to a directory or file in a OS Filesystem.
- path
- as_uri() str#
Return a URI that refers to the entity referenced by the path.
- Returns:
strA URI that refers to the entity referenced by the path.
- copy(destination: AbstractStoragePath) None#
Copy the referenced entity to the given destination directory or folder. The destination directory and any missing parents will be created if they do not exist.
- Parameters:
- destination
AbstractStoragePath The directory or folder where the referenced entity will be copied.
- destination
- copyfileobj(fileobj) None#
Create or replace of the referenced entity with the contents of the file-like object
fileobj.- Parameters:
- fileobj
file like object The object that is the source of data to become the content of the referenced entity.
- fileobj
- property exists#
Whether the entity referenced by the path exists.
- Returns:
- bool
Whether the entity referenced by the path exists.
- glob(pattern: str) list[AbstractStoragePath]#
Return the paths of entities with in the referenced fdirectory or folder that match the given pattern.
- Parameters:
- pattern
str The pattern that is used to match entities within the referenced directory. The pattern can include
*as a wild match and**which matches directories recursively.
- pattern
- Returns:
list of AbstractStoragePathThe paths of entities with in the referenced directory or folder that match the given pattern.
- is_dir() bool#
Return whether the path refers to a directory or folder.
- Returns:
- bool
Whether the path refers to a directory or folder.
- is_file() bool#
Return whether the path refers to a file or blob.
- Returns:
- bool
Whether the path refers to a file or blob.
- iterdir() Iterator[AbstractStoragePath]#
Return an iterator over the entities that exist on the directory or folder referenced by the path.
- Returns:
Iterator over AbstractStoragePathThe entities that exist on the directory or folder referenced by the path.
- property name: str#
The name of the entity referenced by the path.
- Returns:
strThe name of the entity referenced by the path.
- property parent: AbstractStoragePath#
The directory or folder that contains the entity referenced by the path.
- Returns:
AbstractStoragePathThe directory or folder that contains the entity referenced by the path.
- read_text() str#
Return the text content of the file or blob that the path refers to.
- Returns:
strThe text content of the file or blob that the path refers to.
- remove() None#
Remove recursively the entire directory, folder, file or blob referenced by the path.
- resolve() AbstractStoragePath#
Make the path absolute, resolving any symbolic links or
..components. A new path object is returned.- Returns:
AbstractStoragePathA new reference to the same entity but removing symbolic links and
..components.
- property stem: str#
The name of the entity referenced by the path with its suffix (file extension).
- Returns:
strThe name of the entity referenced by the path with its suffix (file extension).
- property suffix: str#
The suffix for file extension of the entity referenced by the path.
- Returns:
strThe suffix for file extension of the entity referenced by the path.
- write_bytes(data: bytes) None#
Replace the content of the file or blob that the path refers to or creates a new file or blob.
- Parameters:
- data
bytes The new content of the file or blob referenced by the path.
- data
- class ansys.saf.glow.client.OperatingSystemStorage#
Bases:
AbstractStorageA factory for
OperatingSystemPathobjects.- create_path_from_reference(reference: str) AbstractStoragePath#
Create a
OperatingSystemPathobject given a URL.- Parameters:
- reference
str The URL of a file or directory.
- reference
- Returns:
AbstractStoragePathA object for accessing the file or directory.
- exception ansys.saf.glow.client.PermissionException#
Bases:
SolutionClientErrorException raised when the GLOW client API is invoked to trigger an operation that the user does not have permission to perform.
- exception ansys.saf.glow.client.SolutionLoadException(errors: str | list[str])#
Bases:
ExceptionException raised when errors are detected during validation of a
Solutionderived class prior to creating an API server.
- exception ansys.saf.glow.client.UnauthorizedException#
Bases:
SolutionClientErrorException raised when the GLOW client API is invoked to trigger an operation that the user does not have authorization to perform.
- class ansys.saf.glow.client.callback(*args: Any, **kwargs: Any)#
Bases:
objectA decorator of Dash callback functions that replaces the Dash callback decorator.
This decorator ensures that: - project can be injected into a callback argument.
Open Telemetry trace spans are generated for callback executions;
The start and end of callback executions are logged ensuring that the module name, callback name, trace id and span id are visible in the log; and
The DashClient class is initialized also in the new process that is spawn when a callback is run in the background.
This class expects the
dash_extensions.enrichpackage to be installed.The parameters of this decorator are identical to the Dash callback decorator.