How to use python connect cache2016 database?
I need connect to cache2016 database by python to get some data, but I don' t know how to connect by python, did anyone know how to create connection?
If you can provide any python code, that will be better!
Comments
well, I tryed python buinding, but the intersys.pythonbind package did not find the connection method, my python version is Anaconda (python 3.9.13 and conda 22.9.0) .If you have some reference document or website that will be fine.
.jpg)
Hi @CJ Q
Any update about this?
Thanks
You can try these packages, it may not work, as it was tested for latest IRIS
- https://pypi.org/project/sqlalchemy-iris/
- https://pypi.org/project/django-iris/
- https://pypi.org/project/intersystems-iris/ - is DB-API driver used by both above, can be used separately
Use the tried and tested mg_python:
Any ODBC connection may do it for data and procedures.
Hi!
I grabbed some pieces of code from a previous project. In this project I could connect to Cache 2018.
PS: I didn't test this mashup.
import irisnative
import jaydebeapi
import pandas as pd
defcreate_conn(type, host, port, namespace, user, password):if type == "cache":
url = f"jdbc:Cache://{host}:{port}/{namespace}"
driver = "com.intersys.jdbc.CacheDriver"
jarfile = "C:/InterSystems/Cache2018/dev/java/lib/JDK18/cache-jdbc-2.0.0.jar"
conn = jaydebeapi.connect(driver, url, [user, password], jarfile)
else:
conn = irisnative.createConnection(host, port, namespace, user, password, sharedmemory = True)
return conn
conn = create_conn("cache", "x.x.x.x", "56772", "namespace", "user", "password")
sql = "select ..."
df = pd.read_sql(sql, conn)
display(df)HTH,
José
I found the best approach was with pythonbind:
import intersys.pythonbind3 as pyb
url = "localhost"
userName= "???"
password="???"
port=1972
def main():
conn = pyb.connection()
version = conn.get_implementation_version()
conn.connect_now(f'[{url}][{port}]:%SYS', userName, password,None)
# Create objects used to access cache/iris
db = pyb.database(conn)
qry = pyb.query (db)
obj = pyb.object(db)
......
With the connection handle and the db, qry, obj objects you can use the methods and classes to access any database item in the cache database