{"id":1597,"library":"oci","title":"Oracle Cloud Infrastructure Python SDK","description":"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.","status":"active","version":"2.170.0","language":"python","source_language":"en","source_url":"https://github.com/oracle/oci-python-sdk","tags":["cloud","oracle","oci","sdk","infrastructure"],"install":[{"cmd":"pip install oci","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"note":"The 'config' module is typically imported directly as oci.config, not from the top-level 'oci' package.","wrong":"from oci import config","symbol":"config","correct":"import oci.config"},{"symbol":"IdentityClient","correct":"from oci.identity import IdentityClient"},{"symbol":"ObjectStorageClient","correct":"from oci.object_storage import ObjectStorageClient"},{"symbol":"ServiceError","correct":"from oci.exceptions import ServiceError"},{"symbol":"Paginators","correct":"import oci.pagination"}],"quickstart":{"code":"import oci\nimport os\n\ntry:\n    # Load configuration from the default location (~/.oci/config)\n    # The 'DEFAULT' profile is used if not explicitly specified.\n    config = oci.config.from_file()\n    # You can specify a different profile or file:\n    # config = oci.config.from_file(file_location=\"~/.oci/config\", profile_name=\"MY_PROFILE\")\nexcept oci.exceptions.ConfigFileNotFound:\n    print(\"WARNING: OCI config file not found.\")\n    print(\"Please ensure your OCI config file is set up at ~/.oci/config and contains a 'DEFAULT' profile.\")\n    print(\"Alternatively, provide credentials via environment variables (e.g., OCI_CONFIG_FILE, OCI_PROFILE) or use Instance Principals for OCI instances.\")\n    exit(1) # Cannot proceed without configuration\n\n# Initialize the IdentityClient for interacting with Identity services\nidentity_client = oci.identity.IdentityClient(config)\n\ntry:\n    # The 'user' OCID is part of the loaded config (from the API key details).\n    user_ocid = config[\"user\"]\n    \n    # Get the current authenticated user's details\n    user = identity_client.get_user(user_ocid).data\n    print(f\"Successfully authenticated as user: {user.name} (OCID: {user.id})\")\n    print(f\"Region: {config['region']}\")\n\n    # Example of another common operation: List the root compartment details\n    # root_compartment = identity_client.get_compartment(config[\"tenancy\"]).data\n    # print(f\"Root Compartment: {root_compartment.name} (OCID: {root_compartment.id})\")\n\nexcept oci.exceptions.ServiceError as e:\n    print(f\"OCI Service Error encountered (Code: {e.code}): {e.message}\")\n    if e.code == \"NotAuthenticated\":\n        print(\"Authentication failed. Please check your OCI configuration (~/.oci/config), API key, or credentials.\")\n    elif e.code == \"InvalidParameter\":\n        print(f\"The user OCID '{user_ocid}' might be invalid or you lack permissions to view it.\")\n    print(\"To troubleshoot, ensure the user OCID in your config file is correct and the API key is valid.\")\n    exit(1)\nexcept Exception as e:\n    print(f\"An unexpected error occurred: {e}\")\n    exit(1)\n","lang":"python","description":"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."},"warnings":[{"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:`","message":"When 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.","severity":"gotcha","affected_versions":"All versions"},{"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()`.","message":"The 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.","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"OCI 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.","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"The 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.","severity":"breaking","affected_versions":">2.24.0"}],"env_vars":null,"search_vec":"'2.170.0':34 'allow':24 'api':18,45 'applic':26 'cloud':2,8,29,47 'comprehens':15 'current':31 'featur':43 'frequent':37 'infrastructur':3,9,51 'interact':20 'manag':28 'new':41 'oci':12,22,49 'oracl':1,7,48 'provid':13 'python':4,10,25 'receiv':36 'resourc':30 'sdk':5,11,50 'servic':23,42 'set':16 'support':40 'updat':38 'version':33,46","created_at":"2026-04-09T03:54:58.061675+00:00","updated_at":"2026-04-16T17:30:52.370756+00:00","problems":[{"fix":"Install the OCI Python SDK using pip: `pip install oci` or `pip3 install oci` if using Python 3 specifically.","cause":"The 'oci' Python package is not installed in the current Python environment or is not accessible via the Python path.","error":"ModuleNotFoundError: No module named 'oci'"},{"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.","cause":"The OCI SDK cannot locate the configuration file required for authentication, which defaults to `~/.oci/config`.","error":"Could not find config file at ~/.oci/config"},{"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.","cause":"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.","error":"oci.exceptions.ServiceError: {'status': 404, 'code': 'NotAuthorizedOrNotFound'"},{"fix":"Correct the client class name to use proper capitalization: `identity_client = oci.identity.IdentityClient(config)`.","cause":"This error typically occurs due to incorrect capitalization when instantiating OCI client objects; OCI SDK client classes use PascalCase (e.g., `IdentityClient`).","error":"AttributeError: module 'oci.identity' has no attribute 'identityClient'"},{"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.","cause":"This error usually indicates an issue with SSL certificate validation, often encountered in corporate environments behind a proxy or with outdated/missing root certificates.","error":"[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"2.178.0","cli_name":"oci","cli_version":"sh: 1: oci: not found","type":"library","homepage":"https://docs.oracle.com/en-us/iaas/tools/python/latest/index.html","github":null,"docs":null,"changelog":null,"pypi":"https://pypi.org/project/oci/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["aws","gcp","azure","devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-06-28","next_check":"2026-07-28","install_tag":null}}