PyMechanical is a Python interface for Ansys Mechanical (FEA software for structural engineering), enabling automation and integration of simulation workflows from 2024 R2 and later.
PyMechanical provides two distinct modes of interaction:
- Embedding mode — Run Mechanical directly in your Python process via the
Appclass. Full object-model access, fast startup, ideal for Jupyter notebooks and interactive scripting. - Remote session mode — Launch Mechanical as a separate server process and communicate via gRPC. Process isolation, optional GUI, ideal for CI/CD, Docker, and automation.
- Python: 3.10 – 3.13
- Mechanical: 2024 R2 (v242) and later
- Platforms: Windows, Linux
Install from PyPI:
pip install ansys-mechanical-core
For graphics support:
pip install ansys-mechanical-core[graphics]
For RPC functionality:
pip install ansys-mechanical-core[rpc]
Requirements:
- Licensed copy of Ansys Mechanical (2024 R2 or later).
- For embedded mode: Local Mechanical installation required.
- For remote session mode: Network access to a running Mechanical instance.
Embedding mode:
from ansys.mechanical.core import App
app = App(globals=globals())
print(app)
# Access Mechanical objects directly
Model.AddStaticStructuralAnalysis()Remote session mode:
from ansys.mechanical.core import launch_mechanical
mechanical = launch_mechanical()
result = mechanical.run_python_script("2+3")
print(result) # Output: 5
mechanical.exit()Connect to existing instance:
from ansys.mechanical.core import connect_to_mechanical
mechanical = connect_to_mechanical(port=10000)
result = mechanical.run_python_script("Model.Name")
print(result)- Connection refused: Ensure Mechanical is running and the port is accessible.
- License error: Verify your Ansys license is properly configured.
- Import error: Check that
ansys-pythonnetis installed (notpythonnet). - Linux embedding: Use
mechanical-envto run Python scripts for embedded mode.
- Documentation
- Cheat sheet
- Issues — report bugs or request features
- Discussions — ask questions
- Contributing guide
