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 forcx_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_11or/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/adminfolder 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
userandpassword.
π§ͺ Quick Checklist
| Item | Required | Example | 
|---|---|---|
| Oracle Instant Client | β | instantclient_19_11 | 
| Oracle Wallet files | β | cwallet.sso,sqlnet.ora, etc. | 
| tnsnames.oraentry | β | 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?
