Skip to content
pvmehta.com

pvmehta.com

  • Home
  • About Me
  • Toggle search form
  • Running some SQL on multiple databases connecting using monitoring userid and password Linux/Unix
  • nfs mount command Linux/Unix
  • move_arch_files.ksh Linux/Unix
  • Gather Stats manually using DBMS_STATS after disabling DBMS_SCHEDULER jobs as previous entry Oracle
  • chk_space_SID.ksh Linux/Unix
  • lck.sql Oracle
  • sess1.sql Oracle
  • OPENING A STANDBY DATABASE IN READ-ONLY MODE Oracle
  • How to find the real execution plan and binds used in that explain plan in Oracle 10g?? Oracle
  • Find execution plan from dba_hist_sql_plan for a specific SQL_ID and PLAN_HASH_VALUE fplan.sql Oracle
  • MYSQL for Oracle DBA MYSQL
  • checking connectivity between two servers Linux/Unix
  • CTAS with LONG Column for 9i and higher Oracle
  • To check whether standby is recovering properly or not?? Oracle
  • Jai Shree Ram 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

  • sid_wise_sql.sql Oracle
  • find_string_in_database.sql Oracle
  • Changing the Global Database Name Oracle
  • Jai Shree Ram Oracle
  • switchover for primary database Oracle
  • Oracle 11g Environment Setup Oracle

Leave a Reply Cancel reply

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

Categories

  • Ansible (0)
  • AWS (2)
  • Azure (1)
  • Django (0)
  • GIT (1)
  • Linux/Unix (149)
  • MYSQL (5)
  • Oracle (400)
  • PHP/MYSQL/Wordpress (10)
  • POSTGRESQL (1)
  • Power-BI (0)
  • Python/PySpark (7)
  • RAC (18)
  • rman-dataguard (26)
  • shell (150)
  • SQL scripts (348)
  • SQL Server (6)
  • Uncategorized (3)
  • Videos (0)

Recent Posts

  • Running PDB on single node in RAC09-Apr-2026
  • find_arc.sql09-Apr-2026
  • pvm_pre_change.sql08-Apr-2026
  • find_encr_wallet.sql08-Apr-2026
  • find_pdbs.sql08-Apr-2026
  • Creating a Container Database using dbaascli08-Apr-2026
  • track_autoupgrade_copy_progress.sql01-Apr-2026
  • refre.sql for multitenant01-Apr-2026
  • prepfiles.sh for step by step generating pending statistics files10-Mar-2026
  • tracksqltime.sql05-Mar-2026

Archives

  • 2026
  • 2025
  • 2024
  • 2023
  • 2010
  • 2009
  • 2008
  • 2007
  • 2006
  • 2005
  • DBMS_Shared_pool pinning triggers Oracle
  • Insert cause enqueue locks Oracle
  • get_aix_vmstat.ksh Oracle
  • Gathering statistics with DBMS_STATS Oracle
  • SQL_PROFILE – I explaination Oracle
  • get_ratio.sql get the ratio of users from v$session and this uses CASE-WHEN-THEN clause Oracle
  • GSQ.sql Oracle
  • Recovering lost SYS password Oracle

Copyright © 2026 pvmehta.com.

Powered by PressBook News WordPress theme