Using libguestfs from Python*

Create handle — Inspect — Modify — Shutdown

import guestfs

input = "disk.img"

g = guestfs.GuestFS ()

g.add_drive_opts (input,
                  format = "raw",
                  readonly = 0)

g.launch ()

* For more examples: http://libguestfs.org/guestfs-python.3.html
or man guestfs-python