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?

  • $\begingroup$ Won't be easy because the wolframclient package talks either to a local kernel or to one in the Wolfram cloud. According to Wolfram's WSTP page, there are bindings only for C/C++, Java and .NET, for other languages "it's in development". Don't hold your breath, though. One solution could be to write a Python web server that talks to a local Wolfram kernel using the wolframclient package and then you'd access that Python server remotely over HTTP. $\endgroup$ Apr 2, 2023 at 17:12
  • $\begingroup$ Oh, and if you go for the HTTP service: be mindful of the Wolfram license conditions , see e.g. https://www.wolfram.com/engine/faq/ . They even consider in-house web access "commercial use". $\endgroup$ Apr 3, 2023 at 15:01


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.