Differences

This shows you the differences between two versions of the page.

Link to this comparison view

muster:8.0:python [2018/01/11 08:21] (current)
Line 1: Line 1:
 +====== Muster Python API ======
 +
 +Muster 8 uses an embedded Python interpreter,​ the interpreter is invoked by each function used by the template system, that means every line you put into a new template (extension is now .py) will be fired from the embedded interpreter. This opens a few points: Every module you want to use to extend the Muster template system, must be copied into the python distribution (3.3) that comes with Muster (installation folder / python / lib).
 +
 +When you use the Python modules for the API, so , extending another Python installation,​ there'​re a few scenarios you must be warned about: If you are extending Python 2.7, there'​s no problem, if you use the template system for some other reason, i.e. querying for the installed templates, Muster will bring up its own 3.3 interpreter and everything is fine. If you're extending a 3.3 Python installation,​ Muster will share the interpreter. It that case be aware that you'll access libraries and functions from your interpreter.
 +
 +In both scenarios, you must configure your PATH environmental variables on Windows, and the LD_LIBRARY_PATH and DYLD_LIBRARY_PATH on posix platforms to let the API find the Muster .DLL/so files . You'll also need to set the MUSTER environmental variable to the Muster 8 root installation path, this allows the .LIB to find the python installation related to Muster.
 +Don't forget to configure the environmental variables, because, you may end up loading another python installation laying somewhere on your filesystem and this could lead to module import errors very hard to sort out.
 +
 +A typical example configuration for Window is:
 +
 +<​code>​
 +MUSTER=C:​\program files\virtual vertex\muster8
 +PATH=%MUSTER%;​%PATH%
 +</​code>​
 +
 +A typical example configuration on Linux is:
 +
 +<​code>​
 +MUSTER=/​usr/​local/​muster8
 +LD_LIBRARY_PATH=/​usr/​local/​muster8:​$LD_LIBRARY_PATH
 +export MUSTER
 +export LD_LIBRARY_PATH
 +</​code>​
 +
 +A typical example configuration on Mac is:
 +
 +<​code>​
 +MUSTER=/​Applications/​Muster8/​Contents
 +DYLD_LIBRARY_PATH=/​Applications/​Muster8/​Contents/​Frameworks:​$DYLD_LIBRARY_PATH
 +export MUSTER
 +export DYLD_LIBRARY_PATH
 +</​code>​
 +
 +Due to namespaces differences,​ the API exposed under Python is inside the MClientAPI namespace (instead of MClientLib).
 +
 +After configuring your environment,​ you can simply copy the files inside the SDK/​Libs/​Python27 (or Python33) inside your Python installation library (you can use the site-packages directory if you like) . This will expose the MClientAPI namespace inside your python installation.
 +
 +Each module in Python that uses the Muster API must import the API itself:
 +
 +<code python>
 +import MClientAPI
 +</​code>​
 +
 +You can then use the exact set of functions available to the C++ API to initialize the library:
 +
 +<code python>
 +err = MClientAPI.InitializeLibrary(""​)
 +if err.getErrorCode() != 0:
 + abort()
 +</​code>​
 +
 +Then you can setup a session and connect to the Dispatcher:
 +
 +<code python>
 +session = MClientAPI.InitializeSession()
 +err = MClientAPI.Connect(session,​dispatcherAddress,​9781)
 +if err.getErrorCode() != 0:
 + abort()
 +</​code>​
 +
 +then authenticate on the Dispatcher:
 +
 +<code python>
 +err = MClientAPI.Authenticate(session,​username,​password)
 +if err.getErrorCode() != 0:
 + abort()
 +</​code>​
 +
 +and perform an action:
 +
 +<code python >
 +err = MClientAPI.JobActionPause(session,​jobid)
 +if err.getErrorCode() != 0:
 + abort()
 +</​code>​
 +
 +remember to shutdown the connections and the library after completing your operations:
 +
 +<code python>
 +err = MClientAPI.Disconnect(session)
 +MClientAPI.ShutdownLibrary()
 +</​code>​
 +
 +A full set of Python examples is available inside the SDK examples folder.
 +