Registry / devops / oci-cli

oci-cli

JSON →
library3.91.0pypypi✓ verified 22d ago

The Oracle Cloud Infrastructure CLI (oci-cli) is a command-line interface that allows users to interact with Oracle Cloud Infrastructure services. Built on the OCI Python SDK, it provides equivalent functionality to the OCI Console, plus additional commands and scripting capabilities. The current version is 3.78.0, and it is actively maintained by Oracle with frequent updates and new feature releases.

pip install oci-cli
INSTALL
IMPORT
SIG · OCI-CLI
O
oci-cli
devopspythonv3.91.0
Install
23.9s avg
Import
1260ms
Disk
735MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v3.91.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 1.254s · 697.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 33.4s · import 1.266s · 700MB
735MB installed
● package 735MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

oci
import oci
import oci_cli
While `oci-cli` is the installed package, the underlying Python SDK for programmatic interaction is imported as `oci`. Do not attempt to import modules directly from `oci_cli` as it primarily contains CLI internals.

This quickstart demonstrates how to use the underlying OCI Python SDK to list compartments within your Oracle Cloud Infrastructure tenancy. Before running, ensure you have configured your OCI CLI by running `oci setup config` in your terminal to create the `~/.oci/config` file and API keys. The script loads this configuration for authentication.

# First, ensure your OCI configuration file (~/.oci/config) is set up. # You can generate one interactively using: oci setup config # # Then, use the OCI Python SDK (installed with oci-cli): import oci import os # Load the OCI config from the default location and profile # (or specify path and profile like oci.config.from_file("/path/to/config", "YOUR_PROFILE")) try: config = oci.config.from_file(os.environ.get('OCI_CONFIG_FILE', '~/.oci/config'), os.environ.get('OCI_PROFILE', 'DEFAULT')) except oci.exceptions.ConfigFileNotFound as e: print(f"Error: OCI config file not found. Please run 'oci setup config' or set OCI_CONFIG_FILE and OCI_PROFILE environment variables. {e}") exit(1) # Create an IdentityClient identity_client = oci.identity.IdentityClient(config) # Get the tenancy OCID from the config tenancy_id = config["tenancy"] # List compartments in the tenancy try: list_compartments_response = identity_client.list_compartments(compartment_id=tenancy_id, compartment_id_in_subtree=True) print("Listing Compartments:") for compartment in list_compartments_response.data: print(f" Name: {compartment.name}, ID: {compartment.id}, Lifecycle State: {compartment.lifecycle_state}") except oci.exceptions.ServiceError as e: print(f"Error listing compartments: {e}") if e.code == 'NotAuthenticated': print("Please check your API key and fingerprint in ~/.oci/config.") elif e.code == 'AuthRequired': print("Authentication failed. Ensure your API key is correctly configured and has necessary permissions.")
oci --version
Debug
Known issues
breakingBreaking changes occur frequently in new releases, often involving parameter renames, commands being moved, or parameters becoming required. Always review the GitHub releases page or `CHANGELOG.rst` before upgrading major or minor versions.
fix
Consult the `CHANGELOG.rst` or GitHub release notes for the specific version you are upgrading to and update your scripts/commands accordingly. Example: `--software-source-ids` became a required parameter in `oci os-management-hub profile create-software-source-profile` in a recent update.
affects: All versions (check release notes for specific changes)
gotchaThe `--defaults-file` CLI option is deprecated. Use `--cli-rc-file` instead for specifying CLI-specific configuration files.
fix
Replace `--defaults-file` with `--cli-rc-file` in your CLI commands and scripts.
affects: All versions where `--defaults-file` is used
breakingOCI Data Science is deprecating Oracle Identity Cloud Service (IDCS) authentication for ML Applications. After April 11, 2026, deployments using IDCS-based authentication will not be supported, and new ML application instances cannot be created using IDCS.
fix
Migrate all ML application instances to use Oracle Cloud Infrastructure Identity and Access Management (IAM) for authentication and authorization.
affects: ML Application instances using IDCS authentication, effective April 11, 2026
gotchaThe OCI CLI (and SDK) requires a properly configured `~/.oci/config` file and corresponding API key pair for authentication. Incorrect setup or permissions is a common source of errors.
fix
Run `oci setup config` to generate the configuration file and API keys. Ensure the public key is uploaded to your OCI user in the Console, and the private key file path and fingerprint in `~/.oci/config` are correct and accessible.
affects: All versions
gotchaWhen querying JSON output with `--query`, the argument uses JMESPath syntax. This is powerful but can be unfamiliar and requires understanding JMESPath expressions for effective filtering and transformation. Using `--filter` provides SCIM-based filtering *before* `--query` is applied.
fix
Familiarize yourself with JMESPath (jmespath.org). For large datasets, consider using `--filter` with SCIM expressions (which might use different attribute names than the CLI output) alongside `--query` to reduce client-side processing.
affects: All versions using `--query`
Errors
Common errors & fixes
oci: command not found
The 'oci' executable is not in your system's PATH environment variable, or the OCI CLI was not installed correctly or in an active virtual environment.
fix
Ensure the OCI CLI is installed in an accessible location and its executable directory (e.g., `~/bin` or Python's `Scripts` directory on Windows) is included in your system's PATH. If using a virtual environment, activate it. On Windows, you might need to add `C:\Users\<username>\AppData\Roaming\Python\Scripts` to your PATH.
ServiceError: { "code": "NotAuthenticated", "message": "The required information to complete authentication was not provided.", "status": 401 }
This error typically indicates that the OCI CLI cannot authenticate due to an invalid or incomplete configuration file, incorrect API key details (user OCID, tenancy OCID, fingerprint, key file path), or a mismatch between the local private key and the public key uploaded to OCI.
fix
Run `oci setup config` to reconfigure your CLI. Verify that your `~/.oci/config` file contains the correct `user`, `fingerprint`, `key_file` path, `tenancy`, and `region`. Ensure the private key file has appropriate permissions (e.g., `600`) and the corresponding public key is uploaded to your OCI user's API Keys in the OCI Console.
ERROR: Could not find config file at /root/.oci/config
The OCI CLI cannot locate its configuration file at the default or specified path, often due to an incorrect path, the file not existing, or improper permissions preventing access.
fix
Check if the `~/.oci/config` file exists in the expected location (e.g., `/home/user/.oci/config` on Linux/macOS or `C:\Users\<username>\.oci\config` on Windows). If not, run `oci setup config` to create it. Ensure the `.oci` directory and `config` file have restrictive permissions (e.g., `chmod 700 ~/.oci` and `chmod 600 ~/.oci/config`).
ServiceError: { "code": "NotAuthorizedOrNotFound", "message": "Authorization failed or requested resource not found.", "status": 404 }
This error means the authenticated user either lacks the necessary IAM permissions (policy statements) to perform the requested operation on the specified resource, or the resource itself does not exist (e.g., incorrect OCID, wrong compartment).
fix
Verify that the resource OCID is correct and that the resource exists. Review your IAM policies in the OCI Console to ensure your user or group has the required permissions for the operation and the resource's compartment. If accessing a resource in a specific compartment, confirm the compartment ID is correct.
Upgrade
Version history
3.91.0latest on PyPI · released Aug 25, 2026
Audit
Dependencies
ocirequiredThe core Oracle Cloud Infrastructure Python SDK, which the CLI is built upon.
cryptographyrequiredUsed for secure communications and API key management.
PyYAMLrequiredUsed for parsing and managing configuration files.
jmespathrequiredUsed for powerful JSON querying capabilities, especially with the `--query` flag.
Agent activity
20 hits · last 30 days
node
18
Amazon
1
Resources