#Embedded Python

4 Followers · 292 Posts

Embedded Python refers to the integration of the Python programming language into the InterSystems IRIS kernel, allowing developers to operate with data and develop business logic for server-side applications using Python.

Documentation.

Article Alex Woodhead · Sep 5, 2023 8m read

Overview

The online documentation contains a reference Defining and Using Class Queries -

Customizing Stored Procedures with ObjectScript directly has been useful to access NoSQL storage and external messaging via integration, to present output in tabular format.

For example: An application that already uses 90% SQL interaction from a front end, can then also extend this access to the other 10% of required platform functionality, via the same SQL access.

The purpose of this article is to explore how to achieve the same effect via Embedded Python methods.

Figure 1: Stored Procedure as a SQ





0
0 472
Article Luis Angel Pérez Ramos · Aug 29, 2023 8m read

We continue with the series of articles based on the QuinielaML application.

In today's article I will describe how to work with the Embedded Python functionality available in InterSystems products.

Embedded Python allows us to use Python as a programming language within our productions, being able to take advantage of all the features available in Python. Here you can expand information about it.

First of all, let's remember what the designer of the architecture of our project is like:

Problematic to solve

In our case, we need to obtain the historical results of the First and Second

2
2 262
Article Luis Angel Pérez Ramos · Aug 22, 2023 4m read

Welcome dear members of the Community to the presentation and first article of a small project that will demonstrate the capabilities of InterSystems IRIS to provide full backup functionality for a web application developed in Angular. This article will be limited to presenting the concept as well as the InterSystems IRIS functionalities used in a general way, going into more detail in subsequent articles.

Welcome to QuinielaML!

Introduction

It is possible that you have already heard about InterSystems IRIS functionalities such as Embedded Python and IntegratedML, but surely you have not


0
1 573
Question Menno Voerman · Jul 13, 2023

Hi All,

We're doing our first babysteps with embedded Python and IRIS with an interoperability solution. We want to convert a CSV file to an Excel xlt file.

As service we've got a EnsLib.File.PassthroughService which picks up a csv file

As operation we've got a EnsLib.File.PassthroughOperation which writes the Excel file.

In the middle:

We've created an Business Process with an %Stream.GlobalCharacter in the Request and a %Stream.GlobalCharacter  in the Response.

But how do we get the %Stream.GlobalCharacter in the Python ClassMethod? Ideally I don't would like to write the stream first

3
0 565
Question Armin Gayl · Jul 28, 2023

Hello,

I need AES ECB with PKSC7 padding for an interface.
Unfortunately, the %SYSTEM.Encryption.AESEncode cannot do this.

Therefore I wanted to include the following python lib.
PyCrptydome -> https://pycryptodome.readthedocs.io/en/latest/index.html

We need to install the package offline on the system. So I downloaded it and put it in the MGR/Python/ directory.

However, when I try to install it, I get the following error message:

E:\HealthConnect\20201\bin>irispip install E:\HealthConnect\20201\Mgr\python\pycryptodome-3.18.0.tar.gz --target E:\HealthConnect\20201\Mgr\python pycryptodomex

11
0 379
Article Nicholai Mitchko · Oct 27, 2022 2m read
   _________ ___ ____  
  |__  /  _ \_ _|  _ \ 
    / /| |_) | || |_) |
   / /_|  __/| ||  __/ 
  /____|_|  |___|_|    

Starting in version 2021.1, InterSystems IRIS began shipping with a python runtime in the engine's kernel. However, there was no way to install packages from within the instance. The main draw of python is its enormous package ecosystem. With that in mind, I introduce my side project zpip, a pip wrapper that is callable from the iris terminal.

What is zpip?

zpip is a a wrapper for python pip that enables developers to quickly add packages to an instance through the InterS

6
1 878
Article Sowmiya Nagarajan · Jul 5, 2023 7m read

Previous postUsing AI to Simplify Clinical Documents Storage, Retrieval and Search

This post explores the potential of OpenAI's advanced language models to revolutionize healthcare through AI-powered transcription and summarization. We will delve into the process of leveraging OpenAI's cutting-edge APIs to convert audio recordings into written transcripts and employ natural language processing algorithms to extract crucial insights for generating concise summaries.

While existing solutions like Amazon Medical Transcribe and MedVoice offer similar capabilities, the focus of this post

2
2 1848
Article Muhammad Waseem · Mar 15, 2023 10m read

         

