#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 Guillaume Rongier · Mar 29, 2023 1m read

Quick Tips: Total Productive Maintenance

Named parameters can be achieved with SQLAlchemy :  

from sqlalchemy import create_engine, text,types,engine

_engine = create_engine('iris+emb:///')

with _engine.connect() as conn:
    rs = conn.execute(text("select :some_private_name"), {"some_private_name": 1})
    print(rs.all())

or with native api

from sqlalchemy import create_engine, text,types,engine

# set URL for SQLAlchemy
url = engine.url.URL.create('iris', username='SuperUser', password='SYS', host='localhost', port=33782, database='FHIRSERVER')

_engine = create_engine(url)

with _engine.connect() as conn:
    rs = conn.execute(text("select :some_private_name"), {"some_private_name": 1})
    print(rs.all())
0
0 579
Article Guillaume Rongier · Nov 30, 2022 2m read

If you are using Python, you can use the built-in venv module to create a virtual environment. This module is the recommended way to create and manage virtual environments.

A virtual environment is a tool that helps to keep dependencies required by different projects separate by creating isolated python virtual environments for them. It solves the “Project X depends on version 1.x but, Project Y needs 4.x” dilemma, and keeps your global site-packages directory clean and manageable.

So if like me you work a lot with Python, you can use the venv module to create a virtual environment for your project. This will allow you to install packages without affecting the global Python installation.

You will find here two neat alias to create and activate a virtual environment.

Python aliases

alias venv="python3 -m venv .venv; source .venv/bin/activate"
alias irisvenv="python3 -m venv .venv; source .venv/bin/activate; pip install https://github.com/grongierisc/iris-embedded-python-wrapper/releases/download/v0.0.3/iris-0.0.3-py3-none-any.whl"
3
2 2083
Question Elijah Cotterrell · Mar 6, 2023

I'm curious about how embedded Python is handled by %CSP classes, particularly in the case of defining REST endpoints on IRIS.
Here is a simple dispatch class for the endpoint /api/pythonapp on my local IRIS instance (2022.3):

Class Python.App.Dispatch Extends%CSP.REST
{

XData UrlMap [ XMLNamespace = "https://www.intersystems.com/urlmap" ]
{
<Routes>
    <Route Url="/test" Method="GET" Call="Hello" />
</Routes>
}

ClassMethod Hello() As%Status [ Language = python ]
{
    import iris

    print('Hello World!')
    return True
}

}

Making a GET request to <ip:webport>/api/p


4
0 338
Question Kurt Hofman · Feb 10, 2023

Hello,

I'm starting testing embedded python and external libraries.

When I try to use the win32api-library I get the following error :

<THROW> *%Exception.PythonException  230 ^^0^ <class 'ModuleNotFoundError'>: No module named 'win32api' -

This is my code :

ClassMethod CreateDocument(path As %String) [ Language = python ]
{
import win32api

...
}
 

The librarie is visible in C:\InterSystems\IRIS\mgr\python\win32.

Am I doing something wrong ?

Regards,

Kurt Hofman,

ASCI nv.

7
0 704
Article Muhammad Waseem · Feb 9, 2023 2m read

Hi Community,
In this article I will demonstrate below steps to add Interactive map and visualize geographic data to web application:

  • Step1 : Install Application
  • Step2 : Create CSP Page
  • Step3 : Extend dc.IrisGeoMap.Folium class
  • Step4 : Invoke DrawGeoDetails() Method

So Let us start.
 

Step1 : Install Application

First of all we need to install iris-geo-map application by using ZPM

zpm "install iris-geo-map"

0
1 416
Question Dmitry Maslennikov · Feb 6, 2023

So, I know that I can return a SQL Error message from my SQL Procedure written in ObjectScript, with code like this

$ cat <<EOF | irissqlcli iris://_SYSTEM:SYS@localhost:1972/USER
CREATEorREPLACEPROCEDUREtest()
LANGUAGE OBJECTSCRIPT
{
 SET %sqlcontext.%SQLCODE = 400SET %sqlcontext.%ROWCOUNT = -1SET %sqlcontext.%Message = "test error message"
};

CALLtest();

EOF
[SQLCODE: <-400>:<Fatal error occurred>]
[Location: <SPFunction>]
[%msg: <test error message>]

But I did not find how to do it with Python. I can't find %sqlcontext variable available there

1
0 255
Article Muhammad Waseem · Feb 6, 2023 3m read

Hi Community
In this article, I will demonstrate the functionality of my app iris-geo-map
 

