Packaging the VMware vSAN SDK for Python

The vSAN Management SDK for Python is distributed as a Zip archive available at The latest version as of writing this document is 6.7.0 and can be found here.

Unfortunately the vSAN SDK for Python is currently not available at PyPI, so you cannot install it easily using pip for example. In this document we will see how to package the VMware vSAN Management SDK for Python and have it uploaded to a package index in Artifactory.


First, make sure that you download the latest vSAN SDK for Python from the following link.


Once you download the archive, simply unzip it.


The official vSAN SDK for Python archive contains the following files and directories in version 6.7.0 of the SDK.

$ ls -l vsan-sdk-python
total 8
-rw-rw-r--@    1 mnikolov  staff    2051 Feb 28 19:08 README
drwxr-xr-x@    3 mnikolov  staff      96 Feb 28 19:08 bindings
drwxr-xr-x@ 3519 mnikolov  staff  112608 Feb 28 19:08 docs
drwxr-xr-x@    5 mnikolov  staff     160 Feb 28 19:08 samplecode

In order to convert this to a proper Python package we will do:

  • Move the SDK modules from bindings to the vmware.vsan package
  • The samplecode directory contains sample scripts that you can run. We will include these as part the installed scripts by the package.
  • The docs directory contains the vSAN API reference, which we will include in our source distribution tarball.

The bindings and samplecode directories contain the following files. The docs directory contains the API reference documentation, which contains many files, and that is why it was not included in the output below.

$ tree bindings samplecode

0 directories, 4 files

Our Python modules will reside in the src directory, so let’s create the directory structure now for our packages and modules. Also, make sure to create files in each package directory, so that our package is properly recognized as a Python package.

$ mkdir -p src/vmware/vsan
$ touch src/vmware/
$ touch src/vmware/vsan/

Rename the README file as and optionally provide any details about the repository location of your custom vSAN SDK for Python package.


We will move the and modules to the vmware.vsan package. The and scripts will be installed as scripts from our Python package.

$ mv bindings/ src/vmware/vsan
$ mv samplecode/ src/vmware/vsan
$ mv samplecode/ src/vsanapisamples
$ mv samplecode/ src/vsaniscsisamples

The included sample scripts import the vsanmgmtObjects and vsanapiutils modules, but since we have moved these to the vmware.vsan package, make sure to update the following scripts so that they now import vmware.vsan.vsanmgmtObjects and vmware.vsan.vsanapiutils modules respectively.

  • src/vsanapisamples
  • src/vsaniscsisamples

Let’s also add version of our Python package. Update the src/vmware/vsan/ file and add the corresponding __version__ to it.

$ cat src/vmware/vsan/
__version__ = '6.7.0'

Now, we can create our file, which will drive the packaging and installation process for our package. Since the vSAN SDK for Python depends on pyvmomi we will add it to the list of dependencies below. This is how our file looks like.

import re
import ast

from setuptools import setup, find_packages

_version_re = re.compile(r'__version__\s+=\s+(.*)')

with open('src/vmware/vsan/', 'rb') as f:
    version = str(ast.literal_eval('utf-8')).group(1))

    description='VMware vSAN SDK for Python',
    author='VMware, Inc.',
    maintainer='John Doe',
    package_dir={'': 'src'},
        'Documentation': '',
        'Download': '',
        'pyvmomi >= 6.7.0',

Since we also want our source distribution tarball to ship with the official API reference documentation we will create a template.

$ cat
include README.*
include docs/*

Finally, remove the now empty bindings and samplecode directories.

$ rmdir bindings
$ rmdir samplecode


In order to install the package simply execute the following command.

$ python install

Above command should take care of properly installing any dependencies (e.g. pyvmomi) and afterwards install our vSAN SDK modules. We can confirm that everything has been installed correctly, by checking the output below.

$ pip freeze


The vSAN API Python modules will be installed as:

  • vmware.vsan.vsanmgmtObjects
  • vmware.vsan.vsanapiutils

Sample Scripts

The pyvsan package will also install the following sample scripts.

  • vsanapisamples
  • vsaniscsisamples

After installing pyvsan you can run the included sample scripts.

$ vsanapisamples
usage: vsanapisamples [-h] -s HOST [-o PORT] -u USER [-p PASSWORD]
                      [--cluster CLUSTER]
vsanapisamples: error: the following arguments are required: -s/--host, -u/--user

And the usage info for vsaniscsisamples:

$ vsaniscsisamples
usage: vsaniscsisamples [-h] -s HOST [-o PORT] -u USER [-p PASSWORD]
                        [--cluster CLUSTER]
vsaniscsisamples: error: the following arguments are required: -s/--host, -u/--user


This pyvsan package ships with the official vSAN API Reference.

The following documentation is also worth checking out.

Uploading to a package index

In this section we will see how to upload the vSAN SDK package we’ve created in the previous section to a package index, which in this case would be the internal Artifactory repository.

For more information about PyPI repository support, please refer to the link below.


We will be uploading the package to the internal PyPI repository, called foo-pypi-local. First, make sure that you define the Artifactory repository in your ~/.pypirc. This is how my ~/.pypirc file looks like.

index-servers =

username: username
password: p4ssw0rd

username: foo-deployer
password: p4ssw0rd

Register your package. Make sure to specify the Artifactory repository you’ve defined above.

$ python register --repository pypi-foo

If above command is successful you can now upload your source distribution by executing the following command.

$ python sdist upload --repository pypi-foo

Once you upload the package to Artifactory you should be able to install it by executing the following command.

$ pip install \
        --extra-index \
Written on August 8, 2019