Skip to main content

qemu.qmp: QEMU Monitor Protocol Library

Welcome! qemu.qmp is a QEMU Monitor Protocol (“QMP”) library written in Python, using asyncio. It is used to send QMP messages to running QEMU emulators. It requires Python 3.6+ and has no mandatory dependencies.

This library can be used to communicate with QEMU emulators, the QEMU Guest Agent (QGA), the QEMU Storage Daemon (QSD), or any other utility or application that speaks QMP.

This library makes as few assumptions as possible about the actual version or what type of endpoint it will be communicating with; i.e. this library does not contain command definitions and does not seek to be an SDK or a replacement for tools like libvirt or virsh. It is “simply” the protocol (QMP) and not the vocabulary (QAPI). It is up to the library user (you!) to know which commands and arguments you want to send.

Who is this library for?

It is firstly for developers of QEMU themselves; as the test infrastructure of QEMU itself needs a convenient and scriptable interface for testing QEMU. This library was split out of the QEMU source tree in order to share a reference version of a QMP library that was usable both within and outside of the QEMU source tree.

Second, it’s for those who are developing for QEMU by adding new architectures, devices, or functionality; as well as targeting those who are developing with QEMU, i.e. developers working on integrating QEMU features into other projects such as libvirt, KubeVirt, Kata Containers, etc. Occasionally, using existing virtual-machine (VM) management stacks that integrate QEMU+KVM can make developing, testing, and debugging features difficult. In these cases, having more ‘raw’ access to QEMU is beneficial. This library is for you.

Lastly, it’s for power users who already use QEMU directly without the aid of libvirt because they require the raw control and power this affords them.

Who isn’t this library for?

It is not designed for anyone looking for a turn-key solution for VM management. QEMU is a low-level component that resembles a particularly impressive Swiss Army knife. This library does not manage that complexity and is largely “VM-ignorant”. It’s not a replacement for projects like libvirt, virt-manager, GNOME Boxes, etc.

Installing

This package can be installed from PyPI with pip:

> pip3 install qemu.qmp

Usage

Launch QEMU with a monitor, e.g.:

> qemu-system-x86_64 -qmp unix:qmp.sock,server=on,wait=off

Then, at its simplest, script-style usage looks like this:

import asyncio
from qemu.qmp import QMPClient

async def main():
    qmp = QMPClient('my-vm-nickname')
    await qmp.connect('qmp.sock')

    res = await qmp.execute('query-status')
    print(f"VM status: {res['status']}")

    await qmp.disconnect()

asyncio.run(main())

The above script will connect to the UNIX socket located at qmp.sock, query the VM’s runstate, then print it out to the terminal:

> python3 example.py
VM status: running

For more complex usages, especially those that make full advantage of monitoring asynchronous events, refer to the online documentation or type import qemu.qmp; help(qemu.qmp) in your Python terminal of choice.

Contributing

Contributions are quite welcome! Please file bugs using the GitLab issue tracker. This project will accept GitLab merge requests, but due to the close association with the QEMU project, there are some additional guidelines:

  1. Please use the “Signed-off-by” tag in your commit messages. See https://wiki.linuxfoundation.org/dco for more information on this requirement.

  2. This repository won’t squash merge requests into a single commit on pull; each commit should seek to be self-contained (within reason).

  3. Owing to the above, each commit sent as part of a merge request should not introduce any temporary regressions, even if fixed later in the same merge request. This is done to preserve bisectability.

  4. Please associate every merge request with at least one GitLab issue. This helps with generating Changelog text and staying organized. Thank you 🙇

Developing

Optional packages necessary for running code quality analysis for this package can be installed with the optional dependency group “devel”: pip install qemu.qmp[devel].

make develop can be used to install this package in editable mode (to the current environment) and bring in testing dependencies in one command.

make check can be used to run the available tests. Consult make help for other targets and tests that make sense for different occasions.

Before submitting a pull request, consider running make check-tox && make check-pipenv locally to spot any issues that will cause the CI to fail. These checks use their own virtual environments and won’t pollute your working space.

Stability and Versioning

This package uses a major.minor.micro SemVer versioning, with the following additional semantics during the alpha/beta period (Major version 0):

This package treats 0.0.z versions as “alpha” versions. Each micro version update may change the API incompatibly. Early users are advised to pin against explicit versions, but check for updates often.

A planned 0.1.z version will introduce the first “beta”, whereafter each micro update will be backwards compatible, but each minor update will not be. The first beta version will be released after legacy.py is removed, and the API is tentatively “stable”.

Thereafter, normal SemVer / PEP440 rules will apply; micro updates will always be bugfixes, and minor updates will be reserved for backwards compatible feature changes.

Changelog

0.0.1 (2022-07-20)

  • Initial public release. (API is still subject to change!)

Metadata

Release files for qemu.qmp 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for qemu.qmp 0.0.1
File Size Uploaded Provenance Actions
qemu.qmp-0.0.1.tar.gz 89.9 kB Without provenance Details for qemu.qmp-0.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for qemu.qmp 0.0.1
File Interpreter ABI Platform Actions
qemu.qmp-0.0.1-py3-none-any.whl Python 3 none any Details for qemu.qmp-0.0.1-py3-none-any.whl

Total release size: 159.3 kB

Release files / qemu.qmp-0.0.1.tar.gz

Download URL qemu.qmp-0.0.1.tar.gz
Size 89.9 kB
Tags Source
SHA-256 checksum
How to use checksums
a6a81be2484653232ca1eb7089f717299d08d06af0df561cd441afbbabf7ef64
BLAKE2b-256 checksum
How to use checksums
fd550c08d766804b9b7d765f563c6f4cecf204fa0ff54a3f425936e8d7251351
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.13

Release files / qemu.qmp-0.0.1-py3-none-any.whl

Download URL qemu.qmp-0.0.1-py3-none-any.whl
Size 69.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
43d43b79cb718f4d0b00fbdccbff68e3e307793a5eef2932f1d6c4fff52a1e06
BLAKE2b-256 checksum
How to use checksums
b28638f906fea9993a160f295cfd341643079ffbd20005fbd90739eecc3eceec
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.13

Security for qemu.qmp 0.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page