oracledb python module as cx_Oracle replacement

oracledb

oracledb python module as cx_Oracle replacement

  • python-oracledb is the new python module for connecting with Oracle database in place of cx_Oracle. The new module is more efficient with better intellisense suggestions and descriptive error messages.
  • Database connectivity can be established directly from python without installing oracle client libraries. This is called thin mode. This makes installing the module very easy.
  • Advanced functionality can be enabled by using oracle client libraries. This is called thick mode.
  • python-oracledb can be used as it is like cx_Oracle. In fact, the following can be used in legacy code
import oracledb as cx_Oracle
# ...

Installing python-oracledb

  • Install the python-oracledb module using the following command
python -m pip install oracledb

Connecting to Oracle

  • Connect to oracle using username, password, host IP or hostname, port, service name as shown below
import oracledb
conn = oracledb.connect(user="hr", password="pwd",
                              host="localhost", port=1521, service_name="xepdb1")

References

Comments