{"id":4729,"library":"python-openstackclient","title":"OpenStack Command-line Client","description":"OpenStackClient (OSC) is a command-line client for OpenStack that unifies the command sets for core services like Compute, Identity, Image, Network, Object Store, and Block Storage into a single shell with a uniform structure. It is currently at version 9.0.0 and aligns its release cadence with the broader OpenStack project releases, offering regular updates and support for new features.","status":"active","version":"9.0.0","language":"en","source_language":"en","source_url":"https://github.com/openstack/python-openstackclient","tags":["OpenStack","CLI","cloud","client","infrastructure"],"install":[{"cmd":"python3 -m pip install python-openstackclient","lang":"bash","label":"Install `python-openstackclient`"},{"cmd":"python3 -m pip install openstackclient","lang":"bash","label":"Recommended: Install `openstackclient` metapackage (includes plugins)"}],"dependencies":[{"reason":"The `openstackclient` package is a metapackage that installs `python-openstackclient` and a number of optional plugins, simplifying installation for a full CLI experience.","package":"openstackclient","optional":true}],"imports":[{"note":"`python-openstackclient` is primarily a command-line interface. Direct programmatic import of the `openstackclient` module for application logic is not the typical pattern. For Python API interactions, the `openstacksdk` library is recommended. If you need to execute CLI commands from Python, use `subprocess`.","wrong":"from openstackclient import Client","symbol":"openstack","correct":"import subprocess\n# ... or use openstacksdk for direct Python API interaction"}],"quickstart":{"code":"import os\nimport subprocess\n\n# --- Configuration (choose one method) ---\n# Method 1: Environment Variables (recommended for scripts)\nos.environ['OS_AUTH_URL'] = os.environ.get('OS_AUTH_URL', 'http://<your-keystone-url>/v3')\nos.environ['OS_USERNAME'] = os.environ.get('OS_USERNAME', 'admin')\nos.environ['OS_PASSWORD'] = os.environ.get('OS_PASSWORD', 'your_password')\nos.environ['OS_PROJECT_NAME'] = os.environ.get('OS_PROJECT_NAME', 'admin')\nos.environ['OS_USER_DOMAIN_NAME'] = os.environ.get('OS_USER_DOMAIN_NAME', 'Default')\nos.environ['OS_PROJECT_DOMAIN_NAME'] = os.environ.get('OS_PROJECT_DOMAIN_NAME', 'Default')\nos.environ['OS_IDENTITY_API_VERSION'] = os.environ.get('OS_IDENTITY_API_VERSION', '3')\n\n# Method 2: clouds.yaml (often found in ~/.config/openstack/clouds.yaml)\n# Ensure your clouds.yaml is configured and replace 'my-cloud' with your cloud name\n# If using clouds.yaml, you might not need to set environment variables.\n# Example clouds.yaml content (place in ~/.config/openstack/clouds.yaml or specify via OS_CLIENT_CONFIG_FILE):\n# clouds:\n#   my-cloud:\n#     auth:\n#       auth_url: 'http://<your-keystone-url>/v3'\n#       username: 'admin'\n#       password: 'your_password'\n#       project_name: 'admin'\n#       user_domain_name: 'Default'\n#       project_domain_name: 'Default'\n#     region_name: 'RegionOne'\n\n# Example: List OpenStack projects using the CLI\ntry:\n    print(\"\\n--- Listing OpenStack Projects ---\")\n    # Use 'openstack --os-cloud my-cloud project list' if using clouds.yaml\n    result = subprocess.run(['openstack', 'project', 'list'], capture_output=True, text=True, check=True)\n    print(result.stdout)\n    if result.stderr:\n        print(\"Stderr:\\n\", result.stderr)\n\n    print(\"\\n--- Listing OpenStack Services ---\")\n    result = subprocess.run(['openstack', 'service', 'list'], capture_output=True, text=True, check=True)\n    print(result.stdout)\n    if result.stderr:\n        print(\"Stderr:\\n\", result.stderr)\n\nexcept subprocess.CalledProcessError as e:\n    print(f\"Error executing OpenStack CLI command: {e.cmd}\")\n    print(f\"Return Code: {e.returncode}\")\n    print(f\"Stdout:\\n{e.stdout}\")\n    print(f\"Stderr:\\n{e.stderr}\")\nexcept FileNotFoundError:\n    print(\"Error: 'openstack' command not found. Is OpenStackClient installed and in your PATH?\")\n","lang":"python","description":"This quickstart demonstrates how to interact with the OpenStack CLI programmatically from Python using `subprocess`. It shows two common authentication methods: environment variables (often sourced from an `openrc` file) and `clouds.yaml`. Ensure your OpenStack credentials are set as environment variables or configured in a `clouds.yaml` file for the client to authenticate successfully."},"warnings":[{"fix":"Ensure your environment uses Python 3.10 or higher. Use `python3 -m pip install ...`.","message":"Python 2.x is no longer supported. `python-openstackclient` 9.0.0 requires Python >=3.10. Older versions of the client (especially pre-3.x) might have exhibited syntax errors if run with Python 2.","severity":"breaking","affected_versions":"<9.0.0"},{"fix":"For a full suite of commands, `pip install openstackclient` is generally preferred.","message":"There are two PyPI packages: `python-openstackclient` (the core client) and `openstackclient` (a metapackage that installs `python-openstackclient` and common plugins). The latter is often recommended for a more complete experience.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Prefer using `openstack <service> <command>` (e.g., `openstack server list`) over legacy commands (e.g., `nova list`). Refer to documentation for equivalent commands.","message":"Legacy project-specific command-line clients (e.g., `nova`, `glance`, `cinder` CLIs) are being actively superseded by `python-openstackclient` for a unified experience. Some advanced or less common features might still exist only in the legacy clients but are being migrated.","severity":"deprecated","affected_versions":"All versions (ongoing transition)"},{"fix":"Always use Python virtual environments (`python3 -m venv .venv` and `source .venv/bin/activate`) when installing packages with `pip` to isolate dependencies.","message":"Installing Python packages directly into the system's Python environment using `pip install` without a virtual environment can lead to conflicts and break system tools.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure one of the authentication methods is correctly configured. For `clouds.yaml`, it's typically located at `~/.config/openstack/clouds.yaml` or specified via `OS_CLIENT_CONFIG_FILE`. Verify settings like `OS_AUTH_URL`, `OS_USERNAME`, `OS_PASSWORD`, `OS_PROJECT_NAME`, etc.","message":"Authentication can be configured via environment variables (e.g., sourcing an `openrc` file), a `clouds.yaml` file, or command-line options. Inconsistent or missing authentication details are a common source of errors.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}