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.
pip install ociVerified import paths — ran on the pinned version, not inferred.
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.
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:`
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()`.
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.
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.
Install the OCI Python SDK using pip: `pip install oci` or `pip3 install oci` if using Python 3 specifically.
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.
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.
Correct the client class name to use proper capitalization: `identity_client = oci.identity.IdentityClient(config)`.
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.
No dependency data recorded yet.