Create a Python Client
This example shows how to write a MATLAB®
Production Server™ client using the Python® client API. The client application calls the addmatrix
MATLAB function deployed to a server instance. For information on writing and
compiling the function for deployment, see Create Deployable Archive for MATLAB Production Server. For deploying the
function to the server, see Deploy Archive to MATLAB Production Server.
Before you write the client application, you must have the MATLAB Production Server Python client libraries installed on your system. For details, see Install the MATLAB Production Server Python Client.
Start the Python command line interpreter.
Enter the following import statements at the Python command prompt.
import matlab from production_server import client
Open the connection to the MATLAB Production Server instance and initialize the client runtime.
client_obj = client.MWHttpClient("http://localhost:9910")
Create the MATLAB data to input to the function.
a1 = matlab.double([[1,2,3],[3,2,1]]) a2 = matlab.double([[4,5,6],[6,5,4]])
Call the deployed MATLAB function. To call the function, you must know the name of the deployed archive and the name of the function.
The syntax for invoking a function is
client.
.archiveName
.functionName
(arg1
,arg2
, .., [nargout=numOutArgs
])client_obj.addmatrix.addmatrix(a1,a2)
The output is:
matlab.double([[5.0,7.0,9.0],[9.0,7.0,5.0]])
Close the client connection.
client_obj.close()
See Also
matlab.production_server.client.MWHttpClient