%SYS
Python Class Reference

Provides utilities for loading and using Python modules, running Python commands, and starting the Python shell. More...

Inheritance diagram for Python:
Collaboration diagram for Python:

Static Public Member Functions

_.CPP.LongLong Builtins (_.Library.Integer flags)
 Loads the Python builtins module and returns a handle to that module. More...
 
_.CPP.LongLong Bytes (_.Library.String cmd)
 Given an ObjectScript string, returns a Python object of type bytes. More...
 
_.CPP.LongLong False ()
 Returns the Python False value.
 
_.Library.Integer GetPythonInfo (info)
 Returns descriptive general information about process and system wide python and python related CPF settings. More...
 
_.Library.String GetPythonVersion ()
 Returns descriptive version information about the python currently loaded in the process. More...
 
_.CPP.LongLong Import (_.Library.String name)
 Loads a Python module and returns a handle to that module. More...
 
_.CPP.LongLong None ()
 Returns the Python None value.
 
_.Library.Integer Run (_.Library.String cmd)
 Runs one or more Python commands; to run multiple commands, separate the commands. More...
 
_.Library.Integer SetInteractiveMode (_.Library.Integer state)
 Set the mode of python to Interactive meaning that signal handling state swaps will be allowed. More...
 
_.Library.Status Shell (_.Library.Integer vars)
 Starts the interactive Python shell. More...
 
_.CPP.LongLong ToList (_.CPP.BinList contentList)
 Given contentList (an ObjectScript list),. More...
 
_.CPP.LongLong ToListTyped (_.CPP.BinList contentList, _.CPP.BinList typeList)
 Given two ObjectScript lists,. More...
 
_.CPP.LongLong True ()
 Returns the Python True value.
 

Detailed Description

Provides utilities for loading and using Python modules, running Python commands, and starting the Python shell.

For information on working with Python within IRIS, see Using Embedded Python.

Member Function Documentation

◆ Builtins()

_.CPP.LongLong Builtins ( _.Library.Integer  flags)
static

Loads the Python builtins module and returns a handle to that module.

On failure, this method returns 0. Using this method is equivalent to using <method>Import</method> to load the Python builtins module.

◆ Bytes()

_.CPP.LongLong Bytes ( _.Library.String  cmd)
static

Given an ObjectScript string, returns a Python object of type bytes.

The input string cannot contain any wide character.

◆ GetPythonInfo()

_.Library.Integer GetPythonInfo (   info)
static

Returns descriptive general information about process and system wide python and python related CPF settings.

Informational names/API compatibility not guaranteed.

◆ GetPythonVersion()

_.Library.String GetPythonVersion ( )
static

Returns descriptive version information about the python currently loaded in the process.

Example: "3.10.12 (main, Jun 11 2023, 05:26:28) [GCC 11.4.0]" on Ubuntu 22. If python is not loaded it will return "Not Loaded". Does not Load Python.

◆ Import()

_.CPP.LongLong Import ( _.Library.String  name)
static

Loads a Python module and returns a handle to that module.

On failure, this method returns 0.

Typically you use this method to bind the module to a variable, which you then use to call code within the module. For example:

set mypython = ##class(SYS.Python).Import("package.subpackage.name") write mypython.helloWorld()

◆ Run()

_.Library.Integer Run ( _.Library.String  cmd)
static

Runs one or more Python commands; to run multiple commands, separate the commands.

with a new line, $char(10). This method returns 0 on success or -1 on failure.

◆ SetInteractiveMode()

_.Library.Integer SetInteractiveMode ( _.Library.Integer  state)
static

Set the mode of python to Interactive meaning that signal handling state swaps will be allowed.

Interactive mode has a performance cost, but enables useful features like saving/restoring terminal state and generating better documentation. Returns previous signal state: 0 - swapping allowed, 1 - swapping disabled, -1 - Swapping unapplicable to your platform.

◆ Shell()

_.Library.Status Shell ( _.Library.Integer  vars)
static

Starts the interactive Python shell.

To use this method, you must have USE permission on the Developer resource. To exit the shell, type the command quit()

◆ ToList()

_.CPP.LongLong ToList ( _.CPP.BinList  contentList)
static

Given contentList (an ObjectScript list),.

this method returns a Python list that contains the same data. For example:

set clist = $lb(123, 456.789, "hello world") set plist = ##class(SYS.Python).ToList(clist)


Warning:
Don't pass binary data via this API, Use ToListTyped with one of the binary ODBC types instead.
If you put binary data in this API, IRIS will try to translate it as a UTF8 string.

◆ ToListTyped()

_.CPP.LongLong ToListTyped ( _.CPP.BinList  contentList,
_.CPP.BinList  typeList 
)
static

Given two ObjectScript lists,.

returns a Python list that contains the same data as contentList, with each member of the list having the data type specified in typeList. For example, the following code returns a Python list where each member of the list has the value 42, but is represented as ODBCTYPEbit(SQLBIT), ODBCTYPEnumeric(SQLNUMERIC), ODBCTYPEdecimal(SQLDECIMAL), and ODBCTYPEinteger(SQLINTEGER), respectively. More info on the type values can be found in occODBC.inc as well as:
the docs

Include occODBC set clist = $lb(42, 42, 42, 42) set tlist = $lb(-7, 2, 3, 4) [or] set tlist = $lb($$$ODBCTYPEbit,$$$ODBCTYPEnumeric,$$$ODBCTYPEdecimal,$$$ODBCTYPEinteger) set plist = ##class(SYS.Python).ToListTyped(clist, tlist)


This type translation obeys Intersystems SQL Rules, so for the string and binary ODBC types, $C(0) will turn into Python "". For all ODBC types, $lb(,"") will be 2 Python "None" elements.