IBM Cloud Platform Services Python SDK

0.75.0 · active · verified Sun Apr 12

The Python client library for IBM Cloud Platform Services, providing access to various IBM Cloud platform APIs such as IAM Identity, Global Tagging, Account Management, and more. Currently at version `0.75.0`, it receives frequent updates, often on a monthly or bi-monthly cadence, incorporating new features and bug fixes derived from upstream API changes.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to authenticate with an IBM Cloud API key and initialize the IAM Identity service client to list account settings. Replace `YOUR_IBMCLOUD_API_KEY` or set the `IBMCLOUD_API_KEY` environment variable. The `IBMCLOUD_IAM_IDENTITY_SERVICE_URL` is optional, defaulting to the global IAM endpoint.

import os
from ibm_platform_services.iam_identity_v1 import IamIdentityV1
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
from ibm_cloud_sdk_core.detailed_response import DetailedResponse

# Configure API key and service URL
api_key = os.environ.get("IBMCLOUD_API_KEY", "YOUR_IBMCLOUD_API_KEY")
service_url = os.environ.get("IBMCLOUD_IAM_IDENTITY_SERVICE_URL", "https://iam.cloud.ibm.com")

if api_key == "YOUR_IBMCLOUD_API_KEY":
    print("Please set the IBMCLOUD_API_KEY environment variable or replace 'YOUR_IBMCLOUD_API_KEY' with your actual IBM Cloud API key.")
    exit(1)

try:
    # 1. Authenticate using IAMAuthenticator
    authenticator = IAMAuthenticator(api_key)

    # 2. Initialize the service client (e.g., IAM Identity Service)
    iam_identity_service = IamIdentityV1(authenticator=authenticator)
    iam_identity_service.set_service_url(service_url)

    # 3. Perform an operation (e.g., list account settings)
    print("Attempting to list account settings...")
    response: DetailedResponse = iam_identity_service.list_account_settings().get_result()
    
    print("Successfully retrieved account settings (first 200 chars):\n")
    print(str(response)[:200] + ('...' if len(str(response)) > 200 else ''))

except Exception as e:
    print(f"An error occurred: {e}")
    print("Please ensure your API key and service URL are correct and you have the necessary permissions.")

view raw JSON →