{"id":5112,"library":"apache-libcloud","title":"Apache Libcloud","description":"Apache Libcloud is a standard Python library that abstracts away differences among multiple cloud provider APIs, offering a unified interface to manage various cloud resources like servers, object storage, load balancers, and DNS. The current version is 3.9.0. The project follows an event-driven release schedule, with new versions released as enough changes accumulate, or for critical bug and security fixes.","status":"active","version":"3.9.0","language":"en","source_language":"en","source_url":"https://github.com/apache/libcloud","tags":["cloud","multi-cloud","aws","gcp","azure","compute","storage","dns","load-balancer","iaas"],"install":[{"cmd":"pip install apache-libcloud","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"note":"Import specific cloud provider types from the relevant service module (e.g., compute, storage, dns).","symbol":"Provider","correct":"from libcloud.compute.types import Provider"},{"note":"Use 'get_driver' from the 'providers' submodule of the desired service API.","symbol":"get_driver","correct":"from libcloud.compute.providers import get_driver"}],"quickstart":{"code":"import os\nfrom libcloud.compute.types import Provider\nfrom libcloud.compute.providers import get_driver\n\n# Set your credentials using environment variables for security\nRACKSPACE_USER = os.environ.get('RACKSPACE_USERNAME', 'your_username')\nRACKSPACE_API_KEY = os.environ.get('RACKSPACE_API_KEY', 'your_api_key')\n\nif RACKSPACE_USER == 'your_username' or RACKSPACE_API_KEY == 'your_api_key':\n    print(\"Please set RACKSPACE_USERNAME and RACKSPACE_API_KEY environment variables.\")\n    exit(1)\n\n# Obtain a reference to the Rackspace Compute driver\ncls = get_driver(Provider.RACKSPACE)\ndriver = cls(RACKSPACE_USER, RACKSPACE_API_KEY, region='iad') # 'iad' for US-East (Virginia)\n\nprint(\"Connected to Rackspace Compute service.\")\n\n# List available sizes (flavors)\nprint(\"Available sizes:\")\nsizes = driver.list_sizes()\nfor size in sizes:\n    print(f\"  - {size.id}: {size.name} ({size.ram}MB RAM, {size.disk}GB Disk)\")\n\n# List available images\nprint(\"Available images:\")\nimages = driver.list_images()\nfor image in images:\n    print(f\"  - {image.id}: {image.name}\")\n\n# Example: Select a size and image for node creation (adjust as needed)\n# This is a placeholder and might require matching a specific image/size from your account/region\n# For Rackspace, a common base image might be 'Ubuntu 18.04' or similar.\n# For size, 'performance1-1' (1GB RAM) is common.\nselected_size = next((s for s in sizes if s.id == 'performance1-1'), None)\nselected_image = next((i for i in images if 'Ubuntu 18.04' in i.name), None)\n\nif selected_size and selected_image:\n    print(f\"Attempting to create node with size: {selected_size.name} and image: {selected_image.name}\")\n    # Note: Creating a node usually incurs cost. This part is commented out.\n    # try:\n    #     node = driver.create_node(name='libcloud-test-node', size=selected_size, image=selected_image)\n    #     print(f\"Node created: {node.name} (ID: {node.id}, State: {node.state})\")\n    # except Exception as e:\n    #     print(f\"Error creating node: {e}\")\nelse:\n    print(\"Could not find suitable size or image for node creation. Please check available options.\")\n","lang":"python","description":"This quickstart demonstrates how to connect to a cloud provider (Rackspace in this example) using the Libcloud Compute API. It shows how to obtain a driver, authenticate using environment variables, and list available server sizes and images. Remember to replace placeholder credentials with your actual API keys and username, preferably loaded from environment variables for security."},"warnings":[{"fix":"Ensure your Python environment is running Python 3.10 or newer when using Libcloud 3.9.0+. For older Python versions, you must pin to an older Libcloud release (e.g., v3.8.x for Python 3.7/3.8, v3.9.x for Python 3.9).","message":"Libcloud 3.9.0 (and newer) has significantly narrowed its Python version support. It now officially requires Python >= 3.10. Support for Python 3.9, 3.8, and 3.7 has been explicitly dropped in recent 3.x releases.","severity":"breaking","affected_versions":"3.x (specifically 3.5.0+, 3.7.0+, 3.9.0+)"},{"fix":"Review the Libcloud 3.8.0 changelog for a list of removed drivers. If your provider is affected, you will need to migrate to a supported provider or pin to an older Libcloud version that still includes the necessary driver.","message":"Several compute drivers for defunct or non-offering providers were removed in Libcloud 3.8.0. If you are upgrading from an older version and using one of these providers, your code will break.","severity":"breaking","affected_versions":"3.8.0+"},{"fix":"Always use environment variables, a secure configuration management system, or a dedicated secrets manager to handle sensitive API keys and usernames. Access them via `os.environ.get()` as shown in the quickstart example.","message":"Hardcoding API credentials directly in your code is a security risk. It's a common mistake that leads to credential exposure.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Upgrade to Libcloud version 0.4.2 or higher. Additionally, ensure `libcloud.security.VERIFY_SSL_CERT` is set to `True` for secure connections, although this is the default in modern versions.","message":"In older versions (prior to 0.4.2), Libcloud did not validate host SSL certificates by default, making applications vulnerable to Man-in-the-Middle attacks.","severity":"gotcha","affected_versions":"< 0.4.2"}],"env_vars":null,"last_verified":"2026-04-13T00:00:00.000Z","next_check":"2026-07-12T00:00:00.000Z"}