Skip to main content


class %SYS.Python extends %Library.SystemBase

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.

Method Inventory


classmethod Builtins(flags As %Integer) as %CPP.LongLong
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 Import() to load the Python builtins module.
classmethod Bytes(cmd As %String) as %CPP.LongLong [ Language = cpp ]
Given an ObjectScript string, returns a Python object of type bytes. The input string cannot contain any wide character.
classmethod False() as %CPP.LongLong [ Language = cpp ]
Returns the Python False value.
classmethod GetPythonInfo(ByRef info) as %Integer
Returns descriptive general information about process and system wide python and python related CPF settings. Informational names/API compatibility not guaranteed.
classmethod GetPythonVersion() as %String
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.
classmethod Import(name As %String) as %CPP.LongLong [ Language = cpp ]
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("")
   write mypython.helloWorld()
classmethod None() as %CPP.LongLong [ Language = cpp ]
Returns the Python None value.
classmethod Run(cmd As %String) as %Integer [ Language = cpp ]
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.
classmethod SetInteractiveMode(state As %Integer) as %Integer
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.
classmethod Shell(vars As %Integer = 0) as %Status
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()
classmethod ToList(contentList As %CPP.BinList) as %CPP.LongLong [ Language = cpp ]
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)

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.
classmethod ToListTyped(contentList As %CPP.BinList, typeList As %CPP.BinList) as %CPP.LongLong [ Language = cpp ]
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 as well as:
the docs

  Include %occODBC
  set clist = $lb(42, 42, 42, 42)
  set tlist = $lb(-7, 2, 3, 4)
  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.
classmethod True() as %CPP.LongLong [ Language = cpp ]
Returns the Python True value.

Inherited Members

Inherited Methods

FeedbackOpens in a new tab