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=Truewhen creating a module to force that module logger toDEBUG. - Pass
logger=<your logger>toModule(...)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.Protocolpyqmh.ProtocolErrorpyqmh.Modulepyqmh.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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c7e0549e0a7ead151a13990de73c947c80b8cab5b98aed5d342d74c0fbb4f8e7
|
|
| MD5 |
8af4347c25cf82bca7724053d545ae45
|
|
| BLAKE2b-256 |
9815a112bf7665ce8d90904831b309d2cd8df72ae36169f4bce446ba366ef02c
|
Provenance
The following attestation bundles were made for pyqmh-0.0.3.tar.gz:
Publisher:
publish-to-pypi.yml on PCLabTools/pyqmh
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyqmh-0.0.3.tar.gz -
Subject digest:
c7e0549e0a7ead151a13990de73c947c80b8cab5b98aed5d342d74c0fbb4f8e7 - Sigstore transparency entry: 1809077733
- Sigstore integration time:
-
Permalink:
PCLabTools/pyqmh@f31bfed3e7476fb159a340bdb3d9001545e2d5b3 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/PCLabTools
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@f31bfed3e7476fb159a340bdb3d9001545e2d5b3 -
Trigger Event:
workflow_dispatch
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
43d8dbda179a815a5af672b80b8193aa53fc852117bc9a548f4affbc2bc6b204
|
|
| MD5 |
c25f33fd224634be83a3c972b97000a8
|
|
| BLAKE2b-256 |
059cc738d120fee299c72d0ea4ce9067d6f872bcc77f0457b4b86beff4f4364f
|
Provenance
The following attestation bundles were made for pyqmh-0.0.3-py3-none-any.whl:
Publisher:
publish-to-pypi.yml on PCLabTools/pyqmh
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyqmh-0.0.3-py3-none-any.whl -
Subject digest:
43d8dbda179a815a5af672b80b8193aa53fc852117bc9a548f4affbc2bc6b204 - Sigstore transparency entry: 1809077737
- Sigstore integration time:
-
Permalink:
PCLabTools/pyqmh@f31bfed3e7476fb159a340bdb3d9001545e2d5b3 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/PCLabTools
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@f31bfed3e7476fb159a340bdb3d9001545e2d5b3 -
Trigger Event:
workflow_dispatch
-
Statement type: