{"id":24494,"library":"qmp","title":"QEMU Machine Protocol (QMP) Client","description":"qmp is a Python client library for the QEMU Machine Protocol (QMP), used to interact with QEMU virtual machines programmatically. The current version is 1.1.0, supported on Python >=3.6. The library is mature but sees infrequent releases.","status":"active","version":"1.1.0","language":"python","source_language":"en","source_url":"https://github.com/qemu/qmp","tags":["QEMU","QMP","virtualization","monitor","protocol"],"install":[{"cmd":"pip install qmp","lang":"bash","label":"Latest release from PyPI"}],"dependencies":[],"imports":[{"note":"In v1.x, the class is directly exposed at the package level. Old imports from .qmp submodule may fail.","wrong":"from qmp.qmp import QEMUMonitorProtocol","symbol":"QEMUMonitorProtocol","correct":"from qmp import QEMUMonitorProtocol"}],"quickstart":{"code":"from qmp import QEMUMonitorProtocol\n\n# Connect to QEMU over a Unix socket\nsock_path = '/tmp/qemu.sock'  # or os.environ.get('QEMU_SOCK', '/tmp/qemu.sock')\ntry:\n    qmp = QEMUMonitorProtocol(sock_path)\n    qmp.connect()\n    # Send a QMP command\n    result = qmp.command('query-status')\n    print(result)\nfinally:\n    qmp.close()","lang":"python","description":"Connect to a running QEMU instance via a Unix socket and execute a QMP command."},"warnings":[{"fix":"Use Python >=3.6.","message":"Python 3.6 is the minimum required version; Python 2 is not supported. Using with Python <3.6 will cause syntax errors.","severity":"breaking","affected_versions":"<1.0? (pre-1.0 versions may have supported Python 2)"},{"fix":"Use connect() with a timeout (e.g., via socket timeout) or implement async connect; qmp does not natively support timeouts.","message":"The connect() method blocks until the connection is established. If QEMU is not ready or the socket path is wrong, it may hang indefinitely.","severity":"gotcha","affected_versions":"all"},{"fix":"Always handle 'error' key in response dictionary, or use qmp.command() which raises QMPError on failure (but only for QMP-level errors).","message":"Commands expecting a 'return' key in the response may fail if the QMP event is a 'QMP' greeting or an error. Always check the response for success.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Run `pip install qmp` and use `from qmp import QEMUMonitorProtocol`.","cause":"The library is not installed or the wrong package name is used (e.g., trying `import qemu`).","error":"ModuleNotFoundError: No module named 'qmp'"},{"fix":"Use `from qmp import QEMUMonitorProtocol` directly.","cause":"Trying to import from an old submodule path (e.g., `from qmp.qmp import QEMUMonitorProtocol`).","error":"AttributeError: module 'qmp' has no attribute 'QEMUMonitorProtocol'"},{"fix":"Verify the socket path (e.g., check QEMU startup logs) and ensure QEMU is started with '-qmp unix:/tmp/qemu.sock,server,nowait'.","cause":"The QEMU socket path does not exist or QEMU is not running.","error":"qmp.QMPError: [Errno 111] Connection refused"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}