IRIS Geo Map application is a tool to visualize geographic data by generating interactive maps by using Embedded Python functionality. Application is using Folium Python library

folium builds on the data wrangling strengths of the Python ecosystem and the mapping strengths of the leaflet.js library. Manipulate your data in Python, then visualize it in on a Leaflet map via folium. folium makes it easy to visualize data that’s been manipulated in Python on an interactive leaflet map. It enables both the









0
0 474
Question Oliver Wilms · Feb 5, 2023

I copied a 5 MB messages.log file to AWS where I have iris-log-viewer app deployed. I ran the test to see how it takes in IRIS code to import the lines into a persistent table:

IRISAPP>set m5mb="/home/irisowner/irisdev/messages.old_20221231.log"

IRISAPP>

IRISAPP>do ##class(otw.log.irislogreader).Test1(m5mb)
Test1 begins at 02/05/2023 12:49:30
ReadLogLines
/home/irisowner/irisdev/messages.old_20221231.log
Open
Test1 ends at 02/05/2023 12:49:34
Test1 execution time: 3.500789

select count(*) from otw_log.Log

63239

It took 3.5 seconds and I had 63239 lines in the table. Then I tried to test usi

7
0 332
Article Oliver Wilms · Feb 5, 2023 2m read

As my entry into InterSystems Developer Tools Contest happening now I have been working on an alternative to the Console Log Viewer web page provided as part of InterSystems IRIS Management Portal. Console log is a file called messages.log. It is what InterSystems support asks me to send to them when I open a support ticket. Working on IRIS containers deployed in the cloud it is not straight forward to copy the messages.log file to a place where I can attach it to an email. Iris-log-viewer app provides a Download link to download messages.log from any browser. 

I observed it takes a coupl

0
1 232
Article Oliver Wilms · Feb 4, 2023 1m read

I developed iris-log-viewer on a work laptop using an older version of IRIS. My messages.log file has nearly 10k lines. I noticed it takes a couple of seconds to read messages.log file line by line, import each line into a persistent class, and display messages on my screen. I wonder if Python can speed up the process.

I developed EmbeddedPython class. Initially I imported a python script file to read messages.log file in Python. Later I figured out how to write a Python classMethod where I invoke IRIS classMethod to import one line at a time while reading messages.log.

I developed iri

0
0 297
Article Yuri Marx · Jul 20, 2022 6m read

