How can we use the wolframclient Python library to call Mathematica functions when Mathematica is running in an another server?

For example, if we have Mathematica running locally we can do as following:

from wolframclient.language import wlexpr
from wolframclient.evaluation import WolframLanguageSession

if __name__ == '__main__':
    with WolframLanguageSession() as session:
        code = 'N[Zeta[2]]'
        expression = wlexpr(code)
        result = session.evaluate(expression)


the code above will connect with our local Kernel and execute the command. We can also pass an argument to point the location of the Mathematica Kernel as well with


But how can we configure and call Mathematica running in another server? Let's say

I've seen that we have an option to use a WSTPServer, but I couldn't figure it out how to use it with the wolframscript Python library.

Also in the WolframScript documentation we have an option to use the argument -wstpserver.

So how could we put all of this together?



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy