{"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":"python","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,"search_vec":"'4.10.0':54 'abstract':39 'access':43 'activ':50 'align':67 'api':46,77 'applic':13 'build':12 'client':78 'cloud':18,73 'comprehens':24 'consist':22 'continu':64 'current':57 'cycl':72 'develop':71 'direct':42 'follow':62 'high':37 'high-level':36 'iaa':75 'interact':27 'layer':40 'level':38 'librari':48 'maintain':51 'model':66 'numer':31 'offer':33 'offici':8 'openstack':1,17,29,69,74 'openstacksdk':5 'provid':20 'python':4,9 'releas':59,65 'sdk':2,10,76 'servic':32 'set':25 'stabl':58 'under':45 'version':53 'work':15","created_at":"2026-04-11T17:41:57.825448+00:00","updated_at":"2026-04-16T17:37:49.173882+00:00","problems":[{"fix":"Ensure your `clouds.yaml` file is correctly configured with all necessary authentication parameters (auth_url, username, password, project_name, etc.), or that the corresponding `OS_*` environment variables are properly set and sourced. Double-check for typos, extra quotes, or unescaped special characters in passwords, especially when setting environment variables.","cause":"This error, often accompanied by 'The request you have made requires authentication. (HTTP 401)', indicates that the OpenStack SDK could not successfully authenticate with the Keystone identity service due to incorrect or missing credentials in `clouds.yaml` or environment variables (e.g., `OS_AUTH_URL`, `OS_USERNAME`, `OS_PASSWORD`).","error":"Authentication failed"},{"fix":"Install the `openstacksdk` package using pip: `pip install openstacksdk`. If using a virtual environment, ensure it's activated before installation. If the error persists, verify the Python interpreter configured in your IDE or used by your script matches the one where the package was installed.","cause":"This error occurs when the `openstacksdk` library is not installed in the Python environment being used, or the Python interpreter cannot find the installed package.","error":"ModuleNotFoundError: No module named 'openstack'"},{"fix":"Verify that `clouds.yaml` exists in an accessible location and that the `cloud` parameter in `openstack.connect()` exactly matches a cloud entry in the `clouds.yaml` file. If using environment variables, use `cloud='envvars'` in `openstack.connect()` or ensure `OS_CLOUD` is set.","cause":"This error arises when `openstack.connect(cloud='<your_cloud_name>')` is called with a cloud name that is not defined in the `clouds.yaml` configuration file, or the `clouds.yaml` file itself is not found in one of the expected locations (e.g., `~/.config/openstack/`, `./`).","error":"No cloud named '<your_cloud_name>'"},{"fix":"This issue often requires ensuring all OpenStack-related Python packages (e.g., `openstacksdk`, `python-openstackclient`, `python-novaclient`) are compatible and up-to-date with each other. If using a specific tool or older client, consult its documentation for `openstacksdk` version requirements. In some cases, it might involve upgrading `openstacksdk` and related clients: `pip install --upgrade openstacksdk python-openstackclient`.","cause":"This `AttributeError` often occurs when older OpenStack client libraries or specific OpenStack components (like `nova-manage`) attempt to access internal `openstacksdk` attributes or classes (`openstack.proxy.Proxy`) that have been refactored, moved, or removed in newer versions of `openstacksdk`. This typically indicates an incompatibility between different installed OpenStack Python packages or a change in the SDK's internal structure.","error":"AttributeError: module 'openstack.proxy' has no attribute 'Proxy'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"4.19.1","cli_name":"","cli_version":null,"type":"library","homepage":"https://docs.openstack.org/openstacksdk","github":null,"docs":null,"changelog":null,"pypi":"https://pypi.org/project/openstacksdk/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["http-networking","devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-08-29","next_check":"2026-07-28","install_tag":null}}