Python has become the most used programming language in the world (source: https://www.tiobe.com/tiobe-index/) and SQL continues to lead the way as a database language. Wouldn't it be great for Python and SQL to work together to deliver new functionality that SQL alone cannot? After all, Python has more than 380,000 published libraries (source: https://pypi.org/) with very interesting capabilities to extend your SQL queries within Python. This article details how to create new SQL Stored Procedures in InterSystems IRIS Database using Embedded Python.

Python libraries used as samples

This art


https://raw.githubusercontent.com/yurimarx/iris-sql-python-sample/main/screen2.png

3
0 1349
Article Yuri Marx · Jan 9, 2023 7m read

Applications that work with bill payments and receipts, as well as the delivery and inventory of items, generally require the use of barcodes or QR Codes. The latter is used in even broader scenarios since the QR Code can store more information than a simple bar code. Thus, it is important to have the ability to generate barcodes and QR Codes or read the data stored in them from an image or a PDF. This article will show you how to do this using Python and some of its free libraries.

Pyzbar library

The pyzbar library reads one-dimensional barcodes and QR codes from Python 2 and 3 using the zb




Read PDF barcodes

1
2 1790
Question Anderson Negreli · Jan 2, 2023

 Hello, good afternoon! (or good morning or good evening)
 

I was doing some very basic tests, based on the documentation, using Python in Studio.
I decided to call a python method through the Studio's own terminal as a demonstration, but the result was different from the terminal result:
Code:

Class User.EmbeddedPython
{

// Write ##class(User.EmbeddedPython).Test()/// DescriptionClassMethod Test() As%Status [ Language = python ]
{
    # print the members of the Fibonacci series that are less than 10print("Fibonacci series")
    a, b = 0, 1while a < 10:
        print(a,

3
0 341
Article Rizmaan Marikar · Jul 27, 2022 6m read

What is Web Scraping:

In simple terms, Web scrapingweb harvesting, or web data extraction is an automated process of collecting large data(unstructured) from websites. The user can extract all the data on particular sites or the specific data as per the requirement. The data collected can be stored in a structured format for further analysis.


Steps involved in web scraping:

  1. Find the URL of the webpage that you want to scrape
  2. Select the particular elements by inspecting
  3. Write the code to get the content of the selected elements
  4. Store the data in the required format

It’s that simple














12
9 1871
Article Jean Millette · Oct 26, 2022 7m read

TL;DR: This article describes an introductory-level project that exercises some string-manipulation functions in both ObjectScript and Python…with specs from a song.

After you’ve written your first “Hello World!” program, are you ready for a new fun challenge?  An old, very popular (at the time) song may be just what you need.

While I was driving around on vacation in southern Maine, the local “Legends” radio station played the old classic, “The Name Game” by Shirley Ellis (https://www.youtube.com/watch?v=5MJLi5_dyn0). If the listener resists the urge to get up and dance and instead listens





3
0 385
Article José Pereira · May 2, 2022 16m read

Introduction

This article aims to give an introduction to what gRPC is and an example of how to play with the official Hello World using IRIS Embedded Python.

You can find all the code exposed here, in this project repo.

gRPC

The gRPC (gRPC remote procedure call) is an API architectural style based on the RPC protocol. The project was created by Google in 2015 and is licensed under Apache 2.0. Currently, the project is supported by the Cloud Native Computing Foundation (CNCF).

Successful cases of its use are related to connecting services between backends, such as services in microservices sty

5
0 2110
Article Yaron Munz · Jul 12, 2022 5m read

Overview

We started to use Azure Service Bus (ASB) as an enterprise messaging solution 3 years ago. It is being used to publish and consume data between many applications in the organization. Since the data flow is complex, and one application’s data is usually needed in multi applications the “publisher” ---> ”multiple subscribers” model was a great fit. The ASB usage in the organization is dozens of millions of messages per day, while IRIS platform is having around 2-3 million messages/day.

The Problem with ASB

When we started with the ASB integration, we found that the AMQP protocol is n

3
3 857
Question Evgeny Shvarov · Oct 21, 2022

Hi developers!

Those who code IRIS solutions in VSCode using Docker often use the convenient ObjectScript menu, which contains links to Management Portal, Class Reference, Unittest portal, Productions, etc.

While drilling down to a Dev Container to code Embedded Python there is no such option, at least within my settings:

So I don't know how to connect to it. 

Thoughts?

6
0 425
Article Evgeny Shvarov · Oct 24, 2022 4m read

Hi developers!

Let me share with you a minimal embedded python template, that I can recommend as a starting point for any general project with InterSystems IRIS that will use embedded python.

Features:

  • Embedded Python ready;
  • Examples of 3 ways of Embedded python development;
  • VSCode development ready;
  • Docker enabled;
  • Online demo enabled;
  • ZPM First development ready.

Let's discuss the features below!

0
0 1153
Question Evgeny Shvarov · Oct 20, 2022

Hi, devs!

What's the way to call the methods of %SYSTEM class from python?

I tried this way:

print(iris.cls('_SYSTEM.OBJ').Version())

and getting an error:

Traceback (most recent call last):
  File "<input>", line 1, in <module>
RuntimeError: iris.class: error finding class

Here is how it works in ObjectScript:

USER>w##class(%SYSTEM.OBJ).Version()
InterSystems IRIS Version 2022.1.0.209
USER>

Thoughts?

4
1 366
Question Evgeny Shvarov · Oct 20, 2022

Hi folks!

I'm playing with Embedded python with IRIS trying to do some 'hello-world' exercises.

I'm running IRIS in container and have the following python code:

# Program to test coding with IRIS

print('Hello World')

# Run IRIS Class Method import iris
print(iris.cls('dc.sample.ObjectScript')).Test()

So, when I execute it, I get the following:

$ /usr/irissys/bin/irispython /irisrun/repo/python/app.py
Hello World
Traceback (most recent call last):
  File "/irisrun/repo/python/app.py", line 7, in <module>
    import iris
  File "/usr/irissys/lib/python/iris.py", line 14
5
0 677
Article Lucas Enard · Aug 17, 2022 9m read

In this GitHub based on this InterSystems community rest api template Guillaume and I have created this example of all the import CRUD operations usable using ONLY Python on IRIS and using Flask.

Using the IRIS ORM or by simply doing SQL requests as both methods are seen in the GitHub.

1. intersystems-iris-docker-rest-template

This is a template of a REST API application built in python in InterSystems IRIS. It also has OPEN API spec, can be developed with Docker and VSCode.






Here is an example

13
0 924