Skip to main content

A python wrapper for Ansys Mechanical

Project description

PyMechanical logo

PyAnsys PyPI Python GH-CI Codecov MIT Black

Overview

PyMechanical brings Ansys Mechanical to Python. It enables your Python programs to use Mechanical within Python’s ecosystem. It includes the ability to:

  • Connect to a remote Mechanical session

  • Embed an instance of Mechanical directly as a Python object

Install the package

Install PyMechanical using pip with:

pip install ansys-mechanical-core

For more information, see Install the package in the PyMechanical documentation.

Dependencies

You must have a licensed copy of Ansys Mechanical installed. When using an embedded instance, that installation must be runnable from the same computer as your Python program. When using a remote session, a connection to that session must be reachable from your Python program.

Getting started

PyMechanical uses the built-in scripting capabilities of Mechanical. For information on the scripting APIs available, see the Scripting in Mechanical Guide in the Ansys Help.

Configuring the mechanical installation

On a Windows system, the environment variable AWP_ROOT<ver> is configured when Mechanical is installed, where <ver> is the Mechanical release number, such as 251 for release 2025 R1. PyMechanical automatically uses this environment variable (or variables if there are multiple installations of different versions) to locate the latest Mechanical installation. On a Linux system, you must configure the AWP_ROOT<ver> environment variable to point to the absolute path of a Mechanical installation.

Starting a remote session

To start a remote session of Mechanical on your computer from Python, use the launch_mechanical() method. This methods returns an object representing the connection to the session:

import ansys.mechanical.core as pymechanical

mechanical = pymechanical.launch_mechanical()

Running commands on the remote session

Given a connection to a remote session, you can send an IronPython script. This uses the built-in scripting capabilities of Mechanical. Here is an example:

result = mechanical.run_python_script("2+3")
result = mechanical.run_python_script("ExtAPI.DataModel.Project.ProjectDirectory")

Using an embedded instance of Mechanical as a Python object

PyMechanical also supports directly embedding an instance of Mechanical as a Python object. In this mode, there is no externally running instance of Mechanical. This feature is supported on Windows and Linux for version 2024 R1 and later. Here is an example:

import ansys.mechanical.core as pymechanical

app = pymechanical.App()
app.update_globals(globals())
project_dir = DataModel.Project.ProjectDirectory

How to report issues

If you encounter any issues or limitations with PyMechanical that hinder your work, please create an issue or discussion so our team can address them promptly:

For issues pertaining to Mechanical scripting, please make a post on the Developer Portal.

If you have general questions about PyAnsys or are unsure which repository to place an issue in, email pyansys.core@ansys.com.

Documentation resources

Documentation for the latest stable release of PyMechanical is hosted at PyMechanical documentation.

In the upper right corner of the documentation’s title bar, there is an option for switching from viewing the documentation for the latest stable release to viewing the documentation for the development version or previously released versions.

You can also view or download the PyMechanical cheat sheet. This one-page reference provides syntax rules and commands for using PyMechanical.

Testing and development

If you would like to test or contribute to the development of PyMechanical, see Contribute in the PyMechanical documentation.

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_mechanical_core-0.11.36.tar.gz (93.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ansys_mechanical_core-0.11.36-py3-none-any.whl (148.6 kB view details)

Uploaded Python 3

File details

Details for the file ansys_mechanical_core-0.11.36.tar.gz.

File metadata

  • Download URL: ansys_mechanical_core-0.11.36.tar.gz
  • Upload date:
  • Size: 93.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ansys_mechanical_core-0.11.36.tar.gz
Algorithm Hash digest
SHA256 261e25d5d43c05e645c14c0d927d0106587466cef96c4370040625c0d579ff82
MD5 ca18babb303ae6223909bc8d9d7419da
BLAKE2b-256 654c2d244451c7ca329377da656f4222119ebee691b81c4fb1d34da032b90ed8

See more details on using hashes here.

Provenance

The following attestation bundles were made for ansys_mechanical_core-0.11.36.tar.gz:

Publisher: ci_cd.yml on ansys/pymechanical

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ansys_mechanical_core-0.11.36-py3-none-any.whl.

File metadata

File hashes

Hashes for ansys_mechanical_core-0.11.36-py3-none-any.whl
Algorithm Hash digest
SHA256 ad49ea4860df32cdcb0dc3135479370faf44421f412222fa73347c7f807d9eca
MD5 df09384dea0ff0a95351f41ad5c76fa0
BLAKE2b-256 5ebe74358405be3b634f5dfc295e228c394a1c0547abc567acf1d2f6eac1ffa6

See more details on using hashes here.

Provenance

The following attestation bundles were made for ansys_mechanical_core-0.11.36-py3-none-any.whl:

Publisher: ci_cd.yml on ansys/pymechanical

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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