Find

Article
· Sep 2, 2024 4m read

IRIS Native Python Part-2

In the preceding section, we explored the installation process and initiated the writing of the IRIS in native Python. We will now proceed to examine global traversal and engage with IRIS class objects.

 get: this function is used to get values from the traversal node.

def traversal_firstlevel_subscript():
    """
    ^mygbl(235)="test66,62" and ^mygbl(912)="test118,78"
    """
    for  i in irispy.node('^mygbl'):
        print(i, gbl_node.get(i,''))

 

node and items: single level traversal with node and get the values same as $Order(^mygbl(subscript), direction, data)

#single level traversal
def traversal_dollar_order_single_level():
    for  sub,val in irispy.node('^mygbl').items():
         print('subscript:',sub,' value:', val)
# multi level traversal
def traversal_dollar_order_multi_level():
    for  sub,val in irispy.node('^mygbl').items():
         print(f'sub type is: {type(sub)} {sub} and val type is {type(val)}')
         for sub1,val1 in irispy.node('^mygbl',sub).items():
            print('subscript:',sub1,' value:', val1)
        

 

nextsubscript: unlike above code you can use nextsubscript to get the next subscript easily

def traversal_dollar_order_use_nextsubscript():
      direction = 0
      next_sub = ''
      while next_sub != None:
            next_sub = irispy.nextSubscript(direction,'^mygbl', next_sub)
            print(f'next subscript = {next_sub}' )
            next_sub1=''
            if next_sub == None:return
            while next_sub1 != None:
                next_sub1 = irispy.nextSubscript(direction,'^mygbl',next_sub,next_sub1)
                print(f'1st subscript = {next_sub} next subscript {next_sub1}' )

 

Classes and Objects

You can call the classmethods, methods from the class definition by using the specific function. As  I mentioned earlier Typecast Methods are crucial to get the proper response from IRIS

Prior to this, it is important to note that, Unlike IRIS datatypes, which we can treat everything as strings, Python data types such as int, str, bool, and list are classified as objects. Each of these types possesses its own attributes and methods; for instance, the Python string type includes functions such as .upper() and .lower(), which are not applicable to other data types. Consequently, IRIS is equipped with the ability to convert IRIS string values into Python-supported datatype objects through the use of Typecast Methods. This functionality is similarly applicable to class methods, user-defined functions, and procedures. Alternatively, one must utilize Python's type conversion functions to achieve the desired data type.

 

