Skip to content
pvmehta.com

pvmehta.com

  • Home
  • About Me
  • Toggle search form
  • Settting up get_vmstat.sh for colletinf CPU Usage. Oracle
  • Benefits and Usage of RMAN with Standby Databases Oracle
  • create trigger syntax Oracle
  • Windows based Command line mailing program like mailx (Sednmail for windows) PHP/MYSQL/Wordpress
  • executing Function from SQLPLUS prompt Oracle
  • Find Command Linux/Unix
  • Oracle Identifiers Oracle
  • upload.html PHP/MYSQL/Wordpress
  • plan10g.sql good Oracle
  • before_trunc.sql Before Truncate table needs to execute following: Oracle
  • backspace in SQL Plus not working then..? Linux/Unix
  • crontab syntax Linux/Unix
  • create a folder in multiple places Linux/Unix
  • Rename Tablespace Oracle
  • Virtual Indexes in Oracle Oracle

How to connect to Oracle Database with Wallet with Python.

Posted on 21-Mar-2025 By Admin No Comments on How to connect to Oracle Database with Wallet with Python.

To connect Python to Oracle Database using an Oracle Wallet, you can use the cx_Oracle or oracledb library with Oracle Client libraries (like Oracle Instant Client). Oracle Wallet simplifies secure connections by storing credentials and SSL certificates.


βœ… Steps to Connect Python to Oracle using Oracle Wallet


Step 1: Install Required Python Package

pip install oracledb
  • Prefer oracledb (official Oracle-supported replacement for cx_Oracle).
  • Compatible with Oracle Wallet and works in both thin and thick modes.

Step 2: Install Oracle Instant Client

  • Download from Oracle Instant Client Downloads
  • Extract it to a known location (e.g., C:\oracle\instantclient_19_11 or /opt/oracle/instantclient_19_11)
  • Add the path to your system environment:

Linux/macOS:

export LD_LIBRARY_PATH=/path/to/instantclient:$LD_LIBRARY_PATH

Windows (Command Prompt):

set PATH=C:\oracle\instantclient_19_11;%PATH%

Step 3: Create or Use an Oracle Wallet

  • Oracle Wallet typically resides under:
    network/admin folder inside the Oracle Client path.
  • Your folder should contain:
    • sqlnet.ora
    • tnsnames.ora
    • cwallet.sso

Example sqlnet.ora:

WALLET_LOCATION = (SOURCE = (METHOD = FILE) (METHOD_DATA = (DIRECTORY = /path/to/wallet)))
SQLNET.WALLET_OVERRIDE = TRUE
SSL_SERVER_DN_MATCH = yes

Example tnsnames.ora:

MYDB_ALIAS =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCPS)(HOST = your_host)(PORT = 2484))
    (CONNECT_DATA = (SERVICE_NAME = your_service))
    (SECURITY = (SSL_SERVER_CERT_DN = "CN=your_cert"))
  )

Step 4: Python Code to Connect

import oracledb

# Optional: Switch to thick mode to use Oracle Wallet
oracledb.init_oracle_client(lib_dir="/path/to/instantclient")

# Use tns alias defined in tnsnames.ora
conn = oracledb.connect(dsn="MYDB_ALIAS")

# Use the connection
cursor = conn.cursor()
cursor.execute("SELECT * FROM dual")
for row in cursor:
    print(row)

cursor.close()
conn.close()

βœ… If the wallet contains credentials, you don’t need to provide user and password.


πŸ§ͺ Quick Checklist

ItemRequiredExample
Oracle Instant Clientβœ…instantclient_19_11
Oracle Wallet filesβœ…cwallet.sso, sqlnet.ora, etc.
tnsnames.ora entryβœ…MYDB_ALIAS = ...
Python library (oracledb)βœ…pip install oracledb
init_oracle_client()βœ…For thick mode

Would you like help writing a sample sqlnet.ora and tnsnames.ora for your setup? Or are you facing a specific error?

Oracle, Python/PySpark

Post navigation

Previous Post: JSON/XML Types in Oracle
Next Post: SQL Tracker by SID sqltrackerbysid.sql

Related Posts

  • Good Doc 28-JUN-2006 Oracle
  • compile_inv.sql Oracle
  • Jai Shree Ram Oracle
  • mutex in Oracle 10.2.0.2 or Oracle 10g Oracle
  • oradebug ipcrm ipcs Oracle
  • DBMS_UTILITY.ANALYZE_SCHEMA Oracle

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Categories

  • AWS (2)
  • Azure (1)
  • Linux/Unix (149)
  • Oracle (392)
  • PHP/MYSQL/Wordpress (10)
  • Power-BI (0)
  • Python/PySpark (7)
  • RAC (17)
  • rman-dataguard (26)
  • shell (149)
  • SQL scripts (341)
  • Uncategorized (0)
  • Videos (0)

Recent Posts

  • load SPM baseline from cursor cache05-Jun-2025
  • Drop all SPM baselines for SQL handle05-Jun-2025
  • Load SPM baseline from AWR05-Jun-2025
  • Drop specific SQL plan baseline – spm05-Jun-2025
  • findinfo.sql (SQL for getting CPU and Active session info)27-May-2025
  • SQL Tracker by SID sqltrackerbysid.sql22-Apr-2025
  • How to connect to Oracle Database with Wallet with Python.21-Mar-2025
  • JSON/XML Types in Oracle18-Mar-2025
  • CPU Core related projections12-Mar-2025
  • Exadata Basics10-Dec-2024

Archives

  • 2025
  • 2024
  • 2023
  • 2010
  • 2009
  • 2008
  • 2007
  • 2006
  • 2005
  • How to sort list of files on basis of their sizes. Linux/Unix
  • find_err.sql for finding errors from dba_errors. Oracle
  • move_arch_files.ksh Linux/Unix
  • My Test Case On 21-OCT-2005 Oracle
  • findx.sql /* Find Indexes on specified USER.TABLE_NAME */ Oracle
  • DBMS_UTILITY.ANALYZE_SCHEMA Oracle
  • DBMS_JOB all example Oracle
  • get_vmstat.ksh for Solaris Oracle

Copyright © 2025 pvmehta.com.

Powered by PressBook News WordPress theme