{"id":4229,"library":"pyvmomi","title":"VMware vSphere Python SDK","description":"pyVmomi is the Python SDK for the VMware vSphere Management API, enabling developers to build solutions integrated with VMware ESXi and vCenter Server. It provides Python bindings for several SOAP-based vSphere APIs, including core VIM API and related extensions like ESX Agent Manager and Storage Policy API. While pyVmomi focuses on SOAP APIs, the vSphere Automation SDK for Python is recommended for REST API features. pyVmomi releases often correlate with vSphere major versions and maintain backward compatibility with the previous four vSphere releases and its own previous four releases.","status":"active","version":"9.0.0.0","language":"en","source_language":"en","source_url":"https://github.com/vmware/pyvmomi","tags":["vmware","vsphere","sdk","virtualization","api","automation","cloud"],"install":[{"cmd":"pip install --upgrade pyvmomi","lang":"bash","label":"Latest stable release"},{"cmd":"pip install -e \".[sso]\"","lang":"bash","label":"Install with SSO support (from source)"}],"dependencies":[{"reason":"Required for SSL operations; version limited to '<24.3.0' in pyvmomi 9.0.0.0 due to breaking changes in pyOpenSSL.","package":"pyOpenSSL"}],"imports":[{"note":"SmartConnectNoSSL is deprecated; it's better to manage SSL context explicitly with SmartConnect.","wrong":"from pyVim.connect import SmartConnectNoSSL","symbol":"SmartConnect","correct":"from pyVim.connect import SmartConnect, Disconnect"},{"symbol":"vim","correct":"from pyVmomi import vim"},{"note":"Path changed in pyvmomi 9.0.0.0.","wrong":"from pyVmomi.VmomiSupport import VmomiJSONEncoder","symbol":"VmomiJSONEncoder","correct":"from pyVmomi.VmomiJSONEncoder import VmomiJSONEncoder"},{"note":"Path changed in pyvmomi 9.0.0.0.","wrong":"from pyVmomi.VmomiSupport import templateOf","symbol":"templateOf","correct":"from pyVmomi.VmomiJSONEncoder import templateOf"},{"note":"Path changed in pyvmomi 9.0.0.0.","wrong":"from pyVmomi import ThumbprintMismatchException","symbol":"ThumbprintMismatchException","correct":"from pyVmomi.Security import ThumbprintMismatchException"}],"quickstart":{"code":"import ssl\nimport os\nfrom pyVim.connect import SmartConnect, Disconnect\nfrom pyVmomi import vim\n\n# Environment variables for credentials and host\nVCENTER_HOST = os.environ.get('VCENTER_HOST', 'your_vcenter_ip_or_fqdn')\nVCENTER_USER = os.environ.get('VCENTER_USER', 'your_username')\nVCENTER_PASS = os.environ.get('VCENTER_PASS', 'your_password')\n\nif VCENTER_HOST == 'your_vcenter_ip_or_fqdn' or VCENTER_USER == 'your_username' or VCENTER_PASS == 'your_password':\n    print(\"Please set VCENTER_HOST, VCENTER_USER, and VCENTER_PASS environment variables or update the script.\")\n    exit(1)\n\ndef main():\n    service_instance = None\n    context = None\n\n    try:\n        # Disable SSL certificate verification for labs/testing. NOT recommended for production.\n        context = ssl._create_unverified_context()\n        \n        print(f\"Connecting to vCenter: {VCENTER_HOST}...\")\n        service_instance = SmartConnect(host=VCENTER_HOST,\n                                      user=VCENTER_USER,\n                                      pwd=VCENTER_PASS,\n                                      sslContext=context)\n        \n        content = service_instance.RetrieveContent()\n        print(f\"Connected to vCenter: {content.about.fullName}\")\n\n        # Retrieve all virtual machines\n        container = content.viewManager.CreateContainerView(content.rootFolder, [vim.VirtualMachine], True)\n        vms = container.view\n        \n        print(\"\\nVirtual Machines:\")\n        if not vms:\n            print(\"No virtual machines found.\")\n        for vm in vms:\n            print(f\"  Name: {vm.name}, Power State: {vm.runtime.powerState}\")\n        \n        container.Destroy()\n\n    except Exception as e:\n        print(f\"Error: {e}\")\n    finally:\n        if service_instance:\n            print(\"Disconnecting from vCenter.\")\n            Disconnect(service_instance)\n\nif __name__ == '__main__':\n    main()","lang":"python","description":"This quickstart demonstrates how to connect to a vCenter Server, retrieve its content, and list all virtual machines using pyVmomi. It includes common practices like handling SSL contexts and using environment variables for credentials."},"warnings":[{"fix":"Review the pyVmomi 9.0.0.0 release notes for specific class and alias changes. Update import paths and method calls as detailed in the official documentation or the `imports` section of this registry entry. For example, `pyVmomi.VmomiSupport.VmomiJSONEncoder` moves to `pyVmomi.VmomiJSONEncoder.VmomiJSONEncoder`.","message":"pyVmomi 9.0.0.0 introduced several breaking changes including the removal or replacement of `SoapAdapter` connection classes, aliases like `publicVersions` and `dottedVersions`, and changes to the module paths for `VmomiJSONEncoder`, `templateOf()`, and `ThumbprintMismatchException`.","severity":"breaking","affected_versions":"9.0.0.0 and later"},{"fix":"Ensure your environment meets the updated dependency requirements. If you were relying on `six` directly, update your code to use Python 3 native constructs. Pin `pyOpenSSL` to a compatible version if issues arise.","message":"The `six` dependency has been removed, and the `pyOpenSSL` dependency is now limited to '<24.3.0' in pyVmomi 9.0.0.0 due to breaking changes in pyOpenSSL.","severity":"breaking","affected_versions":"9.0.0.0 and later"},{"fix":"Update your connection calls to use `token` and `tokenType` parameters for SSO authentication, as described in the official vSphere SDK documentation.","message":"The `b64token` and `mechanism` parameters for `pyVim.Connect()` and `pyVim.SmartConnect()` have been disabled in pyVmomi 9.0.0.0. They are replaced by `token` and `tokenType`.","severity":"deprecated","affected_versions":"9.0.0.0 and later"},{"fix":"For development or non-production environments, create an unverified SSL context: `context = ssl._create_unverified_context()` and pass it to `SmartConnect(sslContext=context)`. For production, import and verify the vCenter's SSL certificate.","message":"Connecting to vCenter or ESXi with untrusted (self-signed) SSL certificates will fail by default in modern Python versions.","severity":"gotcha","affected_versions":"All versions with Python 2.7.9+ or Python 3.x"},{"fix":"Determine whether you need to interact with SOAP-based Management APIs or REST-based Automation APIs. If the latter, switch to `vsphere-automation-sdk-python` for appropriate functionality.","message":"pyVmomi is designed for the vSphere Management API (SOAP-based). For newer vSphere Automation APIs (REST-based), you should use the `VMware vSphere Automation SDK for Python` instead.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always check the official pyVmomi compatibility matrix against your vSphere environment version to ensure support and expected behavior.","message":"pyVmomi maintains backward compatibility with the previous four releases of vSphere and its own previous four releases. Using it with significantly older or very new, unsupported vSphere versions may lead to unexpected behavior or missing features.","severity":"gotcha","affected_versions":"All versions (compatibility policy)"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}