Set Up Python

You need to install the python-oracledb driver to successfully configure a connection to a TimesTen database in Python.

Task 1: Install the python-oracledb Driver

There are several approaches for installing the python-oracledb driver. Choose the approach that is most suitable for your setup and environment.

Information for all scenarios is available at Installing python-oracledb.

Task 2: Initialize the python-oracledb Driver

By default, the python-oracledb driver runs in Thin mode which connects directly to Oracle Database. However, to connect to a TimesTen database, the driver needs to be in Thick mode so it uses the Oracle Instant Client library included with TimesTen.

To enable Thick mode for the python-oracledb driver, call the oracledb.init_oracle_client() function in your application before creating any connection. See Enabling python-oracledb Thick mode.

This calls the oracledb.init_oracle_client() function without a lib_dir parameter to ensure it uses the PATH environment variable set by ttenv script. See Task 2: Set the TimesTen Environment.

import oracledb
oracledb.init_oracle_client()

Task 3: Configure Connections to TimesTen in Python

You can use a TNS name or an Easy Connect mechanism to connect to your database. See Task 4: Configure Connections for TimesTen.

This example uses a TNS name for a Python connection string:

connection = oracledb.connect(user="appuser", password="password", dsn="sampledbconn")

This example uses an Easy Connect string that specifies a direct connection to TimesTen:

connection = oracledb.connect(user="appuser", password="password", dsn="myhost/sampledb:timesten_direct")