Skip to main content

Introduction

Ansys Mechanical is one of the most widely used FEA solvers in structural engineering, trusted for everything from component-level stress checks to full-system coupled analyses. The GUI is powerful and approachable, and for a focused analysis it is exactly the right tool. Where scripting adds value is in the workflows that go beyond a single run: parametric studies with dozens of variants, results feeding into a CI/CD pipeline, overnight batch solves, or shared setups that a teammate can reproduce without a walkthrough. For those cases, PyMechanical extends what Mechanical already does well by giving you full programmatic control from Python. Import geometry, configure loads, run the solve, and pull results, all from a script or notebook. The same workflow runs locally on your laptop, on a remote server, or inside a Docker container without changing a line of code. Requirements to follow along:
Jump straight to examples
  • Basic examples covers core workflows including static structural, thermal, modal, harmonic, fracture, and topology-optimization analyses.
  • Advanced examples has more complex, real-world simulations you can adapt directly for your own work.
  • Remote examples covers how to run Mechanical in a remote session, ideal for CI/CD or Docker.

How it works


The Example

PyMechanical provides two modes: embedding (Mechanical runs inside your Python process for fast, in-process scripting) and remote session (Mechanical runs as a separate gRPC server, ideal for CI/CD or Docker). Both modes share the same scripting API.

Starting an embedded session

Importing geometry and meshing

Setting up and solving a static structural analysis

Extracting results and exporting images

Von Mises stress result

Opening a locked project

If a project file was left locked (for example after a crash), pass remove_lock=True at construction or when calling open():

Inspecting the project tree

app.print_tree() prints the full Mechanical object hierarchy with live state icons, useful for debugging and spot-checking your setup before solving:

Launching the GUI from a script

After building a model programmatically, save the project first, then hand it off to the GUI for visual inspection or manual adjustments with app.launch_gui(). The method opens a temporary copy of the saved file, so unsaved changes will not appear.

Managing licenses

From Mechanical 2025 R2 (v252) onward, PyMechanical exposes app.license_manager. It lets you see which license tiers are available, enable or disable specific ones, and control what gets checked out in automated runs.
The enable_session_license() method also accepts a list when you want to activate multiple tiers at once:

Remote session (CI/CD or Docker)

Summary

PyMechanical lets you script the full simulation workflow in plain Python: geometry import, meshing, loads, solving, and results. Embedding mode works well for local scripting and notebooks; the remote session mode fits better on servers, HPC jobs, or in CI/CD. Either way, you get repeatable, version-controlled simulations without touching the GUI. It is open source (MIT), so you can install it with pip install ansys-mechanical-core. Further reading: