#Python

8 Followers · 487 Posts

Python is an interpreted high-level programming language for general-purpose programming. Created by Guido van Rossum and first released in 1991, Python has a design philosophy that emphasizes code readability, notably using significant whitespace

Official site.

InterSystems Python Documentation.

Question Gautam Rishi · Jun 17, 2023

I want to connect IRIS system as it has all the database tables. on top of that I am creating a REST API in python. How can I connect to IRIS DB. here is my example code for connection

def connect():

connection_string = "localhost:1972/USER"

username = "_SYSTEM"

password = "SYS"

conn = iris.connect(connection_string, username, password)

after this connection is created but how can I get tables data. Please let me know more about how we can integrate IRIS database into a python REST API.

1
0 497
Article Alex Woodhead · Jun 15, 2023 6m read

Demonstration example for the current Grand Prix contest for use of a more complex Parameter template to test the AI.

Interview Questions

There is documentation. A recruitment consultant wants to quickly challenge candidates with some relevant technical questions to a role.

Can they automate making a list of questions and answers from the available documentation?

Interview Answers and Learning

One of the most effective ways to cement new facts into accessible long term memory is with phased recall.

0
0 1668
Article Lucas Enard · Aug 2, 2022 8m read

On this GitHub you can find all the information on how to use a HuggingFace machine learning / AI model on the IRIS Framework using python.

1. iris-huggingface

Usage of Machine Learning models in IRIS using Python; For text-to-text, text-to-image or image-to-image models.

Here, models as example :

2. Installation

2.1.

5
1 944
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:

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

So that's it!

Basically it does the same thing as csvgen does, but uses python library sqlalchemy which works because of embedded python and sqlalchemy-iris by @Dmitry Maslennikov

P.S. csvgenpy can import some "complicated" for csvgen csv as

0
1 353
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

pip install irissqlcli

Or run with docker

docker run -it caretdev/irissqlcli irissqlcli iris://_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 30 2023 09: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 1036
Article Muhammad Waseem · May 1, 2023 5m read


 

The Jupyter Notebook is an open source web application that can be used to create and share documents that contain live text, code, equations and visualizations. It is maintained by the people at Project Jupyter.

Jupyter name comes from the core supported programming languages that it supports: Julia, Python, and R.
It allows users to write code in "cells," which are blocks of code that can be executed individually or together. This makes it easy to test and debug code, as well as to organize and present complex analyses.

0
0 578
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)returntest2

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. 


Do you like playing ChatGPT? With this way, you can call ChatGPT APIs not only from Language=python method but from ObjectScript world.  As described in OpenAI page , ChatCompletion.create method of OpenAI library has **kwargs argument.

0
1 346
Article Maria Nesterenko · Apr 20, 2023 5m read

Many factors affect a person's quality of life, and one of the most important is sleep. The quality of our sleep determines our ability to function during the day and affects our mental and physical health. Good quality sleep is critical to our overall health and well-being. Therefore, by analyzing indicators preceding sleep, we can determine the quality of our sleep. This is precisely the functionality of the Sheep's Galaxy application.

5
0 412
Article Oliver Wilms · Apr 21, 2023 2m read

We have a rule to disable a user account if they have not logged in for a certain number of days. IRIS Audit database logs many events such as login failures for example. It can be configured to log successful logins as well. We have IRIS clusters with many IRIS instances. I like to run queries against audit data from ALL IRIS instances and identify user accounts which have not logged into ANY IRIS instance.

1
0 247
Article Oliver Wilms · Apr 21, 2023 1m read

Within IRIS I defined a task to export audit data every day.

I provide some sample files in my GitHub repo.

I wrote ObjectScript code to import all files into otw.audit.consolidator class.

I want to use Python SQLAlchemy, pandas and sqlalchemy-iris (created by Dmitry Maslenikov) to copy consolidated audit data from my consolidator class in my IRIS container to my InterSystems Cloud SQL deployment.

I updated my Dockerfile to pip3 install sqlalchemy-iris and pandas (dataframes).

docker-compose build –no-cache in my personal AWS took 700 seconds.

1
0 244
Article Muhammad Waseem · Apr 17, 2023 4m read

Hi Community,
In this article, I will introduce my application iris-mlm-explainer

