Skip to main content

A Python wrapper for Ansys platform instancemanagement

Project description

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.7 through Python 3.10 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.

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()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ansys_platform_instancemanagement-1.1.2.tar.gz (15.5 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file ansys_platform_instancemanagement-1.1.2.tar.gz.

File metadata

File hashes

Hashes for ansys_platform_instancemanagement-1.1.2.tar.gz
Algorithm Hash digest
SHA256 940d7a27d26e4c6d1228da5e139948fc4b1388f7cc7c3f5356b2b3b41e8d7c48
MD5 6d1a0500ba56b93f33998ea01543a462
BLAKE2b-256 1016c78dc035a3a357f0796e75b41aa7a77f6ff36f5866c57c3f99781ffc7bef

See more details on using hashes here.

File details

Details for the file ansys_platform_instancemanagement-1.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for ansys_platform_instancemanagement-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 52afe4755c4233985a1f5f33cdb2a163a53db5cee75f04c3a4e47fc81e1d0bb1
MD5 e2a1a99c75e1b121b43790f4d61e5f20
BLAKE2b-256 141fa05b62b999ca895ea66e7dbc6242e8121ea578d71fff1055b6cea7e45a51

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page