Skip to main content

Python Queued Message Handler (QMH)

Project description

pyqmh

Python Queued Message Handler (pyqmh) is a lightweight in-process messaging framework for coordinating modules with request/response, actions, and broadcast messaging.

Installation

From PyPI:

pip install pyqmh

From source:

pip install .

Quick Start

from pyqmh import Module, Protocol


class Worker(Module):
 def handle_message(self, message):
  if message.command == "ping":
   self.protocol.send_response(message, "pong")
   return False
  return super().handle_message(message)


protocol = Protocol(main_address="main")
worker = Worker("worker", protocol)

response = protocol.send_request("worker", "ping", timeout=1.0)
print(response)

protocol.send_action("worker", "shutdown")

Debugging and Logging

Module uses Python logging instead of ad-hoc debug prints. Each module instance gets a logger named by address (for example: pyqmh.module.worker).

Enable debug output

import logging

logging.basicConfig(
 level=logging.INFO,
 format="%(asctime)s %(levelname)s %(name)s - %(message)s",
)

Worker example with custom debug logs

from pyqmh import Module, Protocol


class Worker(Module):
 def handle_message(self, message):
  self.logger.debug(
   "Received command=%s payload=%r source=%s",
   message.command,
   message.payload,
   "yes" if message.source is not None else "no",
  )

  if message.command == "ping":
   self.logger.debug("Responding with pong")
   self.protocol.send_response(message, "pong")
   return False

  return super().handle_message(message)


protocol = Protocol(main_address="main")
worker = Worker("worker", protocol, debug=True)

response = protocol.send_request("worker", "ping", payload={"id": 123}, timeout=1.0)
print(response)

protocol.send_action("worker", "shutdown")

Tips:

  • Pass debug=True when creating a module to force that module logger to DEBUG.
  • Pass logger=<your logger> to Module(...) to attach modules to your app logger hierarchy.
  • In child classes, use self.logger.debug(...) for diagnostic output.

Public API

The package exports the following symbols at top-level:

  • pyqmh.Protocol
  • pyqmh.ProtocolError
  • pyqmh.Module
  • pyqmh.Message

Testing

Install the package with test dependencies:

pip install -e ".[test]"

Run the full test suite:

pytest tests/ -v

Run tests with coverage report:

pytest tests/ --cov=src/pyqmh --cov-report=html

Run only unit tests or integration tests:

pytest tests/ -m unit      # unit tests only
pytest tests/ -m integration  # integration tests only

Test Coverage

The test suite includes:

  • 81 tests across Message, Protocol, and Module classes
  • 100% code coverage of the package
  • Unit tests for core functionality (instantiation, equality, hashing, message handling)
  • Integration tests for multi-module communication and broadcast messaging
  • Thread-safe test cleanup to ensure clean pytest exit without requiring keyboard interrupt

Test files:

  • tests/test_message.py - Message class tests (creation, equality, hashing, payloads)
  • tests/test_protocol.py - Protocol class tests (registration, message sending/receiving, requests/responses)
  • tests/test_module.py - Module class tests (threading, message handling, background tasks, cleanup)

Development Build

Build source and wheel distributions:

python -m build

Validate metadata and artifacts:

twine check dist/*

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyqmh-0.0.3.tar.gz (14.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyqmh-0.0.3-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file pyqmh-0.0.3.tar.gz.

File metadata

  • Download URL: pyqmh-0.0.3.tar.gz
  • Upload date:
  • Size: 14.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pyqmh-0.0.3.tar.gz
Algorithm Hash digest
SHA256 c7e0549e0a7ead151a13990de73c947c80b8cab5b98aed5d342d74c0fbb4f8e7
MD5 8af4347c25cf82bca7724053d545ae45
BLAKE2b-256 9815a112bf7665ce8d90904831b309d2cd8df72ae36169f4bce446ba366ef02c

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyqmh-0.0.3.tar.gz:

Publisher: publish-to-pypi.yml on PCLabTools/pyqmh

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyqmh-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: pyqmh-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 8.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pyqmh-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 43d8dbda179a815a5af672b80b8193aa53fc852117bc9a548f4affbc2bc6b204
MD5 c25f33fd224634be83a3c972b97000a8
BLAKE2b-256 059cc738d120fee299c72d0ea4ce9067d6f872bcc77f0457b4b86beff4f4364f

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyqmh-0.0.3-py3-none-any.whl:

Publisher: publish-to-pypi.yml on PCLabTools/pyqmh

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page