Registry / aws / oci

oci

JSON →
library2.170.0pypypi✓ verified 52d ago

The Oracle Cloud Infrastructure Python SDK (oci) provides a comprehensive set of APIs to interact with OCI services, allowing Python applications to manage cloud resources. Currently at version 2.170.0, it receives frequent updates to support new services, features, and API versions.

awsgcpazuredevops
pip install oci
Install & Compatibility
Where this runs
tested against v2.178.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.925 runs
installs and imports cleanly · install 0.0s · import 1.264s · 470.5MB
glibc
py 3.103.925 runs
installs and imports cleanly · install 20.9s · import 1.214s · 471MB
489MB installed
● package 489MB
Code
Verified usage

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

config
import oci.config
from oci import config
The 'config' module is typically imported directly as oci.config, not from the top-level 'oci' package.
IdentityClient
from oci.identity import IdentityClient
ObjectStorageClient
from oci.object_storage import ObjectStorageClient
ServiceError
from oci.exceptions import ServiceError
Paginators
import oci.pagination

This quickstart initializes an OCI IdentityClient using configuration loaded from the default `~/.oci/config` file. It then attempts to fetch the current authenticated user's details to verify connectivity and authentication. A missing configuration file or authentication failure will lead to an error message and exit, guiding the user on how to resolve it.

import oci import os try: # Load configuration from the default location (~/.oci/config) # The 'DEFAULT' profile is used if not explicitly specified. config = oci.config.from_file() # You can specify a different profile or file: # config = oci.config.from_file(file_location="~/.oci/config", profile_name="MY_PROFILE") except oci.exceptions.ConfigFileNotFound: print("WARNING: OCI config file not found.") print("Please ensure your OCI config file is set up at ~/.oci/config and contains a 'DEFAULT' profile.") print("Alternatively, provide credentials via environment variables (e.g., OCI_CONFIG_FILE, OCI_PROFILE) or use Instance Principals for OCI instances.") exit(1) # Cannot proceed without configuration # Initialize the IdentityClient for interacting with Identity services identity_client = oci.identity.IdentityClient(config) try: # The 'user' OCID is part of the loaded config (from the API key details). user_ocid = config["user"] # Get the current authenticated user's details user = identity_client.get_user(user_ocid).data print(f"Successfully authenticated as user: {user.name} (OCID: {user.id})") print(f"Region: {config['region']}") # Example of another common operation: List the root compartment details # root_compartment = identity_client.get_compartment(config["tenancy"]).data # print(f"Root Compartment: {root_compartment.name} (OCID: {root_compartment.id})") except oci.exceptions.ServiceError as e: print(f"OCI Service Error encountered (Code: {e.code}): {e.message}") if e.code == "NotAuthenticated": print("Authentication failed. Please check your OCI configuration (~/.oci/config), API key, or credentials.") elif e.code == "InvalidParameter": print(f"The user OCID '{user_ocid}' might be invalid or you lack permissions to view it.") print("To troubleshoot, ensure the user OCID in your config file is correct and the API key is valid.") exit(1) except Exception as e: print(f"An unexpected error occurred: {e}") exit(1)
oci --version
Debug
Known issues
gotchaWhen performing 'list' operations (e.g., `list_instances`, `list_buckets`), methods typically return only the first page of results. To retrieve all items, you must explicitly use paginators.
fix
Use `oci.pagination.list_call_get_all_results()` or the `.all()` method on the response object (where available) to iterate through all pages. Example: `for item in oci.pagination.list_call_get_all_results(client.list_resources, compartment_id=ocid).data:`
affects: All versions
gotchaThe most common issue is misconfiguration of the OCI SDK. This includes missing `~/.oci/config` file, incorrect profile name, invalid API key paths, or incorrect tenancy/user OCIDs.
fix
Ensure `~/.oci/config` is correctly set up with the required `user`, `fingerprint`, `key_file`, `tenancy`, and `region` properties. Verify permissions for the API key and ensure the profile name matches what's used in `oci.config.from_file()`.
affects: All versions
gotchaOCI API calls can raise `oci.exceptions.ServiceError` for issues like authentication failures, permission errors, or invalid parameters. Not catching this specific exception can lead to unhandled runtime errors.
fix
Wrap your OCI API calls in `try...except oci.exceptions.ServiceError as e:` blocks to handle specific error codes (e.g., `e.code == "NotAuthenticated"`) gracefully and provide user-friendly feedback.
affects: All versions
breakingThe default retry strategy for API calls changed from a fixed retry count to an exponential backoff strategy in versions greater than 2.24.0. This might alter the retry behavior of existing applications.
fix
If your application relies on specific retry behavior, explicitly configure a `retry_strategy` when initializing clients (e.g., `identity_client = oci.identity.IdentityClient(config, retry_strategy=oci.retry.NoneRetryStrategy())`) or update your code to account for the new default exponential backoff.
affects: >2.24.0
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'oci'
The 'oci' Python package is not installed in the current Python environment or is not accessible via the Python path.
fix
Install the OCI Python SDK using pip: `pip install oci` or `pip3 install oci` if using Python 3 specifically.
Could not find config file at ~/.oci/config
The OCI SDK cannot locate the configuration file required for authentication, which defaults to `~/.oci/config`.
fix
Ensure the `~/.oci/config` file exists with correct credentials (user, fingerprint, tenancy, region, key_file) or provide the configuration programmatically. Use `oci setup config` if the OCI CLI is installed to create it, or manually create the file with the necessary details.
oci.exceptions.ServiceError: {'status': 404, 'code': 'NotAuthorizedOrNotFound'
This error indicates either that the requested OCI resource does not exist, or the authenticated user/principal lacks the necessary IAM permissions to access it. OCI intentionally obfuscates the exact reason for security.
fix
Verify the OCID of the resource you are trying to access is correct. Then, review your IAM policies to ensure the user, group, or dynamic group associated with your authentication has the required permissions for the specific resource and compartment.
AttributeError: module 'oci.identity' has no attribute 'identityClient'
This error typically occurs due to incorrect capitalization when instantiating OCI client objects; OCI SDK client classes use PascalCase (e.g., `IdentityClient`).
fix
Correct the client class name to use proper capitalization: `identity_client = oci.identity.IdentityClient(config)`.
[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed
This error usually indicates an issue with SSL certificate validation, often encountered in corporate environments behind a proxy or with outdated/missing root certificates.
fix
In a corporate proxy environment, configure the `REQUESTS_CA_BUNDLE` environment variable to point to a custom certificate bundle, or set `OCI_CLI_CERT_BUNDLE` to a custom CA certificate file. Alternatively, update your operating system's root certificates.
Upgrade
Version history
2.178.0latest on PyPI
Audit
Dependencies

No dependency data recorded yet.

Agent activity
58 hits · last 30 days
node
6
seranking-bot
4
ahrefsbot
3
Amazon
1
bytedance
1
Resources