News, tips, partners, and perspectives for the Oracle Linux operating system and upstream Linux kernel work

Installing Python SDK and CLI for Oracle Cloud Infrastructure on Oracle Linux: a Tutorial

There are several ways to install the Python SDK and CLI for Oracle Cloud Infrastructure (OCI). In this blog post I describe two ways to do so on Oracle Linux 7:


  • using Oracle Linux system Python 2.7 —included in the OS— and the python-oci-sdk and python-oci-cli RPMs
  • Using Python 3.6 from the Oracle Linux EPEL repository and pip

Configuring Required Keys and OCIDs

For the OCI SDK and CLI to work, basic configuration and authentication information is required. For example, Oracle Cloud IDs (OCID) for user and tenancy. This is covered in the OCI Documentation: SDK and Tool Configuration and Required Keys and OCIDs. To set up public and private API keys for the OCI SDK and CLI:


mkdir ~/.oci
openssl genrsa -out ~/.oci/oci_api_key.pem 2048
chmod go-rwx ~/.oci/oci_api_key.pem
openssl rsa -pubout -in ~/.oci/oci_api_key.pem -out ~/.oci/oci_api_key_public.pem
# add this public key to your profile under User Settings > API Keys
cat ~/.oci/oci_api_key_public.pem
-----END PUBLIC KEY-----

Copy the Public Key output and upload it by Signing in to the Console and pasting it under User Settings > API Keys. See Figure 1.

Figure 1. Adding Public Key to User Settings in OCI Console

Create a file ~/.oci/config that contains your user OCID, your tenancy OCID, the fingerprint for your Public Key and your region. The tenancy OCID can be found bottom left in the footer of the Console (see Documentation: Where to Find Your Tenancy's OCID) For example:

$ cat ~/.oci/config

Set the permissions for the ~/.oci/config file to limit access:

chmod go-rwx ~/.oci/config

Oracle Linux System Python 2.7: Install Using RPM from Oracle Linux Yum Server

The Oracle Linux team packages the OCI CLI and SDK in RPM form and publishes them in the Developer repository on Oracle Linux yum server. To install these for (system) Python 2.7:

sudo yum -y install yum-utils
sudo yum-config-manager --enable ol7_developer ol7_developer_epel
sudo yum -y install python-oci-sdk python-oci-cli

Python 3.6 from EPEL: Install Using pip

Oracle Linux yum server has an EPEL repository that includes Python 3.6. You can read more about Python for Oracle Linux here.

	sudo yum -y install yum-utils
	sudo yum-config-manager --enable ol7_developer_epel
	sudo yum install -y python36
	python3.6 -m venv py36env
	source py36env/bin/activate
	python -m pip install oci oci-cli

Testing the OCI CLI

To test the CLI, you'll need the Compartment OCID. You can find this via the Console main "hamburger" menu Identity > Compartments. See figure 2.

Figure 2. Finding your Compartment OCID

A quick test of the CLI by obtaining a list of available images in the Compute service:

oci compute image list --compartment-id=ocid1.compartment.oc1..aaaa..xxx
      "base-image-id": null, 
      "compartment-id": null, 
      "create-image-allowed": true, 
      "defined-tags": {}, 
      "display-name": "Oracle-Linux-7.5-Gen2-GPU-2018.05.09-1", 
      "freeform-tags": {}, 
      "id": "ocid1.image.oc1.iad.aaaaaaaaafiwqi57icjjdkwvlkf7li5lfnk4ad3jw4bvt73uvfdzrgvz7iqq", 
      "launch-mode": "NATIVE", 
      "launch-options": {
        "boot-volume-type": "ISCSI", 
        "firmware": "UEFI_64", 
        "network-type": "VFIO", 
        "remote-data-volume-type": "PARAVIRTUALIZED"
      "lifecycle-state": "AVAILABLE", 
      "operating-system": "Oracle Linux", 
      "operating-system-version": "7.5", 
      "size-in-mbs": 47694, 
      "time-created": "2018-05-15T03:22:42.463000+00:00"
      "base-image-id": null, 
      "compartment-id": null, 
      "create-image-allowed": true, 
      "defined-tags": {}, 
      "display-name": "Oracle-Linux-7.5-Gen2-GPU-2018.05.09-0", 
      "freeform-tags": {}, 
      "id": "ocid1.image.oc1.iad.aaaaaaaafde2zxmzk6abzji6hndayiqzb3jglubvvxhugfjqvvsywag355va", 
      "launch-mode": "NATIVE", 
      "launch-options": {
        "boot-volume-type": "ISCSI", 
        "firmware": "UEFI_64", 
        "network-type": "VFIO", 
        "remote-data-volume-type": "PARAVIRTUALIZED"
      "lifecycle-state": "AVAILABLE", 
      "operating-system": "Oracle Linux", 
      "operating-system-version": "7.5", 
      "size-in-mbs": 47694, 
      "time-created": "2018-05-10T15:41:47.117000+00:00"

Testing the OCI SDK

Here's a quick test of the Python SDK, using sample code from oci-python-sdk on GitHub, reading from the ~/.oci/config file:

(py36env) $ python
Python 3.6.3 (default, Feb  8 2018, 05:35:00) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import oci
>>> config = oci.config.from_file("~/.oci/config","DEFAULT")
>>> identity = oci.identity.IdentityClient(config)
>>> user = identity.get_user(config["user"]).data
>>> print(user)
  "compartment_id": "ocid1.tenancy.oc1..aaaaaaadkjfhksdjfhkjhsdfasieoirusnksndflknasdf7zxoxrw5jq",
  "defined_tags": {},
  "description": "sergio",
  "freeform_tags": {},
  "id": "ocid1.user.oc1..aaaadskjfhaksdjfhkljasdhfkjahsdfkjhasdflkjhsdf2r2req",
  "inactive_status": null,
  "lifecycle_state": "ACTIVE",
  "name": "sergio@domain.com",
  "time_created": "2017-04-08T22:54:30.717000+00:00"


Join the discussion

Comments ( 2 )
  • Johan Almqvist Monday, May 27, 2019
    python-oci-cli-2.5.11-1.el7.noarch requries python-cx_Oracle = 7.0 but that exact version is not availabe in the repo.
  • Simon Monday, May 27, 2019
    Hi Johan,

    python-cx_Oracle is available under "ol7_developer" channel:

    [root@localhost ~]# yum info python-cx_Oracle
    Available Packages
    Name : python-cx_Oracle
    Arch : x86_64
    Version : 7.1.3
    Release : 1.el7
    Size : 693 k
    Repo : ol7_developer/x86_64
    Summary : Python interface to Oracle
    URL : http://cx-oracle.sourceforge.net
    License : Python Software Foundation License
    Description : Python interface to Oracle conforming to the Python DB API 2.0 specification.
    : See http://www.python.org/topics/database/DatabaseAPI-2.0.html.

    To get "python-oci-cli" installed you need:

    - ol7_latest
    - ol7_developer
    - ol7_developer_EPEL

    channels enabled.
    See this example for further details:



Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.