PyAnsys Shared Components#

To enable the use of Ansys products through Python, shared components have been created. These shared components are not interfaces to specific products nor single-purpose tools. They are libraries to facilitate code-sharing across different PyAnsys packages within the PyAnsys project.

As shared components continue to be developed and created, feel free to post issues on the Issues pages for their respective GitHub repositories. For additional support, contact PyAnsys Support so that team members can route your requests to appropriate development teams.

OpenAPI-Common#

OpenAPI-Common provides the source code for authentication-aware clients for OpenAPI client libraries. This Python library is intended for use with the custom code generation template in the PyAnsys project.

OpenAPI-Common currently supports authentication with Basic, Negotiate, NTLM, and OpenID Connect. Most features of the underlying requests session are exposed for use. Some basic configuration is also provided by default.

Installation#

Install openapi-common with:

pip install ansys-openapi-common

Usage#

The package exposes several classes, including a client ApiClient class and a builder ApiClientFactory class that allow a client library to configure a connection to an API.

The ApiClient class is intended to be wrapped by code that implements a client library.

Authentication is configured through the ApiClientFactory object and its with_credentials(), with_autologon(), and with_oidc() methods. If no authentication is required, you can use the with_anonymous() method. You can provide additional configuration with the SessionConfiguration object.

>>> from ansys.openapi.common import ApiClientFactory
>>> session = ApiClientFactory('https://my-api.com/v1.svc')
...           .with_autologon()
...           .connect()
<ApiClient url: https://my-api.com/v1.svc>

Protobuf Compilation Helper#

The Protobuf Compilation Helper simplifies creating Python API packages for protobuf / gRPC APIs. It compiles the interface .proto files into Python source when building the package wheel.

The simplest way to use the Protobuf Compilation Helper is by using the template API repository. More detailed instructions can be found in the project’s README.