<htmlxmlns="http://www.w3.org/1999/xhtml"><head><metahttp-equiv="Content-Type"content="text/html; charset=ISO-8859-1"/><linkrel="stylesheet"type="text/css"href="libvirt.css"/><linkrel="SHORTCUT ICON"href="/32favicon.png"/><title>Binding for Python</title></head><body><divid="container"><divid="intro"><divid="adjustments"></div><divid="pageHeader"></div><divid="content2"><h1class="style1">Binding for Python</h1><p>Libvirt comes with direct support for the Python language (just
make sure you installed the libvirt-python package if not compiling
from sources). Also note that Daniel Berrange provides <ahref="http://search.cpan.org/~danberr/Sys-Virt-0.1.0/">bindings for
Perl</a> and Richard Jones supplies <ahref="http://et.redhat.com/~rjones/ocaml-libvirt/">bindings for
OCaml</a> too.</p><p>The Python binding should be complete and are mostly automatically
(virDomainPtr domain, unsigned long memory);</code></p><p>become</p><p><code>virConn::numOfDomains(self)</code></p><p><code>virDomain::setMaxMemory(self, memory)</code></p><p>This process is fully automated, you can get a summary of the conversion
in the file libvirtclass.txt present in the python dir or in the docs.There
is a couple of function who don't map directly to their C counterparts due to
specificities in their argument conversions:</p><ul><li><code><ahref="html/libvirt-libvirt.html#virConnectListDomains">virConnectListDomains</a></code>
is replaced by <code>virDomain::listDomainsID(self)</code> which returns
a list of the integer ID for the currently running domains</li>
print dom0.<spanstyle="color: #FF0080; background-color: #FFFFFF">info</span>()</pre><p>There is not much to comment about it, it really is a straight mapping
from the C API, the only points to notice are:</p><ul><li>the import of the module called <code><spanstyle="color: #0071FF; background-color: #FFFFFF">libvirt</span></code></li>
<li>getting a connection to the hypervisor, in that case using the
openReadOnly function allows the code to execute as a normal user.</li>