{"id":3723,"library":"openstacksdk","title":"OpenStack SDK for Python","description":"openstacksdk is the official Python SDK for building applications to work with OpenStack clouds. It provides a consistent and comprehensive set of interactions with OpenStack's numerous services, offering both a high-level abstraction layer and direct access to underlying APIs. The library is actively maintained, with version 4.10.0 being the current stable release, and it follows a continuous release model aligned with OpenStack's development cycles.","status":"active","version":"4.10.0","language":"en","source_language":"en","source_url":"https://github.com/openstack/openstacksdk","tags":["cloud","openstack","iaas","sdk","api client"],"install":[{"cmd":"pip install openstacksdk","lang":"bash","label":"Install OpenStack SDK"}],"dependencies":[{"reason":"Used for authentication and HTTP interactions.","package":"keystoneauth1","optional":false},{"reason":"For handling cloud configuration files (clouds.yaml) and environment variables.","package":"os-client-config","optional":false}],"imports":[{"note":"This is the primary and recommended import for accessing the SDK's functionality, including connection management and service proxies.","symbol":"openstack","correct":"import openstack"},{"note":"While technically possible, direct import of `Connection` is less common. The `openstack.connect()` factory function is the idiomatic way to create a connection instance, returning a `Connection` object.","wrong":"from openstack.connection import Connection","symbol":"Connection","correct":"from openstack import connection"},{"note":"Directly using `Resource` classes from submodules like `openstack.compute.v2.server` is a lower-level pattern. The recommended approach is to use the service proxies available through the `Connection` object (e.g., `conn.compute.servers()`) for higher-level operations.","wrong":"from openstack.compute.v2 import server; server.Server.list(session=conn.compute)","symbol":"Server","correct":"conn.compute.servers()"}],"quickstart":{"code":"import os\nimport openstack\nimport time\n\n# Configure connection via environment variables for a quickstart\n# In a real application, consider using a clouds.yaml file for more robust configuration.\n# Example: export OS_CLOUD='devstack' or set individual OS_ prefixed variables.\n# You can also pass auth parameters directly to openstack.connect()\n\n# Initialize and turn on debug logging (optional, but useful for troubleshooting)\nopenstack.enable_logging(debug=True)\n\ntry:\n    # Establish a connection to your OpenStack cloud\n    # 'envvars' tells openstacksdk to look for OS_CLOUD or individual OS_ prefixed environment variables\n    conn = openstack.connect(cloud='envvars')\n\n    print(\"Successfully connected to OpenStack!\")\n\n    # List available images\n    print(\"\\nAvailable images:\")\n    for image in conn.image.images():\n        print(f\"  ID: {image.id}, Name: {image.name}\")\n\n    # List available flavors (instance types)\n    print(\"\\nAvailable flavors:\")\n    for flavor in conn.compute.flavors():\n        print(f\"  ID: {flavor.id}, Name: {flavor.name}, RAM: {flavor.ram}MB, VCPUs: {flavor.vcpus}\")\n\n    # --- Example: Create a new server (instance) --- \n    # Requires an existing image, flavor, network, and keypair in your OpenStack cloud.\n    # Replace with actual values from your environment or obtained from the above listings.\n    IMAGE_NAME = os.environ.get('OS_TEST_IMAGE', 'cirros')\n    FLAVOR_NAME = os.environ.get('OS_TEST_FLAVOR', 'm1.tiny')\n    NETWORK_NAME = os.environ.get('OS_TEST_NETWORK', 'private') # Or 'public' if applicable\n    KEYPAIR_NAME = os.environ.get('OS_TEST_KEYPAIR', 'my_keypair')\n    SERVER_NAME = f\"test-sdk-server-{int(time.time())}\"\n\n    # Find the image, flavor, and network by name\n    image = conn.image.find_image(IMAGE_NAME)\n    flavor = conn.compute.find_flavor(FLAVOR_NAME)\n    network = conn.network.find_network(NETWORK_NAME)\n    keypair = conn.compute.find_keypair(KEYPAIR_NAME)\n\n    if not all([image, flavor, network, keypair]):\n        print(\"\\nError: One or more required resources (image, flavor, network, keypair) not found. Skipping server creation.\")\n    else:\n        print(f\"\\nCreating server '{SERVER_NAME}'...\")\n        server = conn.compute.create_server(\n            name=SERVER_NAME,\n            image_id=image.id,\n            flavor_id=flavor.id,\n            networks=[{\"uuid\": network.id}],\n            key_name=keypair.name\n        )\n        print(f\"Server '{SERVER_NAME}' created (ID: {server.id}). Waiting for active status...\")\n        conn.compute.wait_for_server(server)\n        print(f\"Server '{SERVER_NAME}' is now {server.status}.\")\n        print(f\"Access IPv4: {getattr(server, 'access_ipv4', 'N/A')}\")\n\n        # Cleanup: Delete the created server\n        print(f\"\\nDeleting server '{SERVER_NAME}' (ID: {server.id})...\")\n        conn.compute.delete_server(server.id)\n        conn.compute.wait_for_delete(server)\n        print(f\"Server '{SERVER_NAME}' deleted.\")\n\nexcept openstack.exceptions.SDKException as e:\n    print(f\"An OpenStack SDK error occurred: {e}\")\nexcept Exception as e:\n    print(f\"An unexpected error occurred: {e}\")\n","lang":"python","description":"This quickstart demonstrates how to establish a connection to an OpenStack cloud, list images and flavors, and then optionally create and delete a compute instance (server). It uses environment variables for authentication and resource naming for simplicity. For production, `clouds.yaml` is recommended. Ensure `OS_AUTH_URL`, `OS_USERNAME`, `OS_PASSWORD`, `OS_PROJECT_NAME`, and optionally `OS_CLOUD` are set in your environment, along with `OS_TEST_IMAGE`, `OS_TEST_FLAVOR`, `OS_TEST_NETWORK`, and `OS_TEST_KEYPAIR` for server creation."},"warnings":[{"fix":"Update your code to expect dictionary-like access for resource properties and adjust to new key names. Refer to the official release notes for `0.99.0` and `1.0.0` for detailed changes. For example, use `.to_dict()` if you explicitly need a dictionary representation from a resource object.","message":"Major breaking changes were introduced in `openstacksdk` versions `0.99.0` and `1.0.0`. The `Connection` interface now consistently utilizes `Resource` interfaces under the hood, and many API responses, which previously returned `Munch` objects, now return standard Python dictionaries. Additionally, many keys in the returned data were renamed.","severity":"breaking","affected_versions":">=0.99.0, >=1.0.0"},{"fix":"For services supporting microversions, explicitly specify the desired API version via connection parameters (e.g., `compute_api_version='2.latest'`) or service proxy arguments. Consult the OpenStack API reference for service-specific microversion details.","message":"OpenStack services often use 'microversions' for their APIs. If not explicitly specified, `openstacksdk` will default to the lowest API version supported by the service. This can lead to missing features or unexpected behavior if you expect a newer API version's functionality.","severity":"gotcha","affected_versions":"All versions"},{"fix":"If you require specific attributes that might be lazy-loaded, ensure you call the `fetch()` method on the resource object to retrieve its full details from the OpenStack API before accessing those attributes.","message":"Some resource attributes in `openstacksdk` are lazy-loaded, meaning they are not populated immediately when a resource object is created or returned from a list operation. For example, `block_device_mapping` or `networks` for a `Server` object might only be present after a `server.fetch()` call.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Carefully review your `clouds.yaml` file (if used) and environment variables for correctness. Ensure `auth_url` points to the correct Identity API version endpoint (e.g., `/v3`). The SDK will try to detect the API version, but explicit configuration helps. `openstack.enable_logging(debug=True)` can provide verbose authentication debug information.","message":"Authentication and configuration can be a common source of errors. Incorrect `clouds.yaml` file formats, missing environment variables, or mixing OpenStack Identity API versions (v2 vs. v3) in configuration can lead to authentication failures.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Enable Python's deprecation warnings during development and testing using the `-Wa` command-line option (`python -Wa your_script.py`) or by setting the `PYTHONWARNINGS` environment variable (e.g., `export PYTHONWARNINGS=default`). This helps identify code that needs updating before deprecated features are removed.","message":"`openstacksdk` utilizes a warnings infrastructure (e.g., `openstack.warnings.OpenStackDeprecationWarning`, `RemovedInSDK50Warning`, `RemovedInSDK60Warning`) to signal deprecated features, resources, or behavior. By default, `DeprecationWarning` messages are silenced in Python.","severity":"deprecated","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}