Configure the Python SDK for OCI and run the example

This example is using user opc on a OCI OCI VM.  

First configure the OCI CLI.  See my post here

$ python3 -mvenv pythonocienv

$ source pythonocienv/bin/activate

(pythonocienv) [opc@myhost ~]$ pip install oci

Collecting oci

  Downloading (5.2MB)

    100% |████████████████████████████████| 5.2MB 210kB/s 

Collecting certifi (from oci)

  Downloading (156kB)

    100% |████████████████████████████████| 163kB 5.4MB/s 

Collecting cryptography==2.8 (from oci)

  Downloading (2.3MB)

    100% |████████████████████████████████| 2.3MB 460kB/s 

Collecting pyOpenSSL<=19.1.0,>=17.5.0 (from oci)

  Downloading (53kB)

    100% |████████████████████████████████| 61kB 8.3MB/s 

Collecting pytz>=2016.10 (from oci)

  Downloading (510kB)

    100% |████████████████████████████████| 512kB 2.2MB/s 

Collecting python-dateutil<3.0.0,>=2.5.3 (from oci)

  Downloading (227kB)

    100% |████████████████████████████████| 235kB 3.6MB/s 

Collecting configparser==4.0.2 (from oci)


Collecting cffi!=1.11.3,>=1.8 (from cryptography==2.8->oci)

  Downloading (400kB)

    100% |████████████████████████████████| 409kB 2.4MB/s 

Collecting six>=1.4.1 (from cryptography==2.8->oci)


Collecting pycparser (from cffi!=1.11.3,>=1.8->cryptography==2.8->oci)

  Downloading (112kB)

    100% |████████████████████████████████| 112kB 7.2MB/s 

Installing collected packages: certifi, pycparser, cffi, six, cryptography, pyOpenSSL, pytz, python-dateutil, configparser, oci

Successfully installed certifi-2020.6.20 cffi-1.14.2 configparser-4.0.2 cryptography-2.8 oci-2.21.2 pyOpenSSL-19.1.0 pycparser-2.20 python-dateutil-2.8.1 pytz-2020.1 six-1.15.0

You are using pip version 9.0.3, however version 20.2.2 is available.

You should consider upgrading via the ‘pip install –upgrade pip’ command.

(pythonocienv) [opc@api2 ~]$ 

(pythonocienv) [opc@api2 ~]$ pip install –upgrade pip

Collecting pip

  Using cached

Installing collected packages: pip

  Found existing installation: pip 9.0.3

    Uninstalling pip-9.0.3:

      Successfully uninstalled pip-9.0.3

Successfully installed pip-20.2.2

Install Git to Pull Down the Python SDK 

As root – 

#yum install git

Clone the OCI-Python-SDK (with the samples)

(keep in mind that the directory this is installed in will be your default when you run the command.  It does not need to be under the python virtual directory.  I put mine at the root of my working directory)

(pythonocienv) [opc@myhost ~]$ git clone

Cloning into ‘oci-python-sdk’…

remote: Enumerating objects: 299, done.

remote: Counting objects: 100% (299/299), done.

remote: Compressing objects: 100% (205/205), done.

remote: Total 18883 (delta 156), reused 150 (delta 88), pack-reused 18584

Receiving objects: 100% (18883/18883), 14.79 MiB | 22.81 MiB/s, done.

Resolving deltas: 100% (16182/16182), done.

Configure the SDK Documentation for Reference – 

Now Run the showoci example

$ cd /home/opc/oci-python-sdk/examples/showoci

To see command line information 

$ python

Parameter -ip indicates use of instance principal.

-so summary only

-a all

  -c compute

$python  -so -a -ip

$python  -lq -c -ip

Examine the output of the above.  I have not included it here as it includes a lot of specific tenancy information.

Each time you use the SDK, you should source the python virtual environment as well as set your environment.  

I added to my .bashrc for that.

export export OCI_CLI_AUTH=instance_principal

. /home/opc/pythonocienv/bin/activate

Leave a Reply

Your email address will not be published. Required fields are marked *

I accept that my given data and my IP address is sent to a server in the USA only for the purpose of spam prevention through the Akismet program.More information on Akismet and GDPR.