Skip to main content

PyAnsys PyPI Code Coverage GitHub Workflow Status (branch) MIT License black

PyPIM exposes a Pythonic interface to communicate with the Product Instance Management (PIM) API.

What is the PIM API?

The PIM API is a gRPC API, enabling both library and app developers to start a product in a remote environment and communicate with its API.

The PIM API is intended to be as simple as possible to be adaptable in a variety of network and software infrastructures. Using this API does not require any knowledge of its infrastructure. You need only know which product to start and which API the product exposes. The PIM API itself exposes very few features and assumes that all the configuration is set on a server.

The PIM API is not intended to manage stateless services, to be a job management system, or a fully featured service orchestration API. Its purpose is to expose a minimum feature set for managing service-oriented apps.

Getting started

To use PyPIM, you must have access to the PIM API.

PyPIM itself is pure Python and relies on gRPC.

Installation

The ansys-platform-instancemanagement package is tested for Python 3.10 through Python 3.14 on Windows and Linux.

pip install ansys-platform-instancemanagement

Configuration

By default, PyPIM is configured externally instead of via code. Anywhere in the local storage, create a configuration file with this format:

{
    "version": 1,
    "pim": {
        "uri": "dns:pim.svc.com:80",
        "headers": {
            "metadata-info": "value"
        },
        "tls": false
    }
}

Then, define the environment variable ANSYS_PLATFORM_INSTANCEMANAGEMENT_CONFIG to point to this configuration file.

Security

By default, the connection to the PIM server is insecure. To use TLS, mutual TLS (mTLS), a Unix Domain Socket (UDS), or Windows Named User Authentication (WNUA) instead, either use a version 2 configuration file with a security block or pass the settings directly to connect():

import ansys.platform.instancemanagement as pypim
from ansys.platform.instancemanagement import ConnectionSecurity
from ansys.tools.common.cyberchannel import CertificateFiles

client = pypim.connect(
    uri="dns:pim.svc.com:80",
    security=ConnectionSecurity(
        transport="mtls",
        cert_files=CertificateFiles(
            cert_file="client.crt", key_file="client.key", ca_file="ca.crt"
        ),
    ),
)

Product instances started with create_instance() can also request a transport with the security_settings parameter, and the transport a running instance actually uses is reported back on each of its services. See Security in the PyPIM documentation for the full configuration file schema and all supported transports.

Usage

PyPIM is a single module called ansys.platform.instancemanagement, shortened to pypim.

To start MAPDL and communicate with PyPIM, use this code:

import ansys.platform.instancemanagement as pypim
from ansys.mapdl.core import Mapdl

if pypim.is_configured():
    with pypim.connect() as pim:
        with pim.create_instance(
            product_name="mapdl", product_version="221"
        ) as instance:
            instance.wait_for_ready()
            channel = instance.build_grpc_channel(
                options=[("grpc.max_receive_message_length", 8 * 1024**2)]
            )
            mapdl = Mapdl(channel=channel)
            mapdl.prep7()
            ...

You can also use PyPIM without the with statement, as shown in this code:

import ansys.platform.instancemanagement as pypim
from ansys.mapdl.core import Mapdl

if pypim.is_configured():
    pim = pypim.connect()
    instance = pim.create_instance(product_name="mapdl", product_version="221")
    channel = instance.build_grpc_channel(
        options=[("grpc.max_receive_message_length", 8 * 1024**2)]
    )
    mapdl = Mapdl(channel=channel)
    mapdl.prep7()
    ...
    instance.delete()
    pim.close()

Integration

PyPIM can be integrated in PyAnsys libraries to transparently switch to a remote instance in a suitable environment. This process is described in Integration in the PyPIM documentation.

For example, starting MAPDL with PyPIM is as simple as using this code:

from ansys.mapdl.core import launch_mapdl

mapdl = launch_mapdl()

Ansys developer ecosystem resources

Ansys has an extensive developer ecosystem where you can find assistance for a variety of issues.

  • Developer Portal <https://developer.ansys.com/>: Blog posts, documentation, and guide

  • Developer Forum <https://discuss.ansys.com/>: Scripting and usage support for PyAnsys and other Ansys developer tools

  • Ansys Innovation Space <https://innovationspace.ansys.com/>: Product support forum and training materials

  • GitHub <https://github.com/ansys/pypim>: Development support, bug reporting, feature requests, and more.

  • Ansys Learning Hub <https://learninghub.ansys.com/>: Training, courses and learning plans

Metadata

Release files for ansys-platform-instancemanagement 1.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ansys-platform-instancemanagement 1.2.0
File Size Uploaded
ansys_platform_instancemanagement-1.2.0.tar.gz 25.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ansys-platform-instancemanagement 1.2.0
File Interpreter ABI Platform
ansys_platform_instancemanagement-1.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 60.3 kB

Release files / ansys_platform_instancemanagement-1.2.0.tar.gz

Download URL ansys_platform_instancemanagement-1.2.0.tar.gz
Size 25.4 kB
Tags Source
SHA-256 checksum
How to use checksums
dcff3b759bec05a8d0029d9e74b97b469738739dc8444568fbd20ca31a9b37e0
BLAKE2b-256 checksum
How to use checksums
c933afcc4f5b51d27ee3d2a039f94f5c3644d9a8e950cd458b16c24f72e22da6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.15

Release files / ansys_platform_instancemanagement-1.2.0-py3-none-any.whl

Download URL ansys_platform_instancemanagement-1.2.0-py3-none-any.whl
Size 34.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1c9326b7ffd6d0030237de2230ae5a4475a61cfb61d613431b74e5cdb6e5efab
BLAKE2b-256 checksum
How to use checksums
665123ca197fecf0ebe7b23b66a78bb350775b3e39e5b4031d9466a5e2059a92
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.15
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page