IBM Cloudant Python SDK

0.11.5 · active · verified Thu Apr 09

The IBM Cloudant Python SDK is an actively maintained client library for interacting with IBM Cloudant APIs. Currently at version 0.11.5, it offers a unified IBM Cloud SDK experience, handles various authentication types, and provides a thread-safe client. While considered production-ready, it is still in a 0.x release series, meaning API changes may occur before its 1.0 release. It receives frequent patch releases.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the Cloudant client using IAM authentication with environment variables and then lists all available databases. Ensure to replace placeholder environment variables with your actual IBM Cloudant service URL and IAM API Key.

import os
from ibmcloudant.cloudant_v1 import CloudantV1
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator

# Retrieve credentials from environment variables (recommended)
service_url = os.environ.get('CLOUDANT_URL', 'YOUR_CLOUDANT_URL')
api_key = os.environ.get('CLOUDANT_APIKEY', 'YOUR_IAM_API_KEY')

# Ensure credentials are provided
if not service_url or not api_key:
    print("Error: CLOUDANT_URL and CLOUDANT_APIKEY environment variables must be set.")
    exit(1)

# Authenticate and create client
authenticator = IAMAuthenticator(api_key)
service = CloudantV1(authenticator=authenticator)
service.set_service_url(service_url)

# Example: List all databases
try:
    all_dbs = service.get_all_dbs().get_result()
    print("Databases:")
    for db in all_dbs:
        print(f"- {db}")
except Exception as e:
    print(f"An error occurred: {e}")

view raw JSON →