Do Modelica environments offer interfaces to the Python language so that

Building the system to be simulated in the visual modeling environment while the settings for the simulation are created wit Python. In this way, I will be able to run the simulation several times within an optimization algorithm in Python.

Building complex systems as functions in a language that I already know, for example, I want to create a function in Python that represent the system, then run this function from a "block".
Usually most Modelica simulation environments would offer interfaces to scripting languages like Python. Another alternative is to export a Modelica model using any simulation environment to so called Functional Mockup Units (FMU) which are stand-alone software programs. There are software solutions in Python for simulating an exported FMU multiple times, e.g. each with different values of parameters.

The Modelica language supports calls to external functions written in C/Fortran but not Python.
Open Source Simulation program to work along with Python?