Registry / devops / libvirt-python

libvirt-python

JSON →
library12.4.0pypypiunverified

The `libvirt-python` library provides a Pythonic binding to the C API of libvirt, the open-source virtualization management library. It allows Python applications to manage virtual machines, storage, and networking on various hypervisors like KVM, QEMU, and Xen. Currently at version 12.2.0, it generally tracks the libvirt C library's release cycle, typically seeing multiple updates per year.

pip install libvirt-python
INSTALL
IMPORT
SIG · LIBVIRT-PYTHON
L
libvirt-python
devopspythonv12.4.0
Install
Import
Disk
Pass rate
0/ 10
Env Coverage0 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v? · pip install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
build_error
glibc
py 3.103.920 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

libvirt
import libvirt
The binding module itself is named `libvirt`.

Connects to the local QEMU/KVM hypervisor, prints its hostname and libvirt version, then closes the connection. This demonstrates basic connection and resource management.

import libvirt import sys # Connect to the default QEMU/KVM hypervisor. # 'qemu:///system' requires appropriate permissions (e.g., user in 'libvirt' group or root). # For user-session hypervisor, try 'qemu:///session'. try: conn = libvirt.open("qemu:///system") if conn is None: print('Failed to open connection to qemu:///system', file=sys.stderr) sys.exit(1) except libvirt.libvirtError as e: print(f'Failed to open connection: {e}', file=sys.stderr) sys.exit(1) print(f"Successfully connected to libvirt. Hypervisor: {conn.getHostname()}") # Example: Get and print libvirt version print(f"Libvirt version: {conn.getVersion()}") # Always close the connection conn.close()
Debug
Known issues
gotchaThe `libvirt-python` package is a binding to the `libvirt` C library. You must have the `libvirt` C library (and often its development headers) installed on your system for `libvirt-python` to work. Installing just the Python package is insufficient.
fix
On Debian/Ubuntu: `sudo apt install libvirt-dev`. On RHEL/Fedora: `sudo dnf install libvirt-devel`. Ensure the `libvirtd` service is running.
affects: All versions
gotchaConnecting to hypervisors like `qemu:///system` often requires elevated privileges (e.g., running as root or having your user account in the `libvirt` UNIX group). Connection failures due to permissions are common.
fix
Add your user to the `libvirt` group: `sudo usermod -a -G libvirt $USER` (then log out and back in). Alternatively, connect to `qemu:///session` for user-level virtualization or run your script with `sudo` (use with caution).
affects: All versions
deprecated`libvirt-python` versions 4.x and above (released after 2018) have dropped support for Python 2. The current version only supports Python 3.
fix
Ensure you are using Python 3.6 or newer. The `libvirt-python` PyPI package specifies `requires_python: >=3.6`.
affects: <=3.x for Python 2 support; >=4.0 for Python 3 only
gotchaError handling in `libvirt-python` is done via `libvirt.libvirtError` exceptions. Many operations will raise this exception on failure, requiring robust `try...except` blocks.
fix
Wrap `libvirt` calls in `try...except libvirt.libvirtError as e:` to catch and handle API errors gracefully.
affects: All versions
Upgrade
Version history
12.4.0latest on PyPI · released Jun 1, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
10 hits · last 30 days
node
10
Resources