PyMQ
PyMQ is a simple message-oriented middleware library for implementing Python IPC across machine boundaries. The API enables different styles of remoting via Pub/Sub, Queues, and synchronous RPC. It is an excellent choice for Python projects that need robust IPC without the overhead of more complex frameworks like Celery or gRPC.
With PyMQ, developers can integrate Python applications running on different machines in a loosely coupled way over existing transport mechanisms. PyMQ currently provides a Redis backend, a POSIX IPC backend for single-machine IPC, and an in-memory backend for testing. The API is extensible and other transports can be plugged in.
Using PyMQ
Install
Starting from pymq 0.5, all providers are separated into setuptools extras. If you want to use the redis backend, then run
pip install pymq[redis]
Available providers:
pymq[redis]Redis providerpymq[ipc]Linux IPC providerpymq[full]install all providers
Initialize PyMQ
The core module manages a global eventbus instance that provides the remoting primitives. The default Redis
implementation uses an event loop over a pubsub object. The global eventbus is initialized via pymq.init and by
passing a provider factory.
import pymq
from pymq.provider.redis import RedisConfig
# starts a new thread with a Redis event loop
pymq.init(RedisConfig())
# main application control loop
pymq.shutdown()
This will create an eventbus instance on top of a local Redis server.
Pub/Sub
Pub/Sub allows asynchronous event-based communication. Event classes are used to transport state and identify channels.
import pymq
# common code
class MyEvent:
pass
# subscribe code
@pymq.subscriber
def on_event(event: MyEvent):
print('event received')
# publisher code
pymq.publish(MyEvent())
Queues
Queues are straight forward, as they are compatible to the Python queue.Queue specification.
import pymq
queue = pymq.queue('my_queue')
queue.put('obj')
print(queue.get()) # outputs 'obj'
RPC
Server code
import pymq
@pymq.remote('product_remote')
def product(a: int, b: int) -> int: # pymq relies on type hints for marshalling
return a * b
Client code
import pymq
product = pymq.stub('product_remote')
product(2, 4) # 8
With a shared code-base, methods can also be exposed and called by passing the callable. For example,
import pymq
# common code
class Remote:
def echo(self, param) -> None:
return 'echo: ' + param
# server
obj = Remote()
pymq.expose(obj.echo)
# client
echo = pymq.stub(Remote.echo)
echo('pymq') # "echo: pymq"
Multi-RPC
If there are multiple providers of the same object, then a stub can be initialized with multi=True to get a list of
results. It may be useful to use a timeout in this case.
remote = pymq.stub('remote_method', multi=True, timeout=2)
result = remote() # result will be a list containing the results of all invocations of available remote objects
You can find an example for multi-RPC in the examples/metrics-rpc directory.
Providers
SimpleEventBusused for testing and rudimentary single-thread dispatchingRedisEventBusworks across network and process boundaries but requires a running redis instanceIpcEventBususesposix_ipcmessage queues as event loops and maintains a tree of topic subscriptions in/run/shm. Useful for eventing across process boundaries without an additional server component.
Compatibility
Python 3.8+
Known Limitations
- JSON serialization relies heavily on type hints. Sending complex types without type hints will cause type errors.
- There is currently no support for polymorphism with JSON serialization
- Pattern-based topic matching does not work for the in-memory eventbus or the IPC event bus
- You can only have a limited number of Queues when using the IPC provider, as the kernel limits the number of file descriptors per process
- Subscriptions by foreign components to RPC channels will cause issues in multi-call scenarios
- Using the
pymqsingleton in multiprocessing scenarios may not work as expected because the module holds a Thread in a global variable. A workaround is to re-start the bus by callingshutdown()andinit()in the forked Process. - IPC provider only works for Linux
Background
Originally part of the Symmetry project, was extracted as a standalone library.
Metadata
Release files for pymq 0.7.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pymq-0.7.0.tar.gz | 34.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pymq-0.7.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 63.4 kB
Release files / pymq-0.7.0.tar.gz
| Download URL | pymq-0.7.0.tar.gz |
|---|---|
| Size | 34.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a5968d511656671e559eee88c0d6cadf324153324e5cd5ea8445f1bf37274c3d
|
|
BLAKE2b-256 checksum How to use checksums |
6e4e0da66bc3dab820b4a2c877bfa4ecf16e8b5caa0a20f4802699a006e0599b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 1, 2026.
Transparency logRelease files / pymq-0.7.0-py3-none-any.whl
| Download URL | pymq-0.7.0-py3-none-any.whl |
|---|---|
| Size | 28.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cd1a86bd4ce9a4e7a0454242b9ee9f30218219b34cb4306515bc90d19c6ba663
|
|
BLAKE2b-256 checksum How to use checksums |
4931265fd0c76a8957f60afd77a5a1b1d98daaae3fd4dfd3930c2537ac12baa2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 1, 2026.
Transparency log