For the latest version of JMP Help, visit JMP.com/help.


JSL Syntax Reference > JSL Functions > Python Integration Functions
Publication date: 11/29/2021

Python Integration Functions

Python Connect(<Echo(Boolean),> <Path(path),> <Use Python Version(string),> <Python System Path(list)>)

Description

Initializes the Python integration interfaces and returns an active Python integration interface connection as a scriptable object.

Returns

A Python scriptable object.

Optional Named Arguments

Echo(Boolean)

Global argument. Prints the Python source lines to the JMP log. The default value is true.

Path

Specifies the path to the Python DLL or shared library.

Use Python Version(string)

Specifies which version of Python should be used for JMP-to-Python processing.

Python System Path

Specifies a JSL list of paths that define a Python sys path set on macOS.

Python Control(<named arguments>)

Description

Sends control operations to signal Python with external events, such as source line echoing.

Returns

Returns 0 if the call succeeded and 1 if an error occurred.

Optional Named Arguments

Interactive(Boolean)

Enables interactive mode in the Python matplotlib package. Determines whether the graphics window is released or closed when graphics rendering is complete.

Echo(Boolean)

Global argument. Prints the Python source lines to the JMP log. The default value is true.

Python Disconnect

Description

Terminates the Python interfaces.

Python Execute({list of inputs}, {list of outputs}, Python_Code, named_arguments)

Description

Submits Python code to the active global Python integration interface connection given a list of inputs. On completion, returns a list of outputs.

Returns

Returns 0 if successful and 1otherwise.

Positional Arguments

{list of inputs}

A list of JMP variable names to be sent to Python as inputs.

{list of outputs}

A list of JMP variable names to be retrieved from Python as outputs.

Python_Code

The Python code to submit.

Named Arguments

See Python Submit(Python_Code, <named_arguments>).

Example

This example initiates the Python connection, sends a character variable, a numeric variable, and a set of matrices to Python. Python is then instructed to perform a set of matrix operations on the sent matrices. The Python Execute() function then get the set of matrices created by the matrix operations and gets the values of the character and numeric variables that was originally sent. Upon completion of the data retrieval, the Python connection is closed.

Python Init();
a = "abcdef";
d = 3.141;
v = [9 8 7, 6 5 4, 3 2 1];
m = [1 2 3, 4 5 6, 7 8 9];
ml = Python Execute(
	{v, m, a, d},
	{x1, x2, y1, y2, z1, z2, a, d},
	"\[
import numpy as np
x1 = np.multiply(v, m) # matrix product
print('x1=', x1)
x2 = np.divide(v, m) # matrix division
print('x2=', x2)
y1 = np.dot(v, m) # dot product of v and m
print('y1=', y1)
y2 = np.dot(m, v) # dot product of m and v
print('y2=', y2)
z1 = np.inner(v, m) # inner product of v and m
print('z1=', z1)
z2 = np.inner(m, v) # inner product of m and v
print('z2=', z2)
]\"
);
Show( v, m, ml, x1, x2, y1, y2, z1, z2, a, d );
Python Term();

x1= [[ 9. 16. 21.]

[ 24. 25. 24.]

[ 21. 16. 9.]]

x2= [[ 9. 4. 2.33333333]

[ 1.5 1. 0.66666667]

[ 0.42857143 0.25 0.11111111]]

...

Python Get(name)

Description

Gets a named variable from Python to JMP.

Returns

Returns the value of the named variable.

Argument

name

The name of the Python variable to be sent to JMP. The argument can represent any of the following Python data types: numeric, quoted string, matrix, list, or data frame.

Example

Python Init(); // initiate the Python connection
 
qbx = "The right stuff";
 
// send the qbx variable and sample data table "Animals.jmp" to Python
Python Send( qbx );
 
dt = Open( "$SAMPLE_DATA/Animals.jmp" );
Python Send( dt );
Close( dt, nosave );
 
// get the Python variable qbx and place it into a JMP variable qbx
qbx = Python Get( qbx );
 
/* get the Python variable dt and place it into a JMP data table
referenced by df */
df = Python Get( dt );
 
Python Term();
 
Show( qbx );
df << New Data View;
Wait( 10 );
Close( df, nosave );
Python Term();

qbx = "The right stuff";

0

Python Get Graphics(format)

Description

Gets the last graphics object written to the Python graph display window in the specified graphics format. The graphics object can be returned in several different graphic formats.

Returns

Returns a JMP picture object.

Argument

format

The format that the Python graph display window contents are to be converted to. Valid formats are png, bmp, jpeg, jpg, tiff, tif, and gif.

Python Get Version

Description

Returns the version number of Python being used with the JMP Python interfaces.

Python Init(<Echo(Boolean),> <Path(path),> <Use Python Version(string),> <Python System Path({list })>

Description

Initializes the Python integration interfaces.

Returns

Returns 0 if operation is successful and 1 if not successful.

Optional Named Arguments

Echo(Boolean)

Global argument. Prints the Python source lines to the JMP log. The default value is true.

Path

Specifies the path to the Python DLL or shared library.

Use Python Version(string)

Specifies which version of Python should be used for JMP-to-Python processing.

Python System Path

Specifies a JSL list of paths that define a Python sys path set on macOS.

Python Is Connected

Description

Determines whether a Python integration interface connection is currently connected to Python.

Returns

Returns 1 if connected and 0 otherwise.

Python JMP Name to Python Name(name)

Description

Maps a JMP variable name to its corresponding Python variable name using Python variable name naming rules.

Returns

A quoted string, the mapped Python name.

Argument

name

The name of the JMP variable to be sent to Python.

Python Send(name)

Description

Sends a named variable from JMP to Python.

Returns

Returns 0 if successful.

Argument

name

The name of the JMP variable to be sent to Python.

Python Send File(filename, <, Python Name(name)>)

Description

Sends a data file to Python. The filename argument is a quoted string that specifies a pathname to the file to be sent to Python.

Python Submit(Python_Code, <named_arguments>)

Description

Submits Python code to the active global Python integration interface connection.

Returns

Returns 0 if successful and non-zero otherwise.

Named Arguments

Python_Code

The Python code to submit. Statements can be a quoted string value or a list of string values.

Expand(Boolean)

(Optional) Performs an Eval Insert() on the Python code before submission.

Echo(Boolean)

(Optional) Prints the Python source lines to the JMP log.

Example

Python Init(); // initiate the Python connection
commands =
"
friends = ['john', 'pat', 'gary', 'michael']
print(friends)
for i, name in enumerate(friends):
    print( \!"iteration {iteration} is {name}\!".format(iteration=i, name=name))
";
Python Submit( commands );
Python Term();

['john', 'pat', 'gary', 'michael']

iteration 0 is john

iteration 1 is pat

iteration 2 is gary

iteration 3 is michael

0

Python Submit File(path)

Description

Submits statements to Python using the file specified in the path name.

Argument

path

The path to the file that contains the Python source lines to be executed.

Python Term

Description

Terminates the currently active Python integration interface.

Returns

Returns 0 if successful and 1 otherwise.

Want more information? Have questions? Get answers in the JMP User Community (community.jmp.com).