Skip to content
pvmehta.com

pvmehta.com

  • Home
  • About Me
  • Toggle search form
  • Proc Compilation Oracle
  • Roles and Stored Procs II Oracle
  • Pending Transaction Neighbors Script Oracle
  • v$backup.status information Oracle
  • Removing Blank lines from file using grep Linux/Unix
  • Oracle Data Direct to TAPE Oracle
  • Check Oracle installed products using one command Oracle
  • Follwoing korn shell is used to move files from source folder to destination folder and gzip it in destination folder. mv_iotto.ksh Linux/Unix
  • find_idle_cpu.sql Oracle
  • tar and untar a dolder with all its subfolder. Linux/Unix
  • SQL_PROFILE – I explaination Oracle
  • Kernel Parameters for Solaris Linux/Unix
  • on IBM-AIX for display Linux/Unix
  • Unix split command to split files Linux/Unix
  • First Entry in RAC 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

  • Gathering statistics with DBMS_STATS Oracle
  • longtx.sql Oracle
  • ORA-01220 Oracle
  • Exadata Basics Oracle
  • Oracle 11g Environment Setup Oracle
  • Load testing on Oracle 19C RAC with HammerDB 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
  • longtx.sql with the flag whether session is blocking any DML locks or not. Oracle
  • AWR license Oracle
  • Oracle Recommended Patches — Oracle Database ID 756671.1 Oracle
  • SYSOPER Mystery Oracle
  • Configure ssh authentications for RAC Oracle
  • Find_stale_dr.sql finding stale physical DR.. Oracle
  • DBMS_JOB all example Oracle
  • ipcs -l Linux/Unix

Copyright © 2025 pvmehta.com.

Powered by PressBook News WordPress theme