{"id":64463,"date":"2023-12-11T14:41:26","date_gmt":"2023-12-11T06:41:26","guid":{"rendered":"https:\/\/oihelp.corporate.ifs.com\/help\/?page_id=64463"},"modified":"2024-07-09T10:39:00","modified_gmt":"2024-07-09T02:39:00","slug":"python-script","status":"publish","type":"page","link":"https:\/\/oihelp.corporate.ifs.com\/help\/sentinel\/sentinel-studio\/component-logic-functions\/python-script\/","title":{"rendered":"Python Script"},"content":{"rendered":"\n<p class=\"left-bar\">This article applies to IFS OI Sentinel 4.14 and later.<\/p>\n<p class=\"intro-text\">Python is a versatile, readable high-level programming language with a wide range of applications.<\/p>\n<p class=\"intro-text\">The Python Script component is conceptually similar to the <a href=\"https:\/\/oihelp.corporate.ifs.com\/help\/sentinel\/sentinel-studio\/component-logic-functions\/r-language\/\">R Script<\/a> component, where you can configure input pins, write a script to use these inputs and perform some logic, and set the output value. That output value would then be forwarded to the next node in the UDP graph.<\/p>\n<p class=\"intro-text\">This component sends input data to Python for processing, using a defined Python script. The resultant value declared by the \u2018output\u2019 symbol is sent to the \u2018out\u2019 output pin.\u00a0<\/p>\n<p class=\"intro-text\"><a href=\"https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2023\/12\/Snag_38145976.png\" rel=\"lightbox-0\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-64467\" src=\"https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2023\/12\/Snag_38145976.png\" alt=\"\" width=\"146\" height=\"56\" srcset=\"https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2023\/12\/Snag_38145976.png 146w, https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2023\/12\/Snag_38145976-48x18.png 48w\" sizes=\"auto, (max-width: 146px) 100vw, 146px\" \/><\/a><\/p>\n<p class=\"note\">Once the Python Script has finished executing, the Global Environment is cleared. This means that any state which is stored in the Global Environment is lost between each run of the script.<\/p>\n<p class=\"intro-text\">For security reasons, imports and meta programming are not allowed in Python scripts.<\/p>\n<hr \/>\n<h2 class=\"page-subheading\">Properties<\/h2>\n<p class=\"intro-text\">The Python Script component has four properties: <strong>Name, Python Values<\/strong>, and <strong>Python\u00a0Script<\/strong>.<\/p>\n<p><a href=\"https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2023\/12\/Snag_3828e8b5.png\" rel=\"lightbox-1\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-64472\" src=\"https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2023\/12\/Snag_3828e8b5.png\" alt=\"\" width=\"250\" height=\"362\" srcset=\"https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2023\/12\/Snag_3828e8b5.png 250w, https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2023\/12\/Snag_3828e8b5-104x150.png 104w, https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2023\/12\/Snag_3828e8b5-33x48.png 33w\" sizes=\"auto, (max-width: 250px) 100vw, 250px\" \/><\/a><\/p>\n<p class=\"intro-text\"><strong>Name<\/strong>: Give the Python Script component a name, to differentiate it from other Python Script components in the process. In our example, the <em>Name <\/em>is \u2018value&gt;value2\u2019.<\/p>\n<p class=\"intro-text\"><strong>Python values<\/strong>: Use the Python values to add and name data inputs to the Python Script. These can then be used in the Python Script.<\/p>\n<p class=\"intro-text\"><a href=\"https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2023\/12\/Snag_382f2d14.png\" rel=\"lightbox-2\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-64473\" src=\"https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2023\/12\/Snag_382f2d14.png\" alt=\"\" width=\"250\" height=\"107\" srcset=\"https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2023\/12\/Snag_382f2d14.png 250w, https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2023\/12\/Snag_382f2d14-150x64.png 150w, https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2023\/12\/Snag_382f2d14-48x21.png 48w\" sizes=\"auto, (max-width: 250px) 100vw, 250px\" \/><\/a> <a href=\"https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2023\/12\/Snag_38145976.png\" rel=\"lightbox-0\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-64467\" src=\"https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2023\/12\/Snag_38145976.png\" alt=\"\" width=\"146\" height=\"56\" srcset=\"https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2023\/12\/Snag_38145976.png 146w, https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2023\/12\/Snag_38145976-48x18.png 48w\" sizes=\"auto, (max-width: 146px) 100vw, 146px\" \/><\/a><\/p>\n<p class=\"intro-text\">In our example, we\u2019ve added \u2018value\u2019 and \u2018value2\u2019 as the <strong>Python values<\/strong>. As they are added as properties, they are assigned as inputs to the component.<\/p>\n<p class=\"intro-text\"><strong>Python Script<\/strong>: The Python Script should use the <em>Python values<\/em> in a script that uses the Python language. You can type the Python script in, or you can load it from a Python file that is stored in a file directory.<\/p>\n<p class=\"intro-text\">In our example, the Python Script is: \u2018output = value &gt; value2\u2019. Note that Python language syntax is used here.<\/p>\n<ul class=\"intro-text\">\n<li>To edit the Python Script, click the Edit Python Script\u2026 button.<\/li>\n<\/ul>\n<p class=\"intro-text\"><a href=\"https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2023\/12\/Snag_38307bea.png\" rel=\"lightbox-4\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-64474\" src=\"https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2023\/12\/Snag_38307bea.png\" alt=\"\" width=\"250\" height=\"139\" srcset=\"https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2023\/12\/Snag_38307bea.png 250w, https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2023\/12\/Snag_38307bea-150x83.png 150w, https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2023\/12\/Snag_38307bea-48x27.png 48w\" sizes=\"auto, (max-width: 250px) 100vw, 250px\" \/><\/a><\/p>\n<p class=\"intro-text\">This opens the Edit Python Script dialog.<\/p>\n<p class=\"intro-text\"><img decoding=\"async\" src=\"https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2023\/12\/image007.png\" \/><\/p>\n<p class=\"intro-text\"><strong>OK or Cancel<\/strong><\/p>\n<ul class=\"intro-text\">\n<li>Click OK to validate and save changes to the script or click Cancel to lose any changes and close the dialog. If the script is not valid, an error dialog will be displayed and the script cannot be saved.<\/li>\n<\/ul>\n<p class=\"intro-text\"><strong>Load Python Script\u2026<\/strong><\/p>\n<ul class=\"intro-text\">\n<li>Click <em>Load Python Script<\/em> to load the Python script from a Python file stored in a file directory. This overwrites any text that\u2019s in the Python Script edit box.<\/li>\n<\/ul>\n<p class=\"intro-text\"><strong>Save Python Script\u2026<\/strong><\/p>\n<ul class=\"intro-text\">\n<li>Click <em>Save Python Script<\/em> to save the script from the Python Script edit box to a new Python file.<\/li>\n<\/ul>\n<hr \/>\n<h2 class=\"page-subheading\">Inputs<\/h2>\n<p><a href=\"https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2023\/12\/Snag_38145976.png\" rel=\"lightbox-0\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-64467\" src=\"https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2023\/12\/Snag_38145976.png\" alt=\"\" width=\"146\" height=\"56\" srcset=\"https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2023\/12\/Snag_38145976.png 146w, https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2023\/12\/Snag_38145976-48x18.png 48w\" sizes=\"auto, (max-width: 146px) 100vw, 146px\" \/><\/a><\/p>\n<p class=\"intro-text\">The input has a flow, and any defined Python values.<\/p>\n<p class=\"intro-text\"><strong>Flow<\/strong> <a href=\"https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2018\/12\/word-image-18.png\" rel=\"lightbox-6\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-42986 size-full\" src=\"https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2018\/12\/word-image-18.png\" alt=\"\" width=\"16\" height=\"16\" \/><\/a><\/p>\n<ul class=\"intro-text\">\n<li>The component that acts as a trigger for this component should be connected to this pin.<\/li>\n<\/ul>\n<p class=\"intro-text\"><strong>[value]<\/strong> <a href=\"https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2018\/12\/word-image-17.png\" rel=\"lightbox-7\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-42985 size-full\" src=\"https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2018\/12\/word-image-17.png\" alt=\"\" width=\"16\" height=\"16\" \/><\/a><\/p>\n<ul class=\"intro-text\">\n<li>Define the first Python value in the component\u2019s <strong>Properties<\/strong>. Connect input data to this pin.<\/li>\n<\/ul>\n<p class=\"intro-text\"><strong>[value2]<\/strong>\u00a0<a href=\"https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2018\/12\/word-image-17.png\" rel=\"lightbox-7\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-42985 size-full\" src=\"https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2018\/12\/word-image-17.png\" alt=\"\" width=\"16\" height=\"16\" \/><\/a><\/p>\n<ul class=\"intro-text\">\n<li>Define the second Python value in the component\u2019s <strong>Properties<\/strong>. Connect input data to this pin.<\/li>\n<\/ul>\n<hr \/>\n<h2 class=\"page-subheading\">Outputs<\/h2>\n<p class=\"intro-text\"><strong>out\u00a0<\/strong><a href=\"https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2018\/12\/word-image-17.png\" rel=\"lightbox-7\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-42985 size-full\" src=\"https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2018\/12\/word-image-17.png\" alt=\"\" width=\"16\" height=\"16\" \/><\/a><\/p>\n<ul class=\"intro-text\">\n<li>A mixed value. This is the output value from the Python Script\u2019s processing from the \u2018output\u2019 symbol set in the Python script. Not connecting this pin will produce a warning. If the \u2018out\u2019 pin is connected to a DataSet pin (green pin colour), then the data is passed along as a DataSet (Array) otherwise it is passed along as a single value. If the data is passed as a single value but the \u2018output\u2019 symbol is an array, the first element of the array is passed.<\/li>\n<\/ul>\n<p class=\"intro-text\"><strong>noData\u00a0<\/strong><a href=\"https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2018\/12\/word-image-18.png\" rel=\"lightbox-6\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-42986 size-full\" src=\"https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2018\/12\/word-image-18.png\" alt=\"\" width=\"16\" height=\"16\" \/><\/a><\/p>\n<ul class=\"intro-text\">\n<li>If the \u2018output\u2019 symbol is not declared in the Python script, the \u2018output\u2019 symbol is set to NULL or an array of zero length is returned, and the \u2018noData\u2019 pin is followed.<\/li>\n<\/ul>\n<p class=\"intro-text\"><strong>err\u00a0<\/strong><a href=\"https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2018\/12\/word-image-18.png\" rel=\"lightbox-6\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-42986 size-full\" src=\"https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2018\/12\/word-image-18.png\" alt=\"\" width=\"16\" height=\"16\" \/><\/a><\/p>\n<ul class=\"intro-text\">\n<li>If this pin is not connected, any errors which occur while processing the Python script are raised as errors and the processing is halted. If this pin is connected, the error is caught, the \u2018err\u2019 pin is followed, and processing continues.<\/li>\n<\/ul>\n<hr \/>\n<h2 class=\"page-subheading\">Example<\/h2>\n<p class=\"intro-text\">In the following example, the process checks whether the Python Script input 'value' is greater than the input 'value2'. If <strong>True<\/strong>, a True event is raised; if <strong>False<\/strong>, a False event is raised.<\/p>\n<p class=\"intro-text\">The Python script in the Python Script component used in this example is: \u2018output = value &gt; value2\u2019.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2023\/12\/image005.png\" \/><\/p>\n<p class=\"left-bar\">Related: <a href=\"https:\/\/oihelp.corporate.ifs.com\/help\/sentinel\/sentinel-studio\/sentinel-studio-primers\/\">Sentinel Studio Primers<\/a>,\u00a0<a href=\"https:\/\/oihelp.corporate.ifs.com\/help\/sentinel\/sentinel-studio\/creating-user-processes\/creating-a-new-user-process\/\">Creating a User Process<\/a>, <a href=\"https:\/\/oihelp.corporate.ifs.com\/help\/sentinel\/sentinel-studio\/usage-examples\/\">Usage Examples<\/a><\/p>\n<hr \/>\n<h2 class=\"page-subheading\">Configuration Options<\/h2>\n<p class=\"intro-text\">The following parameters have been added to the <a href=\"https:\/\/oihelp.corporate.ifs.com\/help\/sentinel\/administration\/sentinelconfig\/\">SentinelConfig.xml<\/a> file for additional configurability.<\/p>\n<table>\n<tbody class=\"intro-text\">\n<tr style=\"border: 1px solid #cccccc;\">\n<td><strong>MaximumPythonEngines<\/strong><\/td>\n<td>Maximum number of Python Engines.\u00a0<\/td>\n<\/tr>\n<tr style=\"border: 1px solid #cccccc;\">\n<td><strong>PythonDLLOverride<\/strong><\/td>\n<td>The full path to the python DLL to use in the engine, for custom Python installations only.\u00a0<\/td>\n<\/tr>\n<tr style=\"border: 1px solid #cccccc;\">\n<td><strong>PythonModules<\/strong><\/td>\n<td>Comma separated list of python modules to load into a running python script.\u00a0<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n","protected":false},"excerpt":{"rendered":"<p>The Python Script component is conceptually similar to the R Script component, where you can configure input pins, write a script to use these inputs and perform some logic, and set the output value. That output value would then be forwarded to the next node in the UDP graph.<\/p>\n<p class=\"continue-reading-button\"> <a class=\"continue-reading-link\" href=\"https:\/\/oihelp.corporate.ifs.com\/help\/sentinel\/sentinel-studio\/component-logic-functions\/python-script\/\">Read more<i class=\"crycon-right-dir\"><\/i><\/a><\/p>\n","protected":false},"author":1,"featured_media":42950,"parent":42147,"menu_order":12,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":"","_members_access_role":[],"_members_access_error":""},"categories":[9],"tags":[698,696,1148,726,694],"class_list":["post-64463","page","type-page","status-publish","has-post-thumbnail","hentry","category-tech-ref","tag-components-sentinel","tag-process-component","tag-python","tag-studio-sentinel","tag-user-process","Version-4-14","Product-sen"],"_links":{"self":[{"href":"https:\/\/oihelp.corporate.ifs.com\/help\/wp-json\/wp\/v2\/pages\/64463","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/oihelp.corporate.ifs.com\/help\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/oihelp.corporate.ifs.com\/help\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/oihelp.corporate.ifs.com\/help\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/oihelp.corporate.ifs.com\/help\/wp-json\/wp\/v2\/comments?post=64463"}],"version-history":[{"count":17,"href":"https:\/\/oihelp.corporate.ifs.com\/help\/wp-json\/wp\/v2\/pages\/64463\/revisions"}],"predecessor-version":[{"id":67976,"href":"https:\/\/oihelp.corporate.ifs.com\/help\/wp-json\/wp\/v2\/pages\/64463\/revisions\/67976"}],"up":[{"embeddable":true,"href":"https:\/\/oihelp.corporate.ifs.com\/help\/wp-json\/wp\/v2\/pages\/42147"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/oihelp.corporate.ifs.com\/help\/wp-json\/wp\/v2\/media\/42950"}],"wp:attachment":[{"href":"https:\/\/oihelp.corporate.ifs.com\/help\/wp-json\/wp\/v2\/media?parent=64463"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/oihelp.corporate.ifs.com\/help\/wp-json\/wp\/v2\/categories?post=64463"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/oihelp.corporate.ifs.com\/help\/wp-json\/wp\/v2\/tags?post=64463"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}