Hi Community,
In this article I will demonstrate the usage of InterSystems Embedded Python, We will cover below topics:

  • 1-Embedded Python Overview
  • 2-Usage of Embedded Python
    • 2.1- Using a Python Library from ObjectScript
    • 2.2- Calling the InterSystems APIs from Python
    • 2.3- Using ObjectScript and Python together
  • 3-Using python Built-in Functions
  • 4-Python Modules/Libraries 
  • 5-Embedded Python Use Cases















3
9 1296
Announcement Evgeny Shvarov · Jun 10, 2023

Hi colleagues!

InterSystems Grand Prix 2023 unites all the key features of InterSystems IRIS Data Platform!

Thus we invite you to use the following features and collect additional technical bonuses that will help you to win the prize!

Here we go!

  • LLM AI or LangChain usage: Chat GPT, Bard and others - 6
  • InterSystems FHIR SQL Builder- 5
  • InterSystems FHIR - 3
  • IntegratedML - 4
  • Native API - 3
  • Embedded Python - 4
  • Interoperability - 3
  • Production EXtension(PEX) - 2
  • Adaptive Analytics (AtScale) Cubes usage - 3
  • Tableau, PowerBI, Logi usage - 3
  • InterSystems IRIS BI - 3 
  • Columnar Index Usage - 1
  • Docker container usage - 2 
  • ZPM Package deployment - 2
  • Online Demo - 2
  • Unit Testing - 2
  • Implement InterSystems Community Idea - 4
  • First Article on Developer Community - 2
  • Second Article On DC - 1
  • Code Quality pass - 1
  • First Time Contribution - 3
  • Video on YouTube - 3
4
0 529
Article Ikram Shah · Jul 4, 2023 3m read

Problem

In a fast-paced clinical environment, where quick decision-making is crucial, the lack of streamlined document storage and access systems poses several obstacles. While storage solutions for documents exist (e.g, FHIR), accessing and effectively searching for specific patient data within those documents meaningfully can be a significant challenge.

Motivation

AI has made document search remarkably powerful. Question and answering over docs has never been easier with open-source tools like Chroma and Langchain to store and use vector embeddings to query across Generative AI APIs. Wi

0
2 731
Article Robert Cemper · Jun 20, 2022 7m read

My major interest is  Working with Globals in Embedded Python.
So I checked the available official documentation.

#1 Introduction to Globals
an attempt of a generic description of what a global is. Pointing to

#2 A Closer Look at ObjectScript
But where is Embedded Python ?
Way down you see

#3 Embedded Python

3.1 Embedded Python Overview
3.1.1 Work with Globals

Great if you have never seen a Global before
Otherwise a shocking primitive example
3.2 Using Embedded Python
Last hope: >>> but there is just NOTHING visible.
This is more than just disappointing! Even IRIS Native API for Python is more det

8
3 1346
Question Evgeny Shvarov · Oct 2, 2022

Hi folks!

How can I refer to a classmethod of the same class while coding another classmethod with Embedded python?

I know that I can call it with iris.cls(classname).MethodName(), but it's more cumbersome even comparing with ObjectScript, where I can call ..MethodName().

Compare ObjectScript:

do..SetupGame()

and the same call in EmbeddedPython:

    iris.cls('eshvarov.sample.SeaBattle.GamePython').SetupGame()

 

Thoughts?

6
0 455
Question Robbie Luman · Jun 27, 2023

Has anyone come across a good using Embedded Python to convert a Python List object to an IRIS %List object?

My use case is I want to open an SQL entry with an Objectscript class method, then pass some information from that row into a separate Python class method which will then create a Python List object, then have the Python class method return that list back to the Objectscript class method in such a way that the Python List can be converted to an IRIS %List object for me to then use in the Objectscript code.

3
0 491
Question Evgeny Shvarov · Jun 25, 2023

Hi folks!

I have a need to use symilar to $property function from Python. Here is the code:

obj=iris.cls('some.persistent.class')._New()

for property, value in data.items():

 $property(obj.property)=value ; I invented this

How could I do this? Any trick?

For now I plan to implement a helper function in iris that I will call, but I doubt also how can I transfer oref to IRIS.

Thoughts?

5
0 340
Question Evgeny Shvarov · Jun 25, 2023

Hi folks!

Consider I need to call a python function which name contains "_" symbol (which is quite often in Python). How it could be called from ObjectScript?

E.g. here is the code:

Set sm = ##class(%SYS.Python).Import("sample")

write sm.helloworld() ; function without _
white sm.hello_world() ; function with _ - won't compile.

Thanks in advance!

3
0 327
Article Alex Woodhead · Jun 20, 2023 2m read

Excuse if this is obvious to Python programmers but for those crossing over from ObjectScript this may be a useful tip.

The scenario is developing some Embedded python commands.

Testing out functionality is being confirmed via the shell:

