Not sure if this step is needed since Oracle Instant Client suppose to be back compatible, but I went ahead and installed client that matched Oracle instance that I was trying to connect to Determine Oracle version by running this command. Mine was 12.1.0.2.0

SELECT * FROM V$VERSION
  • Download Oracle Instant Client. I have Linux 86-64 so I used this link to download RPM version.

  • Install downloaded oracle instant client

sudo yum install oracle-instantclient12.1-basic-12.1.0.2.0-1.x86_64.rpm
  • Add oracle instant client to your PATH. Permanently since I don't have any other Oracle products that might have broken.:
sudo sh -c "echo /usr/lib/oracle/12.1/client64/lib > /etc/ld.so.conf.d/oracle-instantclient.conf"
sudo ldconfig
  • At this point your environment is set. Now it is time to connect to it by installing cx_Oracle library in your python.
python -m pip install cx_Oracle --upgrade
  • That should do it. Now write a simple python script to get the version of the Oracle database that you are trying to connect to.
import cx_Oracle
ip = 'specify_ip_or_hostname'
port = 1234
SID = 'specify_sid_or_schema'
dsn_tns = cx_Oracle.makedsn(ip, port, SID)

# You might get these via environment variable to make thing secure
username = 'username'
password = 'password'

conn = cx_Oracle.connect(username, password, dsn_tns)

print(conn.version)
conn.close()
>>> 12.1.0.2.0

References:
Installing cx_Oracle on Linux
Quick cx_Oracle Install