I am trying to build an application in python which will use Oracle Database installed in corporate server and the application which I am developing can be used in any local machine.
Is it possible to connect to oracle DB in Python without installing the oracle client in the local machine where the python application will be stored and executed?
Like in Java, we can use the jdbc thin driver to acheive the same, how it can be achieved in Python.
Any help is appreciated
Installing oracle client, connect is possible through cx_Oracle module. But in systems where the client is not installed, how can we connect to the DB.
The python-oracledb driver (that superseded cx_Oracle) does not need Oracle Client libraries. It only takes a few megabytes. Installation is simple:
python -m pip install oracledb
It supports the Python DB API so usage is the same as cx_Oracle, e.g.:
import getpass
import oracledb
un = 'cj'
cs = 'localhost/orclpdb1'
pw = getpass.getpass(f'Enter password for {un}@{cs}: ')
with oracledb.connect(user=un, password=pw, dsn=cs) as connection:
with connection.cursor() as cursor:
sql = """select systimestamp from dual"""
for (r,) in cursor.execute(sql):
print(r)
See the python-oracledb documentation and samples.
Also see the python-oracledb release announcement.
The cx_Oracle driver is obsolete and should not be used for any projects.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With