IBM Cloud SDK Core Library

3.24.4 · active · verified Thu Apr 09

The `ibm-cloud-sdk-core` library provides essential functionalities like authentication, request signing, and utility methods for Python SDKs targeting IBM Cloud services. It is actively maintained with frequent patch releases addressing security and bug fixes, and periodic minor releases introducing new features or authenticators.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to instantiate an `IAMAuthenticator` using an API key (preferably from an environment variable) and then shows how a `BaseService` (the foundation for IBM Cloud service clients) would integrate with this authenticator. Replace `YOUR_IBMCLOUD_API_KEY` and `https://api.example.com` with actual values for your service.

import os
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
from ibm_cloud_sdk_core.base_service import BaseService

# Instantiate an authenticator using an API key from environment variables
api_key = os.environ.get('IBMCLOUD_API_KEY', 'YOUR_IBMCLOUD_API_KEY')
service_url = os.environ.get('IBMCLOUD_SERVICE_URL', 'https://api.example.com')

if api_key == 'YOUR_IBMCLOUD_API_KEY':
    print("Warning: Please set the IBMCLOUD_API_KEY environment variable or replace the placeholder.")

authenticator = IAMAuthenticator(api_key)

# Example of creating a dummy service client that uses this authenticator
class MyDummyService(BaseService):
    DEFAULT_SERVICE_URL = service_url

    def __init__(self, authenticator_instance):
        super().__init__(
            service_url=MyDummyService.DEFAULT_SERVICE_URL,
            authenticator=authenticator_instance
        )

    def do_something(self):
        # In a real SDK, this would make an API call
        print(f"Dummy service initialized with authenticator type: {type(self.authenticator).__name__}")
        print(f"Service URL: {self.service_url}")

# Initialize and use the dummy service
dummy_service = MyDummyService(authenticator)
dummy_service.do_something()

view raw JSON →