skip to Main Content

Tintri Blog

Tintri Python SDK Released

November 2, 2016

As part of Tintri’s cloud initiative, we are 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:

  • auto pagination
  • automatic re-login after time-out
  • includes all v310.51 APIs which maps to Tintri OS 4.2 and Tintri Global Center (TGC) 3.0
  • works with Python 2.7
  • object oriented

PySDK versus

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

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 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.

If you do a code comparison, the difference between using and the PySDK, I think you’ll want to use the PySDK. The first code snippet is using 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": "",
             "endTime"   : add_6_str,
             "isEnabled" : new_is_enabled,
             "startTime" : now_str
        # Create the maintenance mode DTO for disabling.
        new_maint_mode_info = 
            {"typeId": "",
             "isEnabled" : new_is_enabled,

    # Create the Appliance object wit the new ApplianceDns DTO.
    new_appliance = 
        {"typeId": "",
         "maintenanceMode": new_maint_mode_info

    # Create the Request object with the Appliance DTO.
    request = 
        {"typeId": "",
         "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

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

Back To Top
This site is registered on as a development site.