Python Bindings Plug-In

This plug-in implements libFAUDES bindings for the scripting language Python; see https://www.python.org. Relevant libFAUDES data types and functions can be accessed from the Python interpreter. The most convenient method to make the faudes module available is to install it via pip; i.e., for Linux and macOS

$ pip install faudes
$ python3 -c "import faudes; print(faudes.Version())"

or, for native Windows

> py -m pip install faudes
> py -c "import faudes; print(faudes.Version())"

This will search the index pypi.org for a binary distribution that fits your platform/archirectur. In the case that no such matching binary is present, please let us know. Instructions on how to compile your own binary are below.

Example Script

In large, libFAUDES Python bindings follow the same conventions as the Lua bindingins. Thus, you may want to inspect the documentation of the latter; see https://fgdes.tf.fau.de/faudes/luafaudes/index.html. libFAUDES specific Python tutorial ship with the sourcse distribution; see ./libFAUDES/pybindings/tutorial.

Example Python script:

# load libFAUDES bindings
import faudes
# test
faudes.Version()
# machine 1
gL1=faudes.Generator()
gL1.InsInitState("Idle")
gL1.SetMarkedState("Idle")
gL1.InsState("Busy")
gL1.InsEvent("alpha1")
gL1.InsEvent("beta1")
gL1.SetTransition("Idle","alpha1","Busy")
gL1.SetTransition("Busy","beta1","Idle")
# machine 2
gL2=faudes.Generator()
gL2.InsInitState("Idle")
gL2.SetMarkedState("Idle")
gL2.InsState("Busy")
gL2.InsEvent("alpha2")
gL2.InsEvent("beta2")
gL2.SetTransition("Idle","alpha2","Busy")
gL2.SetTransition("Busy","beta2","Idle")
# overall plant
gL=faudes.Generator()
faudes.Parallel(gL1,gL2,gL)
# controllable events
sCtrl=faudes.EventSet()
sCtrl.Insert("alpha1")
sCtrl.Insert("alpha2")
# specification aka buffer
gE=faudes.Generator()
gE.InsInitState("Empty")
gE.SetMarkedState("Empty")
gE.InsState("Full")
gE.InsEvent("beta1")
gE.InsEvent("alpha2")
gE.SetTransition("Empty","beta1","Full")
gE.SetTransition("Full","alpha2","Empty")
# lift specification to overall eventset
sAll=faudes.EventSet()
sAll=gL.Alphabet()
faudes.InvProject(gE,sAll)
# supremal closed loop
gK=faudes.Generator()
faudes.SupCon(gL,sCtrl,gE,gK)
# show result on console
gK.Write()
# save result as graphics
gK.GraphWrite("K.png")

Note: for graphics output you must have installed dot from the GraphViz package. If dot is not in the systems path, you may direct libfaudes via faudes.DocExecPath("/wherever_dot_is/dot").

Building the libFAUDES Python module

The faudes Python module consists of the glue code faudes.py and a suitably extended libFAUDES shrared object _faudes.so (or _faudes.pyd for Windows). Both files are generated by the libFAUDES build system; see build-system documentation for details. Manualy copying/renaming both files to a project folder enables the import of the faudes module from Python scripts in that folder.

Example for the overall build process incl. copy/rename:

./libFAUDES$ make dist-clean
./libFAUDES$ make -j configure
./libFAUDES$ make -j
./libFAUDES$ cp plugings/pybindings/obj/faudes.py whereever/
./libFAUDES$ cp plugings/pybindings/obj/_faudes.so whereever/
./libFAUDES$ cd whereever
./whereever$ python3 -c "import faudes; print(faudes.Version())"

The libFAUDES build system also has a dedicated target pybindings-wheel that utilises the Python module build to generate a Python package faudes-*.whl for binary distribution. The latter can be installed via pip. The benefit of this approach is that Python build takes care of matching toolchains etc. and that after installing the wheel the module files do not need to be copied to each relevant project folder. The downside is that Python build wont use parallel jobs and therefore can take quite some time.

Example for the overall build process incl. installation:

./libFAUDES$ make dist-clean
./libFAUDES$ make -j configure
./libFAUDES$ make pybindings-wheel
./libFAUDES$ pip install faudes-2.34.0-cp314-cp314-macosx_10_15_universal2.whl

Alternatively, you may download the configured source from PyPI and invoke build directly; e.g. for Windows with official Python distribution and MSVC installed, but no MSYS avialable:

./faudes-2.34> py -m build --wheel --outdir=./

License

The Python bindings plug-in is distributed with libFAUDES. All code is provided under terms of the LGPL.

Copyright (c) 2023 - 2026 Thomas Moor.

libFAUDES 2.34e --- 2026.03.16 --- c++ api documentaion by doxygen