{"id":6835,"library":"python-glanceclient","title":"OpenStack Glance Client Library","description":"python-glanceclient is a client library for OpenStack Glance, the Image service, built on the Glance API. It provides a Python API for interacting with Glance and a command-line tool (`glance`). The current stable version is 4.11.0, and it follows the OpenStack release cadence, typically releasing new versions every six months to align with OpenStack's development cycle.","status":"active","version":"4.11.0","language":"en","source_language":"en","source_url":"https://github.com/openstack/python-glanceclient","tags":["openstack","cloud","api client","glance","image service"],"install":[{"cmd":"pip install python-glanceclient","lang":"bash","label":"Install latest stable"}],"dependencies":[{"reason":"Required for robust authentication against OpenStack Identity (Keystone) service.","package":"keystoneauth1"},{"reason":"Used for some common utilities and provides a higher-level abstraction for OpenStack services, including Glance.","package":"openstacksdk"}],"imports":[{"note":"While specific API versions existed in direct imports in older libraries, the recommended pattern for `python-glanceclient` is to import the generic `client` module and instantiate `glance_client.Client('2', ...)`.","wrong":"from glanceclient.v2 import client","symbol":"Client","correct":"from glanceclient import client as glance_client"}],"quickstart":{"code":"import os\nfrom keystoneauth1.identity import v3\nfrom keystoneauth1 import session\nfrom glanceclient import client as glance_client\n\n# --- Authentication --- \n# Ensure OpenStack environment variables are set (e.g., OS_AUTH_URL, OS_USERNAME, OS_PASSWORD, etc.)\n# You can also pass credentials directly, but environment variables are recommended.\nauth = v3.Password(\n    auth_url=os.environ.get('OS_AUTH_URL', 'http://localhost:5000/v3'),\n    username=os.environ.get('OS_USERNAME', 'admin'),\n    password=os.environ.get('OS_PASSWORD', 'password'),\n    project_name=os.environ.get('OS_PROJECT_NAME', 'admin'),\n    user_domain_name=os.environ.get('OS_USER_DOMAIN_NAME', 'Default'),\n    project_domain_name=os.environ.get('OS_PROJECT_DOMAIN_NAME', 'Default')\n)\nsess = session.Session(auth=auth)\n\n# --- Initialize Glance Client (API v2 recommended) ---\nglance = glance_client.Client('2', session=sess)\n\n# --- List Images ---\ntry:\n    print(\"\\nAvailable Glance Images:\")\n    images = glance.images.list()\n    if images:\n        for image in images:\n            print(f\"  ID: {image.id}, Name: {image.name}, Status: {image.status}, Visibility: {getattr(image, 'visibility', 'unknown')}\")\n    else:\n        print(\"  No images found.\")\nexcept Exception as e:\n    print(f\"Error connecting to Glance or listing images: {e}\")","lang":"python","description":"This quickstart demonstrates how to authenticate with OpenStack Keystone using environment variables and then initialize the Glance client to list available images. It uses API version 2, which is the default for recent Glance client versions. Make sure your OpenStack environment variables (e.g., `OS_AUTH_URL`, `OS_USERNAME`, `OS_PASSWORD`, `OS_PROJECT_NAME`) are set."},"warnings":[{"fix":"Explicitly pass the desired API version as the first argument, e.g., `glance_client.Client('1', session=sess)` for v1, or `glance_client.Client('2', session=sess)` for v2. It's recommended to upgrade to v2 where possible.","message":"The `glanceclient.client.Client()` constructor defaults to Glance API version 2 (v2) since `python-glanceclient` version 2.0.0. Older applications that implicitly relied on v1 might break or misbehave.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Explore `openstacksdk`'s documentation for its Glance module. For existing `glanceclient` code, continue using this library, as it remains a valid and supported option.","message":"While `python-glanceclient` is actively maintained, for new OpenStack-related development, consider using the higher-level `openstacksdk` library. It provides a more unified and consistent API across various OpenStack services.","severity":"gotcha","affected_versions":"All"},{"fix":"Always construct a `keystoneauth1.session.Session` object with an appropriate `keystoneauth1.identity` plugin (e.g., `v3.Password`, `v3.Token`) and pass this session to the `glanceclient.client.Client()` constructor via the `session` keyword argument.","message":"Direct authentication by passing username/password arguments to client constructors is discouraged for production environments due to security and flexibility concerns. The recommended approach is to use `keystoneauth1` sessions.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-15T00:00:00.000Z","next_check":"2026-07-14T00:00:00.000Z","problems":[]}