$SYSTEM.Python.Shell()
 
Python 3.9.5 (default, Mar 14 2023, 06:58:44) [MSC v.1927 64 bit (AMD64)] on win32
Type quit() or Ctrl-D to exit this shell.
>>>

When Python evaluates an expression in the shell, it prints the result of the expression to the terminal.

>>> 1 + 2

3

It is quite easy to accidentally evaluate and print out values

>>> iris.cls(
0
0 295
Article Robert Cemper · Jun 13, 2023 2m read

Technology Strategy

When I started this project I had set myself limits:
Though there is a wide range of almost ready-to-use modules in various languages
and though IRIS has excellent facilities and interfaces to make use of them
I decided to solve the challenge "totally internal" just with embedded Python, SQL, ObjectScript
Neither Java, nor Nodes, nor Angular, PEX, ... you name it.
The combination of embedded Python and SQL is preferred. ObjectScript is just my last chance.

I was especially impressed how easy reading an HTTPS page with Python was.
On the other hand, I left Unit Test and Global M



0
0 247
Article Alex Woodhead · Jun 10, 2023 5m read

Written in reply to community post for can Python create HL7 Message dynamically.

Pre-requisites and setup

Use an integration enabled namespace.
Note: USER namespace is not enabled for interoperability by default.
If following suggest create a new interoperatibility namespace to explore functionality.

# Switch to
ZN "[Interoperability Namespace Name]"

# Launch interactive Python shell:
Do $SYSTEM.Python.Shell()

Script start

#Load dependencies

import datetime as dt
import uuid

# Cache current time in CCYYMMDDHHMMss format
hl7_datetime_now=dt.datetime.now().strftime('%Y%m%d%H%M%S')

0
2 659
Article Joel Solon · May 23, 2023 5m read

Methods written in ObjectScript can use pass-by-reference arguments to return information to the caller. Python doesn’t support pass-by-reference arguments, so Embedded Python in IRIS doesn’t support them either. That's it, that's the end of the post, hope you liked it. 😉 But wait, what about the Classic Rock & Roll?

Actually, since returning values in method arguments can be useful, this post demonstrates several ways to do this, between ObjectScript and Embedded Python. So let’s start with the simplest example: calling an ObjectScript method that already has a pass-by-reference argument fro

1
1 636
Article Henry Pereira · Jan 16, 2023 14m read

In this article, I will show you how one can easily create and read Microsoft Word documents using InterSystems IRIS with the leverage power of embedded Python.

Setup

First things first, let’s install the Python module called python-docx. There are a lot of modules to write MS Word files in Python. However, this one is the easiest one to use.

Just execute the following command on the terminal:

!pip3 install python-docx

If you are working with Docker, like I do, just add the following line to a Dockerfile

ENV PIP_TARGET=${ISC_PACKAGE_INSTALLDIR}/mgr/python RUN pip3 install python-docx

Let’s

template finished

7
7 1383
Article Evgeny Shvarov · May 16, 2023 1m read

Hi folks!

Just want to introduce you a new util to import CSV into IRIS - csvgenpy!

Install

USER>zpm "install csvgenpy"

Use:

do ##class(shvarov.csvgenpy.csv).Generate("file or url","table","schema")

Example:

USER>do ##class(shvarov.csvgenpy.csv).Generate("https://raw.githubusercontent.com/datasciencedojo/datasets/master/titanic.csv","titanic","data")

This will create table and class data.titanic in IRIS and will load the data.  you can proof it with:

USER>:sql

[SQL]USER>>select * from data.titanic

[SQL]USER>>select * from data.titanic

1. select * from data.titanic


passen
0
1 333
Article Dmitry Maslennikov · Feb 6, 2023 4m read

Let me introduce my new project, which is irissqlcli, REPL (Read-Eval-Print Loop)  for InterSystems IRIS SQL 

  • Syntax Highlighting
  • Suggestions (tables, functions)
  • 20+ output formats
  • stdin support
  • Output to files 

Install it with pip

pipinstallirissqlcli

Or run with docker

dockerrun-itcaretdev/irissqlcliirissqlcliiris://_SYSTEM:SYS@host.docker.internal:1972/USER

Connect to IRIS

$ irissqlcli iris://_SYSTEM@localhost:1972/USER -W
Password for _SYSTEM:
Server:  InterSystems IRIS Version 2022.3.0.606 xDBC Protocol Version 65
Version: 0.1.0
[SQL]_SYSTEM@localhost:USER> select $ZVERSION
+---------------------------------------------------------------------------------------------------------+
| Expression_1                                                                                            |
+---------------------------------------------------------------------------------------------------------+
| IRIS for UNIX (Ubuntu Server LTS for ARM64 Containers) 2022.3 (Build 606U) Mon Jan 30202309:05:12 EST |
+---------------------------------------------------------------------------------------------------------+
1 row in set
Time: 0.063s
[SQL]_SYSTEM@localhost:USER> help
+----------+-------------------+------------------------------------------------------------+
| Command  | Shortcut          | Description                                                |
+----------+-------------------+------------------------------------------------------------+
| .exit    | \q                | Exit.                                                      |
| .mode    | \T                | Change the table format used to output results.            |
| .once    | \o [-o] filename  | Append next result to an output file (overwrite using -o). |
| .schemas | \ds               | List schemas.                                              |
| .tables  | \dt [schema]      | List tables.                                               |
| \e       | \e                | Edit command with editor (uses $EDITOR).                   |
| help     | \?                | Show this help.                                            |
| nopager  | \n                | Disable pager, print to stdout.                            |
| notee    | notee             | Stop writing results to an output file.                    |
| pager    | \P [command]      | Set PAGER. Print the query results via PAGER.              |
| prompt   | \R                | Change prompt format.                                      |
| quit     | \q                | Quit.                                                      |
| tee      | tee [-o] filename | Append all results to an output file (overwrite using -o). |
+----------+-------------------+------------------------------------------------------------+
Time: 0.012s
[SQL]_SYSTEM@localhost:USER>
20
2 963
Article Luis Angel Pérez Ramos · May 8, 2023 6m read

Welcome, dear members of the community!

In this article we are going to demonstrate the great potential that IRIS/HealthConnect makes available to all its users with the use of Embedded Python and we are going to do it by developing a small production that will allow us to recognize and identify the faces present in a JPG file from some images that we will use as a reference.

Project configuration:

Let us begin! We have published the entire application in OpenExchange so that you only need to download and deploy it in Docker as you can read in the associated README file. As you will see, it

2
1 571
Article Seisuke Nakahashi · Apr 27, 2023 2m read

Let's say you have Python including variable-length arguments methods. How can you call it from ObjectScript? 

deftest1(*args):return sum(args)
  
deftest2(**kwargs):
  a1 = kwargs.get("a1",None)
  a2 = kwargs.get("a2",None)
  return a1+a2

You can call this "a.py" from ObjectScript as below.  For **kwargs argument, create Dynamic Object in ObjectScript and put it into methods with <variablename>... (3 dots) format. 

set a=##class(%SYS.Python).Import("a")
    write a.test1(1,2,3)   ;; 6set req={}
    set req.a1=10set req.a2=20write a.test2(req...)   ;; 30
0
1 341
Article Alex Woodhead · Apr 24, 2023 3m read

Multidimensional properties can be found on certain classes.

These operate as a collection of values much like a Python dictionary.

Examples of properties that might be encountered:

Class Property Description
%Net.HttpRequest Params Name value pair of form parameters
%Net.HttpResponse Headers

HTTP Headers returned with web content returned:

  • HTTPHeaders
  • EnsConfigName
  • Params
  • Content-Type
  • ResponseCode 
%Library.AbstractStream Attributes Name of originating file from FTP or mounted File system
%Library.AbstractResultSet Data Data Values indexed by
0
0 456
Article Alex Woodhead · Apr 16, 2023 4m read

Overview

Cross-Skilling from IRIS objectScript to Python it becomes clear there are some fascinating differences in syntax.

One of these areas was how Python returns Tuples from a method with automatic unpacking.

Effectively this presents as a method that returns multiple values. What an awesome invention :)

out1, out2 = some_function(in1, in2)

ObjectScript has an alternative approach with ByRef and Output parameters.

Do ##class(some_class).SomeMethod(.inAndOut1, in2, .out2)

Where:

  • inAndOut1 is ByRef
  • out2 is Output

The leading dot (".") in front of the variable name passes ByRef

0
0 591
Question Raj Singh · Mar 1, 2023

My general question is how to convert to a %Library.ListOfObjects to a Python "array-like" structure for use in Matplotlib.

Specifically, I have a Line Object which is comprised of a list of Points (see classes below). I want to pass the line to Python to create a Matplotlib Path.

Bonus points for converting the Point to a Python tuple!

Class geo.model.Point Extends %SerialObject
{
  Property latitude As %Float(MAXVAL = 90.0, MINVAL = -90.0, SCALE = 6);
  Property longitude As %Float(MAXVAL = 180.0, MINVAL = -180.0, SCALE = 6);
}
Class geo.model.Line Extends %SerialObject
{
  Prope
13
0 587