Type Hints
Announcements SDK

pyVmomi supports code auto-complete with type hints

Beta Version of Type Hint Auto completion is available from pyVmomi

Type hints are introduced in Python 3.5 via PEP 484, which allows to check Python code for type conflicts before execution. Popular Integrated Development Environments (IDE) leverages this for the code auto completion.

We are happy to announce pyVmomi supports type hints auto completion. They can speed up your coding process by providing better auto-complete suggestions, and they can catch errors before your code even runs.
Below example demonstrates the pyVmomi auto completion feature usage in building complex VirtualMachineCloneSpec and VirtualMachineRelocateSpec constructs for a cloneVM() Task. For this example we used Visual Studio(VS) Code IDE .

Fig 1: cloneSpec() Type Hints. They are useful to understand all possible properties of clone VM Specifications and their types
Fig 2: Hint types, powerOn=boolean (True/False) determines whether the new clone VirtualMachine should be powered on after creation.

The type hint supports are also dependent on the IDE specific constructs. We recommend to read your IDE documentation to fully utilise this feature.

Video: VS Code IDE pyVmomi Type Hints Usage

In conclusion, type hints are a powerful tool for Python programmers. So next time you’re writing code using pyVmomi, consider using type hints to make your life easier. It will definitely help in speeding up vSphere automation tasks. Also, it could avoid frequent referencing of API documentation guides in application development.

Note: We are releasing this beta version in order to gather feedback from our users and it will improve over new releases. We encourage users to test this feature in your favourite IDEs and report any bugs or issues they encounter.

Credits to our Cloud Infrastructure BU Software Engineers – Daniel Draganov, Kamen Mazdrashki and Stefan Hristov for providing this great capability.


Leave a Reply

Your email address will not be published. Required fields are marked *