Connect Python Applications Without a Wallet (TLS)

You can connect Python applications to your Autonomous Database instance without a wallet. Connecting a Python application without a wallet (TLS) provides security for authentication and encryption, and security is enforced using client credentials (by providing a username and password).

The python-oracledb driver's default "Thin mode" connects directly to Oracle Database. It can optionally use Oracle Client libraries, "Thick mode", for some additional functionality. The Oracle Client libraries can be from Oracle Instant Client, the full Oracle Client, or an Oracle Database installation.

Follow these steps to connect your Python application to an Autonomous Database instance without a wallet (TLS):

  1. Install Python and the python-oracledb Driver

  2. Enable TLS on Autonomous Database and Obtain Connection String

  3. Run Python Application Without a Wallet

See Enabling python-oracledb Thick mode for information on Thick mode.

Topics

Enable TLS on Autonomous Database and Obtain Connection String

To run a Python application without a wallet, enable the Autonomous Database instance for TLS connections and obtain a connection string to contact the database from the Python application.
  1. Determine if your Autonomous Database instance is enabled for TLS connections.

    If the instance is enabled for TLS connections, in the Network area on the Oracle Cloud Infrastructure Console the Mutual TLS (mTLS) authentication field shows: Not Required:

    Description of adb_mutual_tls_not_required.png follows
    Description of the illustration adb_mutual_tls_not_required.png

    If your instance requires Mutual TLS authentication, allow TLS connections on your Autonomous Database instance. See Update your Autonomous Database Instance to Allow both TLS and mTLS Authentication for details.

  2. Obtain an Autonomous Database service connection string to access the database as follows:
    1. On the Oracle Cloud Infrastructure Console, click Database connection.
    2. Select TLS in the Database Connection dialog box, under Connection Strings, in the TLS Authentication drop-down list.

      Note:

      You must select TLS in the TLS Authentication drop-down to obtain the TLS connection strings before you copy a connection string (when the value is Mutual TLS the connection strings have different values and do not work with TLS connections).
    3. Copy the Connection String for the database service you want to use with your application.

Run Python Application Without a Wallet

A Python application can connect to your Autonomous Database instance without a wallet (TLS) using the database credentials and a connect descriptor.

  1. Obtain the connection string, as described in Enable TLS on Autonomous Database and Obtain Connection String.
  2. In your Python application, set the following connection parameters to connect to an Autonomous Database instance:
    • dsn: Use the connection string to specify the desired database service name.
    • password: Specifies the database user password.
    • user: Specifies the database user.

    For example:

    cs='''(description = (retry_count=20)(retry_delay=3)(address=(protocol=tcps)
         (port=1522)(host=xxx.oraclecloud.com))
         (connect_data=(service_name=xxx.adb.oraclecloud.com))
         (security=(ssl_server_dn_match=yes)))'''
    
    connection=oracledb.connect(
         user="admin",
         password=password,
         dsn=cs)
  3. If you want to connect in Thick mode, include oracledb.init_oracle_client() in your Python application.

    For example:

    cs='''(description = (retry_count=20)(retry_delay=3)(address=(protocol=tcps)
         (port=1522)(host=xxx.oraclecloud.com))
         (connect_data=(service_name=xxx.adb.oraclecloud.com))
         (security=(ssl_server_dn_match=yes)))'''
    
    oracledb.init_oracle_client()
    connection=oracledb.connect(
         user="admin",
         password=password,
         dsn=cs)