Jasenko Donlagic · Jul 16, 2018

Connect to IRIS with Python?

I have seen the Cache Python binding documentation and would like to know if it's also possible with IRIS so I can write data and also read/get it from the DB? The cachesys folder does not contain any python libraries.

0 660
Discussion (7)2
Log in or sign up to continue

Components Installed by Setup Type: IRIS, Caché

Unfortunately, Perl/Python Binding supported only on the x86-32 bit platform, but IRIS is only supported for x86-64.

Thanks, I will look into this, for now I'm getting the desired results with REST and CURL.

You can definitely compile and install cache-python binding module on x86-64 machines. I have done this on Ubuntu and it produced (pythonbind3-1.0-py3.6-linux-x86_64.egg). I am not sure I understand why it cannot be installed on IRIS x86-64bit platform. If you install python binding on IRIS I will be also interested in testing my CacheORM object-relational mapper.

Here is a quick example program I wrote a couple of months ago.  This uses JDBC and the JayDeBeapi library others have mentioned.  Note the Credentials import provides a set of  login credentials in the following format.

LocalCreds = {"user":"SuperUser", "password":"SYS"}

Here is the code:

import jaydebeapi
import credentials
def get_database_connection(inpDBInstance):
    IRIS_JARFILE = "/home/ritaylor/InterSystemsJDBC/intersystems-jdbc-3.2.0.jar"
    IRIS_DRIVER = "com.intersystems.jdbc.IRISDriver"
    AA_JARFILE = "/home/ritaylor/Downloads/AtScale/hive-jdbc-uber-"
    AA_DRIVER = "org.apache.hive.jdbc.HiveDriver"
    # note connecting to two data sources in the same program requires that you 
    # reference the paths to BOTH jar files in a list in every call. Otherwise the
    # second connection attempt will fail.  It appears that the paths only get
    # added once within a process.
    # Database settings - this should be in a config file somewhere
    if (inpDBInstance == "local"):
        dbConn = jaydebeapi.connect(IRIS_DRIVER,
         dbConn = None
    return dbConn
def run_database_query(inpQuery, inpDBInstance):
    resultSet = None
    dbConn = get_database_connection(inpDBInstance)
    cursor = dbConn.cursor()
    resultSet = cursor.fetchall()
    return resultSet
def print_db_result_set(resultSet):
    if (resultSet != None):
        for row in resultSet:
        print("Input result set is empty")