Python Bindings
Purpose
Programmatic access to GuestKit offline disk intelligence — assurance scoring and repair from Python.
When to use it
- Automate doctor / migrate-repair in CI or migration pipelines
- Integrate with h2kvm (
h2kvm.core.guestkit_client) - Custom inspection scripts via the
Guestfshandle
How to get there
- Doc id:
python-bindings - Nav: Interfaces → Python Bindings
- Primary interface:
pip install zyvor-guestkit(PyPI) ormaturin develop --features python-bindings
Operate from Python (v1.1.0+)
pip install zyvor-guestkit(PyPI). For local builds:maturin build --release --features python-bindings.import guestkit.- Assurance:
guestkit.run_doctor("disk.qcow2", target="kvm", explain=True). - Repair (dry-run):
guestkit.run_migrate_repair("disk.qcow2", apply=False). - Repair (apply):
guestkit.run_migrate_repair("disk.qcow2", apply=True). - Inject (optional): pass
inject_json=json.dumps({...})on that same call. Fields:hostname,network_files,users,services,firstboot,cloud_init_user_data,ad_rejoin,license_kms,enable_rdp. Omitted or"null"adds nothing. No CLI flag for this. - Live fix (booted guest):
cmds = guestkit.live_fix_commands()then run them over SSH, orguestkit.run_live_plan(cmds, dry_run=True)on the machine where Python is running. - Low-level inspect:
from guestkit import Guestfs→add_drive_ro→launch→inspect_os. - Empty / fail: Import error → wrong package or missing wheel; launch fail → NBD/sudo; bad
inject_json→ValueError. - Success: Bootability score + fix plan JSON (inject ops use ids
inject-NNN); or distro/hostname from Guestfs handle.
Host needs Linux + qemu-img / losetup / qemu-nbd; mount/repair often need root.
See also: examples/python/assurance_doctor.py