Skip to content
pvmehta.com

pvmehta.com

  • Home
  • About Me
  • Toggle search form
  • Running PDB on single node in RAC Oracle
  • My Test Case On 21-OCT-2005 Oracle
  • USER_TABLES.Freelists Oracle
  • Goldengate document from Porus Oracle
  • TOP-N Sql to find Nth max or Top N rows Oracle
  • Adding Datafile on Primary Server and Impact on Standby Server Oracle
  • Another export with Query Oracle
  • login.sql Oracle
  • CTAS with LONG Column for 9i and higher Oracle
  • Changing the Global Database Name Oracle
  • DBMS_JOB all example Oracle
  • VIvek Encryption Package and Its Usage Oracle
  • How to remove blank lines using vi editor command Linux/Unix
  • UTL_FILE test program Oracle
  • grep multuple patterns Linux/Unix

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

  • Running PDB on single node in RAC Oracle
  • proc.sql Oracle
  • DBMS_SQL for alter session. Oracle
  • ENQ: KO – FAST OBJECT CHECKPOINT tips Oracle
  • Goog notes on X$ tables Oracle
  • The most important Tuning Notes 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
  • scp with ssh2 Linux/Unix
  • temp_use.sql diplays usage of temp ts Oracle
  • TRUNCATE Privs Oracle
  • Multiple listeners Oracle
  • secure crt settings Linux/Unix
  • find_pdbs.sql Uncategorized
  • MYSQL and Oracle Comparison for Oracle DBA MYSQL
  • Removing first line Linux/Unix

Copyright © 2026 pvmehta.com.

Powered by PressBook News WordPress theme