This web application connects to InterSystems Cloud SQL to create, train, validate, and predict ML models, make Predictions and display a dashboard of all the trained models with an explanation of the workings of a fitted machine learning model. The dashboard provides interactive plots on model performance, feature importances, feature contributions to individual predictions, partial dependence plots, SHAP (interaction) values, visualization of individual decision trees, etc.

6
1 499
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 and for Output.

0
0 606
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 596
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 2150
Article Harry Tong · Feb 21, 2023 2m read

InterSystems IRIS 2022.2 has Native SDK for Python (https://docs.intersystems.com/iris20222/csp/docbook/Doc.View.cls?KEY=PA…).

We know how to traverse a global data structure using IRIS Object Script $Order function.

SET""FOR

How to do the same from Python using IRIS Native SDK for Python? Here is a code example:

'127.0.0.1'
2
0 604
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):

ClassExtends%CSP.REST

Making a GET request to <ip:webport>/api/pythonapp/test does not return an error, but returns "wstr%SYS.csp" which is interesting.


Can anyone shed light on this behaviour or has achieved an embedded Python dispatch class without passing values to ObjectScript methods for writing?

4
0 357
Question Dean Rochester · Feb 21, 2023

In article

https://community.intersystems.com/print/518106

Traceback (most recent call last):
  File "c:\Users\rochesterd\PythonScripts\fhir_stuff\fhir-client-python-main\fhir-client-python-main\src\client.py", line 57, in <module>
    patient0 = Patient.parse_obj(patients_resources.search(
AttributeError: 'NoneType' object has no attribute 'serialize'

8
0 370
Article Muhammad Waseem · Feb 10, 2023 5m read

Hi Community,

This article is a continuation of my article about  Getting to know Python Flask Web Framework

In this article, we will cover the basics of topics listed below:

1. Routing in Flask Framework
2. Folder structure for a Flask app (Static and Template)
3. Getting and displaying data in the Flask application from IRIS.

So, let's begin.

0
0 1981
Article Ricardo Paiva · Feb 9, 2023 3m read

Schematron is a rule-based validation language for making assertions about the presence or absence of certain patterns in XML documents. A schematron refers to a collection of one or more rules containing tests. Schematrons are written in a form of XML, making them relatively easy for everyone, even non-programmers, to inspect, understand, and write

0
0 1571
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
CREATE or REPLACE PROCEDURE test()
LANGUAGE OBJECTSCRIPT
{
 SET %sqlcontext.%SQLCODE = 400
 SET %sqlcontext.%ROWCOUNT = -1
 SET %sqlcontext.%Message = "test error message"
};

CALL test();

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 270
Article Guillaume Rongier · Dec 14, 2021 10m read

Iris-python-template

Template project with various Python code to be used with InterSystems IRIS Community Edition with container.

Featuring :

  • Notebooks
    • Embedded Python Kernel
    • ObjectScript Kernel
    • Vanilla Python Kernel
  • Embedded Python
    • Code example
    • Flask demo
  • IRIS Python Native APIs
    • Code example

Diagram

2. Table of Contents

4
4 1597
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.

3
0 1387
Question Jonathan Earnest · Jan 13, 2023

I'm trying to get started with IRIS for Health but every time I got to a step that asks me to install a .whl-package I cant continue. I'm getting an error that the file does not exist.

Here is the complete error message:

PS C:\Users\x\GIT\quickstarts-multimodel-python> pip install nativeAPI_wheel\irisnative-1.0.0-cp39-cp39m-win_amd64.whl    
WARNING: Requirement 'nativeAPI_wheel\\irisnative-1.0.0-cp39-cp39m-win_amd64.whl' looks like a filename, but the file does not exist
ERROR: irisnative-1.0.0-cp39-cp39m-win_amd64.whl is not a supported wheel on this platform.

Am I doing something wrong?

6
0 1197
Article Guillaume Rongier · Dec 6, 2022 3m read

OCR DEMO

This is a demo of the OCR functionality of the pero-ocr library.

It used in the iris application server in python.

Demo

This is an example of input data :

input

This is the result of the OCR :

In this example you have the following information:

  • The text is in the TextEquiv tag
  • The confidence is in the conf attribute of the TextEquiv tag
  • The coordinates of the text are in the Coords tag
<PcGts xmlns="http://schema.primaresearch.org/PAGE/gts/pagecontent/2019-07-15" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://schema.primaresearch.org/PAGE/gts/pagecontent/2019-07-15/pagecontent.xsd">
  <Metadata>
    <Creator>Pero OCR</Creator>
    <Created>2022-12-13T08:47:12.207893+00:00</Created>
    <LastChange>2022-12-13T08:47:12.207893+00:00</LastChange>
  </Metadata>
  <Page imageFilename="/irisdev/app/misc/in/United_States_Declaration_of_Independence.jpg" imageWidth="3923" imageHeight="4656">
    <TextRegion id="r004">
      <Coords points="977,121 932,121 932,283 1189,277 1178,114 977,121"/>
      <TextLine id="r004-l002" index="0" custom="heights_v2:[123.7,39.0]">
        <Coords points="932,121 932,283 1189,277 1178,114 1130,118 1100,117 1048,121 1019,121 977,121 932,121"/>
        <Baseline points="932,244 977,244 1019,244 1058,244 1100,241 1138,241 1186,238"/>
        <TextEquiv conf="1.000">
          <Unicode>IN</Unicode>
        </TextEquiv>
      </TextLine>
    </TextRegion>
    <TextRegion id="r008">
      <Coords points="1461,107 1241,107 1241,287 2116,290 2549,281 2986,287 3211,277 3203,98 2978,107 2552,101 2114,111 1461,107"/>
      <TextLine id="r008-l001" index="0" custom="heights_v2:[133.8,45.8]">
        <Coords points="1241,107 1241,287 1464,287 1681,284 1896,287 2116,290 2549,281 2986,287 3211,277 3203,98 2978,107 2552,101 2327,107 2114,111 1461,107 1241,107"/>
        <Baseline points="1241,241 1463,241 1682,238 1897,241 2116,244 2331,241 2550,235 2765,238 2984,241 3209,231"/>
        <TextEquiv conf="0.910">
          <Unicode>CONGRESS, JULY 4, 1776.</Unicode>
        </TextEquiv>
      </TextLine>
    </TextRegion>
    <TextRegion id="r001">
      <Coords points="591,452 208,455 209,611 1723,602 2100,608 2855,595 3617,598 3618,442 2855,439 2098,452 1725,446 591,452"/>
      <TextLine id="r001-l003" index="0" custom="heights_v2:[113.8,42.1]">
        <Coords points="208,455 209,611 592,608 968,605 1218,605 1723,602 2100,608 2855,595 3231,595 3617,598 3618,442 2855,439 2477,446 2098,452 1725,446 1346,449 1159,449 591,452 208,455"/>
        <Baseline points="209,569 592,566 968,563 1347,563 1723,559 2100,566 2479,559 2855,553 3231,553 3617,556"/>
        <TextEquiv conf="0.289">
          <Unicode>Dhe unaniwons Declaratton of te Heten maiss States of TNmerica</Unicode>
        </TextEquiv>
      </TextLine>
    </TextRegion>
    <TextRegion id="r000">
      <Coords points="161,3474 161,3539 423,3539 633,3536 958,3468 1354,3472 1764,3581 1944,3571 2246,3730 2653,3718 2718,3633 2855,3608 3238,3557 3514,3554 3739,3462 3762,3397 3761,3333 3735,3139 3743,2696 3730,2177 3735,1920 3723,1727 3736,1341 3717,1014 3724,943 3719,818 3697,693 1012,712 795,776 421,776 183,786 173,848 168,1032 173,2392 160,2713 161,3474"/>
      <TextLine id="r000-l004" index="0" custom="heights_v2:[40.2,18.4]">
        <Coords points="2796,699 2501,703 2205,706 1909,709 1611,709 1460,709 1012,712 1013,771 1315,768 1611,768 1910,768 2206,764 2502,761 2800,758 3096,758 3392,755 3698,752 3697,693 3392,696 3096,699 2802,699 2796,699"/>
        <Baseline points="1013,752 1315,749 1611,749 1910,749 2206,746 2501,743 2800,739 3096,739 3392,736 3697,733"/>
        <TextEquiv conf="0.281">
          <Unicode>hen n lí loune z human venl, i kemu nematy k mpeopě toíohohhehttcal bandí uhích have connechdí tem vith ancthet, andíl</Unicode>
        </TextEquiv>
      </TextLine>
      <TextLine id="r000-l005" index="1" custom="heights_v2:[40.4,19.2]">
        <Coords points="421,776 421,836 794,836 1157,839 1521,839 1884,836 2244,833 2608,829 2971,826 3335,823 3704,813 3703,754 3333,763 2970,767 2607,770 2244,773 1884,776 1520,779 1157,779 795,776 421,776"/>
        <Baseline points="421,817 794,817 1157,820 1521,820 1884,817 2244,813 2608,810 2971,807 3334,804 3704,794"/>
        <TextEquiv conf="0.211">
          <Unicode>o hi ſhwes f he eail, fie rehatal andequal flohon &amp; ufch lhe laav  . kalut and   Aloil ped entilt ttem, a dant rafech to the ofunin o manknd tequies fhat thep</Unicode>
        </TextEquiv>
      </TextLine>
     <!-- Truncated for readme-->
      <TextLine id="r019-l105" index="9" custom="heights_v2:[47.5,21.7]">
        <Coords points="3209,4269 3214,4336 3257,4333 3296,4333 3332,4333 3373,4337 3411,4337 3452,4336 3488,4333 3527,4333 3575,4333 3575,4264 3527,4264 3488,4264 3446,4267 3411,4267 3373,4267 3338,4264 3296,4264 3257,4264 3209,4267 3209,4269"/>
        <Baseline points="3212,4315 3257,4312 3296,4312 3334,4312 3373,4315 3411,4315 3450,4315 3488,4312 3527,4312 3575,4312"/>
        <TextEquiv conf="0.283">
          <Unicode>imuiaa</Unicode>
        </TextEquiv>
      </TextLine>
      <TextLine id="r019-l108" index="10" custom="heights_v2:[40.9,20.2]">
        <Coords points="3198,4406 3251,4409 3294,4409 3339,4412 3394,4415 3398,4354 3343,4351 3298,4348 3251,4348 3202,4345 3198,4406"/>
        <Baseline points="3199,4386 3251,4389 3296,4389 3341,4392 3395,4395"/>
        <TextEquiv conf="0.370">
          <Unicode>Qlver</Unicode>
        </TextEquiv>
      </TextLine>
      <TextLine id="r019-l114" index="11" custom="heights_v2:[39.2,19.1]">
        <Coords points="3181,4469 3225,4466 3263,4466 3305,4466 3327,4466 3352,4465 3386,4462 3424,4462 3472,4462 3472,4404 3424,4404 3386,4404 3341,4407 3305,4407 3263,4407 3225,4407 3177,4411 3181,4469"/>
        <Baseline points="3180,4450 3225,4447 3263,4447 3305,4447 3344,4447 3386,4443 3424,4443 3472,4443"/>
        <TextEquiv conf="0.312">
          <Unicode>Vbalřew/</Unicode>
        </TextEquiv>
      </TextLine>
    </TextRegion>
    <TextRegion id="r020">
      <Coords points="3685,4399 3607,4399 3607,4465 3685,4465 3685,4399"/>
      <TextLine id="r020-l112" index="0" custom="heights_v2:[44.3,21.4]">
        <Coords points="3607,4399 3607,4465 3685,4465 3685,4399 3607,4399"/>
        <Baseline points="3607,4443 3685,4443"/>
        <TextEquiv conf="0.486">
          <Unicode>17.</Unicode>
        </TextEquiv>
      </TextLine>
    </TextRegion>
  </Page>
</PcGts>
6
2 601
Question Dmitry Maslennikov · Nov 13, 2022

I have table

CREATE TABLE nodes (
        name VARCHAR(50) NOT NULL, 
        parent VARCHAR(50), 
        PRIMARY KEY (name), 
        FOREIGN KEY(parent) REFERENCES nodes (name) ON UPDATE cascade
);

I put some data

INSERT INTO nodes (name, parent) VALUES ('n1', NULL);
INSERT INTO nodes (name, parent) VALUES ('n11', 'n1');
INSERT INTO nodes (name, parent) VALUES ('n12', 'n1');
INSERT INTO nodes (name, parent) VALUES ('n13', 'n1');

Let's delete all

DELETE FROM nodes;

Nope, no way.

SQL Error [124] [S1000]: [SQLCODE: <-124>:<FOREIGN KEY constraint failed referential check upon DELETE of row in referenced table>]
[Location: <ServerLoop>]
[%msg: <At least 1 Row exists in table 'SQLUser.nodes' which references key 'NODESPKey2' - Foreign Key Constraint 'NODESFKey3', Field(s) 'parent' failed on referential action of NO ACTION>]
7
0 693