Skip to content
pvmehta.com

pvmehta.com

  • Home
  • About Me
  • Toggle search form
  • More info about /proc folder and its relation with processes. Linux/Unix
  • Oracle 10g Wait Model Oracle
  • RAC with RHEL4 and 11g Oracle
  • OEM-troubleshooting on 20-MAY-08 Oracle
  • get_vmstat_linux Oracle
  • TRUNCATE table and disabling referential constraints. Oracle
  • The most important Tuning Notes Oracle
  • Database logon trigger issue Oracle
  • Directory wise folder wise space usage Linux/Unix
  • PLSQL Table Syntax 1 Oracle
  • How To Limit The Access To The Database So That Only One User Per Schema Are Connected (One Concurrent User Per Schema) Oracle
  • PLSQL Table Syntax 2 Oracle
  • S3 Basic info AWS
  • Removing Ctrl-M from end of line using vi Linux/Unix
  • Oracle Standby Database Library Index from Metalink 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

  • fkwoind.sql fkwoindex.sql Oracle
  • Roles and Stored Procs II Oracle
  • tab.sql Oracle
  • Resolving RMAN Hung Jobs Oracle
  • New OFA for 11g Oracle
  • find_string_in_database.sql 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
  • Specify the Rollback segment to use in Transaction Oracle
  • ORA-1841 Error Connecting to Upgraded Database After Set PASSWORD_LIFE_TIME Oracle
  • Very clear article about oracle dataguard Oracle
  • 272332.1 CRS 10g Diagnostic Collection Guide Oracle
  • Adding addidional hard drive and attach it to a linux box. Linux/Unix
  • Export Import with QUERY Oracle
  • ENQ: KO – FAST OBJECT CHECKPOINT tips Oracle
  • Btee and Bitmap Plans in Oracle 9i and higher Oracle

Copyright © 2025 pvmehta.com.

Powered by PressBook News WordPress theme