classMethodValue: Call the Classmethod from python without initiate the object same as ( ex: Do ##Class(Test.MYTest).FirstNameGetStored(1) ) and get "string" default value in python. There are different typecast method available for expected return value instead of string. Please refer below.

def get_clsmethod_value():
    print(irispy.classMethodValue('Test.MYTest','FirstNameGetStored',1)) #return string 
    date_horolog = irispy.classMethodInteger('Test.MYTest','GetHorolog') #return +$H value
    print(irispy.classMethodVoid('Test.MYTest','SetTestGlobal','test')) # no return resposne

classMethodObject: Important function to Instantiate a new IRIS object or open the existing object. Set the properties and invoke instance methods etc...

New IRIS object: Initiate the class object for Test.MYTest and set the properties.

def cls_object_new():
    """
    initiate new object and store
    """
    iris_proxy_obj = irispy.classMethodObject('Test.MYTest','%New','ashok','kumar')

    birthdate_horolog = irispy.classMethodInteger('Test.MYTest','GetHorolog','12/12/1990')
    horolog = irispy.classMethodInteger('Test.MYTest','GetHorolog')
    iris_proxy_obj.set('BirthDate',birthdate_horolog) #set birthdate property
    iris_proxy_obj.set('RegisteredDate',horolog) #set the RegisteredDate property
    status = iris_proxy_obj.invoke('%Save') #call instance method
    return status


Open IRIS Object: In the below code. Open Test.MyTest class object and get both Birthdate and RegisteredDate values from the objectid "2" and convert RegisteredDate as python list 

def cls_object_open():
    iris_proxy_obj = irispy.classMethodObject('Test.MYTest','%OpenId',2)
    birth_date = iris_proxy_obj.get('BirthDate')
    full_name iris_proxy_obj.InvokeString("GetFullName")
    data = [birth_date, iris_proxy_obj.get('RegisteredDate')]
    return data

IRIS Class definition which I used for the class and object python code demo

 
Spoiler

 

Typecast methods:

these are few type cast method for retrieve proper return values from IRIS

classMethodValue()   - for call general classmethods

classMethodInteger - Return integer value
classMethodVoid - No return value
classMethodValue - default string
classMethodFloat - float return value

invoke() - is used to call the instance methods. You have to initiate the object for call this invoke functions

invokeString  - default string
invokeFloat - float return value
invokeInteger  -  return integer value

 

Will cover the functions, procedure calls in routines and other functionality in the upcoming article.

Discussion (0)1
Log in or sign up to continue
Question
· Sep 2, 2024

How to convert date in "YYYY-MM-DDTHH:MM:SSZ" format to "yyyymmddhhmmss" format?

I'm trying to convert date - 2023-09-28T20:35:41Z to BST/GMT format. I tried with $ZDT($ZDTH("2023-09-28T20:35:41Z",-2),8,1) but it's giving the output as '19700101 01:33:43' and looks link the date format in $ZDTH specified is wrong. Any inputs or solution would be appreciated.   

4 Comments
Discussion (4)2
Log in or sign up to continue
Article
· Sep 2, 2024 2m read

configuration of Flexible Python Runtime Feature in IRIS 2024.2

Hello Community,

This article aims to walk you through the process of setting up and utilizing the Flexible Python Runtime Feature for embedded Python. Prior to version 2024.2, Intersystems IRIS installer included a preinstalled version of Python, You can find the Python libraries and application files located in the \lib\python directory within your IRIS installation folder (for example, C:\InterSystems\IRIS20242\lib\python).

However, starting with version 2024.2, the IRIS installer no longer includes Python installation by default. Consequently, you will not find these files in the aforementioned directory. It is necessary for you to install the required version of Python to effectively work with embedded Python in IRIS.

Let's proceed to configure the flexible runtime feature within my IRIS environment.

I've installed the community version 2024.2 on my machine and I tried to connect the python shell immediately in IRIS terminal.

USER>Write $ZV
IRIS for Windows (x86-64) 2024.2 (Build 247U) Tue Jul 16 2024 09:57:03 EDT
USER>Do $SYSTEM.Python.Shell()
ERROR #5002: ObjectScript error: <OBJECT DISPATCH>Shell+16^%SYS.Python.1 *Failed to Load Python: Check documentation and messages.log, Check CPF parameters:[PythonRuntimeLibrary,PythonRuntimeLibraryVersion], Check sys.path setup in: $INSTANCE/lib/python/iris_site.py.

It throws an error because of missing configuration of PythonRuntimeLibrary and PythonRuntimeLibraryVersion values are empty( note: I already set the PythonRuntimeLibraryVersion version )

Now. I’ve already installed the python 3.12.5 in my system and configure the values in the settings.

PythonRuntimeLibrary  - “C:\Program Files\Python312\python3.dll”
PythonRuntimeLibraryVersion - 3.12

Once it’s configured. I executed the Do $SYSTEM.Python.Shell() again and it successfully get in to the python shell

 

Note: Flexible python runtime feature documentation and as per the documentation. This feature is not supported for all operating system

5 Comments
Discussion (5)4
Log in or sign up to continue
Announcement
· Sep 2, 2024

InterSystems Open Exchange Applications Digest, August 2024

Hello and welcome to the August 2024 Open Exchange Newsletter.
General Stats:
2 new apps in August
502 downloads in August
976 applications all time
36,294 downloads all time
2,801 developers joined
New Applications
First-Vector-Search-on-IRIS
By Seisuke Nakahashi
DataAI
By Irina Yaroshevskaya
New Releases
irislab by Dmitry Maslennikov
v1.1.0
Added Login page support Multiple namespaces support fixed classes source code display
v1.1.3
fixed running on different versions
v1.1.4
fixed bugs for 2024.1
v1.1.5
fixed bugs for 2024.1
Git for Shared Development Environments by Timothy Leavitt
v2.4.1

Added

  • New API endpoint that accepts git commands as array instead of string (#437)

Fixed

  • Fixed JS errors in Studio on certain operations (#416)
  • Add menu option disabled for unsaved files (#420)
  • Fixed issue where selecting different item in stash list didn't update diff view (#265)
  • Tooltip in workspace now shows user who made uncommitted change if not current user (#411)
  • Files are added to source control upon creation properly (#404)
  • Files show in uncommitted queue when automatically added (#407)
  • WebUI workspace view now works properly for filenames with spaces (#423)
  • Fixed error popups in interop editors in Studio on 2024.1 (#417)
  • Reintroduced amend (#425)
  • Git operations that import items into IRIS now report output from compilation (#426)
  • Double quotes now permissible in commit messages (#433)
Test Coverage Tool by Timothy Leavitt
v4.0.0

[4.0.0] - 2024-08-01

Changed

  • #29: As a consequence of this change, the minimum supported platform version is 2022.1

Added

  • #29: Track code coverage for embedded python methods in .cls files
  • #42: Added a listener interface and manager with an associated user parameter, allowing the user to broadcast output on test method/case/suite completion.
v4.0.1

[4.0.1] - 2024-08-16

Fixed

  • #45: Fixed Python line 0 tracking for 2024.2
  • #46: Fix for bug caused by UpdateComplexity calling GetCurrentByName unnecessarily and causing dependency issues
  • #47: Fixed mapping issue caused by empty lines at top of Python method not showing up in compiled Python
  • #48: When the Line-By-Line Monitor resumes after pausing, resume the Python tracer too
  • #49: Added user parameter for preloading python modules (fixes problem of pandas breaking sys.settrace on first import)
v4.0.2

[4.0.2] - 2024-08-16

Fixed

  • #51: Don't start (and stop) the ObjectScript and Python monitors if there are no ObjectScript/Python routines being tracked respectively, fixes error from trying to start/stop the %Monitor.System.LineByLine with no routines
v4.0.3

[4.0.3] - 2024-08-19

Fixed

  • #52: Method mapping code now doesn't use AST's endline_no property to support older python versions
  • #53: Ignore traced commands from code without a class name
DeepSeeWeb by Anton Gnibeda
v4.0.4
  • added support for exclude filters in KPI widgets (#303)
v4.0.5
  • added KPI drillthrough support for charts (analytics/#421)
  • fixed issue with sharing dashboard/widgets using base64 (analytics/#270)
  • added option to disable tile pushing (analytics/#310)
v4.0.6
  • changing tile push option now applied immediately without page refresh (#310)
v4.0.7
  • fixed issue with colors on map widget
v4.0.8
  • fixed issue with empty map for non-geojson maps
sqlzilla by Henrique Dias
v1.0.2
  • Improved UX/UI
  • Improved LLM prompt generation
v1.0.3
  • Code refactoring
  • Storing examples in a table
  • Button for adding examples
  • Initial examples for sample schemas
  • SQL execution error handling
IRIS RAG App by Alex Alcivar
v1.0.2
Removed Demo
SQL DATA LENS by Andreas Schneider
v3.19.0
  • ENH: Setup improved
  • ENH: The licensing system has been updated to fix issues with error code 28 based on a disabled network adapter (PART2) The activation process needs to read all of a computer’s components to get an accurate “fingerprint” of the computer, and this includes all real (aka non-virtualised) network adapters attached to the computer.
  • ENH: JNA Interface lib updated to 5.14
objectscript-package-example by Evgeny Shvarov
v1.0.2
IPM installation fixed
iris-analytics-template by Evgeny Shvarov
v1.1.7
Fix source control settings for the dashboard
isc-perf-ui by Timothy Leavitt
v2.0.0

[2.0.0] - 2024-08-16

Added

  • New home tab allowing the user to run and see the results of TestCoverage on their unit tests
  • New historical coverage tab showing class level results for past TestCoverage runs

Changed

  • Authentication now uses standard IRIS Login

Fixed

  • Fixed handling for authentication headers to suppress the browser's credential prompts
  • Fixed export behavior when developing with git-source-control and a modern IPM version
  • Updated documentation around node/npm requirement

Security

  • Bumped various dependency versions
iris-bi-utils by Evgeniy Potapov
v1.0.1
  • Check cubes build first
isc-codetidy by Timothy Leavitt
v1.1.7

[1.1.7] - 2024-08-20

Fixed

  • Add Foreign Keys to class items to resequence (#51)
  • Prevented auto-indentation of embedded Python lines until Python linting is implemented (#52)
v1.1.8

[1.1.8] - 2024-08-27

Fixed

  • Fixed auto indent of comments inside dynamic arrays removing white space (#50)
  • Fixed conversion of #; comments at start of line in routines causing syntax error (#55)
  • Fixed resequencing of Projections and XDatas to give assigned positions (#54)
BridgeWorks VDM by Tony Coffman
v2024.8.21
What's New?
  • VDM's now has a built-in self-correction process for Duplicate Appointments that would sometimes cause errors when people are using the Scheduler. (Task 1631)
  • We have adjusted how the selection process works in the Scheduler - Job creation so that you no longer need to select an execution to have access to the execution options (Add Wizard, Edit Wizard, etc.). (Task 1639)
  • We have removed the legacy folders (Maps / VDMDB) that were being created when installing VDM. (Task 1642)
BridgeWorks WebReports by Tony Coffman
v2024.8.21
What's New?
* WebReports's now has an execution date filter on the Completed Reports page. (Feature 1633)
Intersystems-Monitoring by Teunis Stolker
v1.0.16
Added StopProduction for when monitoring is explicitly disabled
iris-datapipe by Alberto Fuentes
v2.0.0
  • Added Dashboard
  • Added Pipes definition
  • Improved representation of each record
  • Improved security
  • Added new examples
Most downloaded
WebTerminal
By Nikita Savchenko
MDX2JSON
By Eduard Lebedyuk
DeepSeeWeb
By Anton Gnibeda
ssl-client
By Evgeny Shvarov
interoperability-embedded-python
By Guillaume Rongier
iris-web-swagger-ui
By Maks Atygaev
ClassExplorer
By Nikita Savchenko
iris-fhir-portal
By Henrique Dias
August, 2024Month at a GlanceInterSystems Open Exchange
Discussion (0)1
Log in or sign up to continue
Discussion (0)1
Log in or sign up to continue