Install & Compatibility
Where this runs
tested against v2.16.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.732s · 30.5MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 5.5s · import 0.676s · 31MB
29MB installed
● package 29MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
ibm_boto3
✓ import ibm_boto3
✗ import boto3
The IBM COS SDK is a fork of boto3. For IBM Cloud Object Storage, you must import `ibm_boto3` instead of `boto3`. Using `boto3` will target AWS services by default.
Config
✓ from ibm_botocore.client import Config
Required for configuring the client with specific IBM COS authentication and endpoint details.
This quickstart demonstrates how to establish a connection to IBM Cloud Object Storage, list existing buckets, and perform basic file upload and download operations. It uses environment variables for secure credential handling. Ensure you replace placeholder values or set corresponding environment variables with your IBM Cloud API Key, resource instance ID, IAM authentication endpoint, and service endpoint.
import os
import ibm_boto3
from ibm_botocore.client import Config
# --- Environment Variables (Replace with your actual credentials/endpoints) ---
# Get these values from your IBM Cloud Object Storage service credentials.
# Set them as environment variables or replace directly in code (not recommended for production).
API_KEY = os.environ.get('IBM_COS_API_KEY_ID', 'YOUR_API_KEY_ID')
SERVICE_INSTANCE_ID = os.environ.get('IBM_COS_RESOURCE_INSTANCE_ID', 'YOUR_SERVICE_INSTANCE_ID')
AUTH_ENDPOINT = os.environ.get('IBM_COS_AUTH_ENDPOINT', 'https://iam.cloud.ibm.com/identity/token') # e.g., 'https://iam.cloud.ibm.com/identity/token'
SERVICE_ENDPOINT = os.environ.get('IBM_COS_ENDPOINT', 'https://s3.us.cloud-object-storage.appdomain.cloud') # e.g., 'https://s3.us.cloud-object-storage.appdomain.cloud'
if not all([API_KEY, SERVICE_INSTANCE_ID, AUTH_ENDPOINT, SERVICE_ENDPOINT]):
print("Error: Missing one or more required environment variables for IBM COS configuration.")
print("Please set IBM_COS_API_KEY_ID, IBM_COS_RESOURCE_INSTANCE_ID, IBM_COS_AUTH_ENDPOINT, IBM_COS_ENDPOINT.")
exit(1)
try:
# Create client object
cos_client = ibm_boto3.client(
's3',
ibm_api_key_id=API_KEY,
ibm_service_instance_id=SERVICE_INSTANCE_ID,
ibm_auth_endpoint=AUTH_ENDPOINT,
config=Config(signature_version='oauth'),
endpoint_url=SERVICE_ENDPOINT
)
print("Successfully connected to IBM Cloud Object Storage. Listing buckets...")
# List buckets
response = cos_client.list_buckets()
for bucket in response['Buckets']:
print(f"Bucket Name: {bucket['Name']}")
# Example: Upload a simple text file
bucket_name = "my-test-bucket-12345" # Replace with an existing bucket or create a new one
object_name = "hello_cos.txt"
data = "Hello from IBM COS Python SDK!"
try:
cos_client.put_object(Bucket=bucket_name, Key=object_name, Body=data)
print(f"Successfully uploaded '{object_name}' to bucket '{bucket_name}'.")
# Example: Download the file
obj = cos_client.get_object(Bucket=bucket_name, Key=object_name)
downloaded_data = obj['Body'].read().decode('utf-8')
print(f"Downloaded '{object_name}': {downloaded_data}")
except cos_client.exceptions.NoSuchBucket:
print(f"Warning: Bucket '{bucket_name}' not found. Skipping upload/download examples.")
except Exception as e:
print(f"An error occurred during object operations: {e}")
except Exception as e:
print(f"Failed to connect to IBM Cloud Object Storage: {e}")
Upgrade
Version history
2.16.2latest on PyPI · released Apr 14, 2026
Audit
Dependencies
ibm-cos-sdk-corerequiredCore functionality for IBM Cloud Object Storage SDK.
ibm-cos-sdk-s3transferrequiredHandles S3-like data transfer operations.
jmespathrequiredQuery language for JSON, used internally by the SDK.