0 0

Tintri Python SDK Released

A Python SDK (PySDK) for Tintri REST APIs is now available. See below for code comparisons and a link to our GitHub.


As part of Tintri's cloud initiative, I'm pleased to announce that a Python SDK (PySDK) for Tintri REST APIs is now available on GitHub. Tintri's PySDK is a thin layer over its REST APIs with the following features:

PySDK versus tintri_1.1.py

If you have been using tintri_1.1.py library from GitHub, you will find the PySDK an improvement. The image below shows the difference.

Python SDK Differences

If you do a code comparison, the difference between using tintri_1.1.py and the PySDK, I think you'll want to use the PySDK. The first code snippet is using tintri_1.1.py. Note that the URL needs to be specified and the results need to be placed into a dictionary.

    # Get a list of VMs, but only return a page size
    url = "/v310/vm"
    r = tintri.api_get(server_name, url, session_id)

    vm_paginated_result = r.json()
    num_vms = int(vm_paginated_result["filteredTotal"])
    if num_vms == 0:
        raise tintri.TintriRequestsException("No VMs present")

    print_info(str(num_vms) + " VMs present")


But with the PySDK, a get_vms method is called instead of a generic get, and the results are returned in an object with typed properties. Also the session_id is not needed because the PySDK object keeps track of it.

    # Get VMs with page size filter.
    vms = tintri.get_vms(filters = vm_filter_spec)
    num_vms = vms.filteredTotal
    if num_vms == 0:
        raise TintriServerError(0, cause="No VMs present")

    print_info(str(num_vms) + " VMs present")


The PySDK has a method call for each REST API. There are more code examples in the examples directory.

In this update example of the difference, the first code snippet shows how to set the VMstore maintenance mode.

    if (new_is_enabled):
        # Create the maintenance mode DTO for enabling.
        new_maint_mode_info = \
            {"typeId": "com.tintri.api.rest.v310.dto.domain.beans.hardware.ApplianceMaintenanceMode",
             "endTime"   : add_6_str,
             "isEnabled" : new_is_enabled,
             "startTime" : now_str
        # Create the maintenance mode DTO for disabling.
        new_maint_mode_info = \
            {"typeId": "com.tintri.api.rest.v310.dto.domain.beans.hardware.ApplianceMaintenanceMode",
             "isEnabled" : new_is_enabled,

    # Create the Appliance object wit the new ApplianceDns DTO.
    new_appliance = \
        {"typeId": "com.tintri.api.rest.v310.dto.domain.Appliance",
         "maintenanceMode": new_maint_mode_info

    # Create the Request object with the Appliance DTO.
    request = \
        {"typeId": "com.tintri.api.rest.v310.dto.Request",
         "objectsWithNewValues": [new_appliance],
         "propertiesToBeUpdated": ["maintenanceMode"]

    # Invoke the appliance API to set the maintenance mode.
    r = tintri.api_put(server_name, url, request, session_id)


Note how the typeId needs to be specified for every DTO above, but the PySDK takes care of that for you in the Python object. Python dictionaries are used with the old library, while properties of objects are used in PySDK.

    # Create the appliance maintenance mode object.
    new_maint_mode_info = ApplianceMaintenanceMode()

    if (new_is_enabled):
        # Add attributes for enabling.
        new_maint_mode_info.isEnabled =  new_is_enabled
        new_maint_mode_info.endTime =  add_6_str
        new_maint_mode_info.startTime =  now_str
        # Add attributes for disabling.
        new_maint_mode_info.isEnabled =  new_is_enabled

    # Call the update appliance method to set the maintenance mode.
    server.update_appliance(None, "default", maintenance_mode = new_maint_mode_info)


The advantages of coding using the PySDK, are:

  • less coding
  • focus on job at hand, and not on Tintri API details
  • better code readability

PySDK versus PowerShell

So how does the PySDK compare with the PowerShell Toolkit 3.0?

Python SDK vs Tintri PowerShell Toolkit

As you can see from the above image, PowerShell is a thicker library. The PowerShell Toolkit provides convenience cmdlets; for example, PowerShell has Enable-TintriMaintenanceMode and Disable-TintriMaintenanceMode, whereas the PySDK uses update_appliance method. See the code example set_maintenance_mode.py for details. Also the PowerShell toolkit can accept hypervisor objects, while PySDK cannot.

PowerShell is great for Windows clients, whereas Python is can be used for non-Windows clients as well. Python is now even more with the PySDK.

How to Use

To use the PySDK, follow the README file and install the wheel. A short tutorial is included in the documentation. My future Python coding examples will be using the PySDK.

- Rick -

You can follow Rick at Twitter @rick_ehrhart.

Rick Ehrhart / Nov 02, 2016

Rick Ehrhart is Tintri’s Developer Evangelist with a strong software development background focusing on APIs. Rick has assisted many companies with API integrations including VMware, NetApp, HP, ...more