IBM Cloud SDK Core Library
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
- breaking Major breaking changes occurred between v2.x and v3.x, including a package rename from `ibm_sdk_core` to `ibm_cloud_sdk_core`. Direct imports and configuration methods for authenticators likely require updates.
- gotcha The library primarily serves as a foundation for other IBM Cloud SDKs. While you can directly use its authenticators, for interacting with specific IBM Cloud services (e.g., Object Storage, Watson APIs), you will typically install and use the dedicated Python SDK for that service, which in turn depends on and uses `ibm-cloud-sdk-core`.
- gotcha Configuration for authenticators (API keys, service URLs) can be sourced from constructor arguments, environment variables (e.g., `IBMCLOUD_API_KEY`, `IBMCLOUD_AUTH_TYPE`), or configuration files. Understand the precedence rules to avoid unexpected authentication failures.
- gotcha The library frequently updates its dependencies (like `requests` and `PyJWT`) to address security vulnerabilities (CVEs). Older versions of `ibm-cloud-sdk-core` might pin to vulnerable versions of these indirect dependencies.
- deprecated Older authenticator types or parameters might be deprecated in favor of new, more secure, or more flexible options. For example, `IAMAuthenticator` and `ContainerAuthenticator` have seen feature additions over time.
Install
-
pip install ibm-cloud-sdk-core
Imports
- IAMAuthenticator
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
- BearerTokenAuthenticator
from ibm_cloud_sdk_core.authenticators import BearerTokenAuthenticator
- NoAuthAuthenticator
from ibm_cloud_sdk_core.authenticators import NoAuthAuthenticator
- get_authenticator_from_external_sources
from ibm_cloud_sdk_core.authenticators import get_authenticator_from_external_sources
Quickstart
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()