Granta MI connection#

Connection builder#

class Connection(servicelayer_url, session_configuration=None)#

Connects to a Granta MI ServerAPI instance.

This is a subclass of the ansys.openapi.common.ApiClientFactory class. All methods in this class are documented as returning ApiClientFactory class instances of the ansys.grantami.system.Connection class instead.

Parameters:
servicelayer_urlstr

Base URL of the Granta MI Service Layer application.

session_configurationSessionConfiguration, optional

Additional configuration settings for the requests session. The default is None, in which case the SessionConfiguration class with default parameters is used.

Notes

For advanced usage, including configuring session-specific properties and timeouts, see the ansys-openapi-common API reference. Specifically, see the documentation for the ApiClientFactory base class and the SessionConfiguration class.

  1. Create the connection builder object and specify the server to connect to.

  2. Specify the authentication method to use for the connection and provide credentials if required.

  3. Connect to the server, which returns the client object.

The examples show this process for different authentication methods.

Examples

>>> client = Connection("http://my_mi_server/mi_servicelayer").with_autologon().connect()
>>> client
<SystemApiClient: url=http://my_mi_server/mi_servicelayer>
>>> client = (
...     Connection("http://my_mi_server/mi_servicelayer")
...     .with_credentials(username="my_username", password="my_password")
...     .connect()
... )
>>> client
<SystemApiClient: url: http://my_mi_server/mi_servicelayer>
with_autologon()#

Set up client authentication for use with Kerberos (also known as integrated Windows authentication).

The default operation of this method is to attempt to connect to the API and to use the provided WWW-Authenticate header to determine if Negotiate authentication is supported by the server. If so, Negotiate will then be used for authentication.

If Negotiate authentication is not supported by the server, an exception is raised.

Returns:
ApiClientFactory

Current client factory object.

Raises:
ConnectionError

If the server does not support Negotiate authentication.

Notes

Requires the user to have a valid Kerberos Ticket-Granting-Ticket (TGT).

  • On Windows, this is provided by default.

  • On Linux, this requires the [linux-kerberos] extension to be installed and your Kerberos installation to be configured correctly.

with_credentials(username, password, domain=None, authentication_scheme=AuthenticationScheme.AUTO)#

Set up client authentication for use with provided credentials.

The default operation of this method is to attempt to connect to the API and to use the provided WWW-Authenticate header to determine whether NTLM or Basic Authentication should be used. The selected authentication scheme will then be configured for use.

Parameters:
usernamestr

Username for the connection.

passwordstr

Password for the connection.

domainstr, optional

Domain to use for connection if required. The default is None.

authentication_schemeAuthenticationScheme

The authentication scheme to use.

Tip

Added to ApiClientFactory.with_credentials in version 2.1 of ansys-openapi-common.

Returns:
ApiClientFactory

Original client factory object.

Raises:
ConnectionError

If the server does not support Basic or NTLM authentication (Windows clients only).

Notes

NTLM authentication is not currently supported on Linux.

with_oidc(idp_session_configuration=None)#

Set up client authentication for use with OpenID Connect.

Parameters:
idp_session_configurationSessionConfiguration, optional

Additional configuration settings for the requests session when connected to the OpenID identity provider.

Returns:
OIDCSessionBuilder

Builder object to authenticate via OIDC.

Notes

OIDC Authentication requires the [oidc] extra to be installed.

with_anonymous()#

Set up client authentication for anonymous use.

This does not configure any authentication or authorization headers. Users must provide any authentication information required themselves.

Clients relying on custom authentication such as client certificates or non-standard tokens should use this method.

Returns:
ApiClientFactory

Original client factory object.

connect()#

Finalize the SystemApiClient client and return it for use.

Authentication must be configured for this method to succeed.

Returns:
SystemApiClient

Client object that can be used to connect to Granta MI and interact with the Granta MI System API. The client object is a subtype of SystemApiClient. The subtype returned depends on the Granta MI server version.

PyGranta System client#

class SystemApiClient(session, service_layer_url, configuration)#

Communicates with Granta MI.

Methods are only implemented if the underlying functionality is supported by the Granta MI server version. If the functionality is not available, a NotImplementedError is raised.

This class should not be instantiated directly. New sessions are created with the Connection class.

Other Parameters:
sessionrequests.Session

A requests.Session object.

service_layer_urlstr

The Granta MI Service Layer URL.

configurationansys.openapi.common.SessionConfiguration

The configuration to apply to the client.

get_activity_report(page_size=1000)#

Get all activity information from the Granta MI server.

Parameters:
page_sizeint, optional

The number of items to include in a single response. Defaults to 1000.

Returns:
Iterator of ActivityItem

An iterator containing the returned activity information.

Warning

Activity information is updated on the Granta MI server at midnight server time. If a request is made while the activity report is being updated, duplicate results may be retrieved from the server.

Avoid making requests while the server is updating the activity report.

get_activity_report_where(filter_, page_size=1000)#

Get activity information from the Granta MI server that matches a filter.

Parameters:
filter_ActivityReportFilter

The filter to apply to the request.

page_sizeint | None, optional

The number of items to include in a single response. Defaults to 1000.

Returns:
Iterator of ActivityItem

An iterator containing the returned activity information.

Warning

Activity information is updated on the Granta MI server at midnight server time. If a request is made while the activity report is being updated, duplicate results may be retrieved from the server.

Avoid making requests while the server is updating the activity report.

get_granta_mi_version()#

Get the version of Granta MI running on the server.

Returns:
GrantaMIVersion

Granta MI version information.