This topic describes how to install, configure, and use the Oracle Cloud Infrastructure Python SDK.
The Python SDK requires:
- Python version 3.6, 3.7, 3.8 and 3.9
- OpenSSL version 1.0.2 or later. The Python SDK uses the Cryptography.io library which requires OpenSSL. For details on all Cryptography.io prerequisites, see Cryptography.io Installation.
In addition, all Oracle Cloud Infrastructure SDKs require:
- An Oracle Cloud Infrastructure account
- A user created in that account, in a group with a policy that grants the desired permissions. This can be a user for yourself, or another person/system that needs to call the API. For an example of how to set up a new user, group, compartment, and policy, see Adding Users in the Getting Started Guide. For a list of other typical Oracle Cloud Infrastructure policies, see Common Policies in the User Guide.
- A keypair used for signing API requests, with the public key uploaded to Oracle. Only the user calling the API should be in possession of the private key. (For more information, see Configuring the SDK.)
Downloading and Installing the SDK¶
You can install the Python SDK through the Python Package Index (PyPI), GitHub, OCI Resource Manager or yum on Oracle Linux.
Set up a virtual environment¶
Oracle recommends that you run the SDK in a virtual environment with virtualenv. This allows you to isolate the dependencies for the SDK and avoids any potential conflicts with other Python packages which may already be installed (e.g. in your system-wide Python).
With Linux, virtualenv is usually in a separate package from the main Python package.
If you need to install virtualenv, use
pip install virtualenv.
To create and activate a virtual environment:
virtualenv <environment name> source <environment name>/bin/activate
virtualenv oci_sdk_env source oci_sdk_env/bin/activate
To install from GitHub:
Download the SDK from GitHub. The download is a zip containing a whl file and documentation.
Extract the files from the zip.
Use the following command to install the SDK:
pip install oci-*-py3-none-any.whl
If you’re unable to install the whl file, make sure pip is up to date. Use
pip install -U pipand then try to install the whl file again.
To install the Python SDK in an environment which does not allow internet connection, you can use the OCI CLI offline install files to install the Python SDK in offline mode. Here are the steps:
Go to the CLI releases page
- To install the latest SDK version, go to the latest release. If you want to install a particular SDK version, follow the below steps:
Go to the “Assets” area.
Download the .zip file for your Operating System.
Copy the .zip file to the environment in which you want to install the SDK.
Unzip the .zip file. This should create a new directory called “oci-cli-installation”.
Use the following command to install the SDK:
pip3 install oci --find-links ./oci-cli-installation/cli-deps --no-index
If you have any issues executing the above steps, please see common installation issues here https://github.com/oracle/oci-cli/blob/master/COMMON_ISSUES.rst or create a Github issue and we will look into it.
Installing with Resource Manager¶
You can use Resource Manager to install the Oracle Cloud Development Kit on a Compute instance in your compartment. The Oracle Cloud Development Kit includes the SDK for Python, along with other Oracle development tools.
Installing with yum¶
If you’re using Oracle Linux 7, you can use yum to install the OCI SDK for Python.
The following example shows how to use yum to install the OCI SDK for Python 3.6:
sudo yum install python36-oci-sdk.x86_64
Configuring the SDK¶
Before using the SDK, you must set up your config file with the required credentials. For instructions, see SDK and Tool Configuration in the User Guide.
Verify OpenSSL Version¶
The supported version of OpenSSL for the Python SDK is version 1.0.2 or newer. Run the following command to find out the version of OpenSSL that you have:
python -c "import ssl; print(ssl.OPENSSL_VERSION)"
If the version is lower than
1.0.2, run the following command to bypass the version issue:
pip install requests[security]==2.18.4
If you don’t want to use
requests[security] you can update OpenSSL as you normally would. For example, on OS X, use Homebrew to update OpenSSL using the following commands:
brew update brew install openssl brew install python
If you need to configure your environment for FIPS-compliance, see Using FIPS-validated Libraries
You might encounter issues when installing Python or the SDK, or using the SDK itself.
Any operation resulting in a service error will cause an exception of type oci.exceptions.ServiceError to be thrown by the SDK. For information about common service errors, see API Errors.
pip 10 Installation Errors¶
If you are attempting to install the SDK in your system-wide Python using pip 10 then you may encounter conflicts with
distutils installed packages. An example error message is:
sudo pip install oci ... ... Cannot uninstall 'requests'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.
Resolve by using a virtual environment¶
Installing the SDK in a virtual environment instead of the system-wide Python. See the Downloading and Installing the SDK section for more information
Resolve by using the system-wide Python¶
If you wish to still use the system-wide Python, you can resolve this issue by downgrading the version of
pip you are using and then trying to re-install the SDK.
sudo pip install pip==9.0.3 sudo pip install oci
If you wish to stick with
pip version 10, then you will either have to install the SDK using the
pip install oci --user
Or you will have to uninstall the distutils installed packages manually. To do this, you will have to:
Make a note of what packages cannot be uninstalled. In the example error message, the package is requests
Find the install location for these packages. You can find this by looking in the directories returned by
python -m site
One of the directories should contain a sub-directory with the same name as the package (e.g. in the case of the example error message the folder should be called requests) and a
.egg-infofile which contains the package name and a version
Delete the folder and the
Try and re-install the SDK:
sudo pip install oci