PYTHON API with FEFLOW
The FEFLOW graphical user interface (GUI) is a robust and versatile platform capable of executing a wide range of modeling workflows. However, when it comes to automation of repetitive workflows, accessing simulation results or dynamically changing model properties during runtime, the Python API becomes especially useful. There are two ways to integrate Python scripting within FEFLOW:
Option 1: Using the Python Interface Within the FEFLOW GUI
FEFLOW provides a built-in scripting interface accessible directly through the GUI. Navigate to the menu item 'Scripting' and choose one of the following dropdown menu items:
/Edit Script - View and modify scripts already attached to the current FEM file.
/Execute Python Command - Write and run Python scripts, and optionally save them.
Selecting either option opens a scripting window with two panels:
The bottom panel is where you write your Python commands or entire script.
The top panel displays any output generated during command or script execution.
When scripting within the GUI, there's no need to manually import the ifm package — it's loaded by default. This allows you to directly call API methods. Note that in this context, the variable doc typically refers to the active FEFLOW model and is used to access various API functionalities.
Fig. 1 shows an example demonstrating the use of some core API methods. For a complete reference of available methods, please refer to the official documentation pages.
Fig. 1 - Scripting example of some ifm functions used in the FEFLOW scripting menu.
Option 2: Using an External Python Editor (e.g., VS Code, PyCharm)
Python scripts can also be developed and executed using any external editor or IDE such as Visual Studio Code, PyCharm, or even from the command line. In this case it is required to explicitly import the ifm module and secondly, to load the corresponding FEM or DAC file using an appropriate method, see Fig. 2.
In external scripts, the variable representing the FEFLOW file is not restricted to doc as in the GUI scripting option. In the example shown in Fig. 2 the variable for the FEM file is named femdata, but you can choose any variable name.
Fig. 2 - Code example of an external python script including import of ifm functionalities and loading a .fem file.
One major benefit of using the Python API outside the FEFLOW GUI is the ability to work within a virtual environment. This allows users to install and manage third-party libraries easier than within the FEFLOW user interface. Additionally, using a code editor provides advantages such as auto-completion and better formatting capabilities.
FURTHER INFORMATION AND USEFUL LINKS
Manuals and User Guides
FEFLOW 10.0 Documentation - Scripting Menu
ifm: Python API for FEFLOW Groundwater Modelling System — ifm 10.000 documentation
Training options
A smooth introduction to the FEFLOW – Python programming interface - self-paced course
FEFLOW – Getting started with FEFLOW Python Interface - self-paced course
Boost workflows on groundwater modelling with latest FEFLOW-Python interface - webinar