Parallels Python API Concepts
Parallels Python API is a wrapper of the C API described earlier in this guide. While it is based on the same essential principles as the C API, there are some notable differences. They are summarized below.
-
Handles are not directly visible in the Python API. Instead, Python classes are used. You don't obtain a handle in Python, you instantiate a class.
-
Instead of calling a C function passing a handle to it, you instantiate a Python class and call a method of that class.
-
Memory management is automatic. This means that you don't have to free a handle (destroy an object) when it is no longer needed.
-
Many C functions are mapped to Python class properties with "get/set" capability, thus eliminating the need to have two separate functions for every read/write operation.
-
No callbacks! Callback functionality does not exist in the Parallels Python API. This means a few things. First, it is impossible to receive asynchronous method results via callbacks, which essentially means that these methods are not truly asynchronous in the Python API. Second, you cannot receive system event notifications in Python. Finally, you cannot automatically receive periodic performance reports (you can still obtain the reports via synchronous calls).
-
Asynchronous operations have a built-in
wait()
method support (in the C API, it is used to call asynchronous functions synchronously). In the Python API, you can call an asynchronous method normally and let your program continue. As soon as you attempt to access an object containing the results of the asynchronous job, the
wait()
method will be invoked automatically. If at that time the corresponding asynchronous job is still running in the background, your program execution will be suspended until the job finishes. If needed, you can use
wait()
with an asynchronous method itself at the time of invocation or at a later time.
-
Error handling is implemented using exceptions.
-
Python sequences and iterators are used extensively providing much easier access to list results, such as a list of virtual machines, list of devices, etc.
-
Strings are handled as objects (not as char arrays compared to C), which makes it much easier to work with strings as input and output parameters.
Please send us your feedback on this help page