🗞️ EasyPubSub
EasyPubSub is a simple wrapper around PyZMQ that provides an easy interface to the PubSub (Publish-Subscribe) functionality of ZeroMQ.
In PubSub, a publisher publishes a message to a topic and a subscriber subscribes to that topic and receives the message. In EasyPubSub, publishers and subscribers connect to each other via a proxy, which acts as intermediary between them. For more information regarding PubSub, see Wikipedia.
Get started
EasyPubSub can be installed via pip:
pip install easypubsub
Proxy
Now let's start a proxy (code from examples/example_proxy.py):
import time
from easypubsub.proxy import Proxy
PUBLISHERS_ADDRESS = "tcp://127.0.0.1:5555"
SUBSCRIBERS_ADDRESS = "tcp://127.0.0.1:5556"
proxy = Proxy(PUBLISHERS_ADDRESS, SUBSCRIBERS_ADDRESS)
proxy.launch()
try:
while True:
time.sleep(0.1)
except KeyboardInterrupt:
proxy.stop()
This starts a proxy (stoppable with CTRL-C) that allows publishers to publish messages to PUBLISHERS_ADDRESS and subscribers to subscribe to topics on SUBSCRIBERS_ADDRESS. By using a proxy, publishers and subscribers can connect to each other without having to know each other's addresses.
Publisher
Let's create a publisher that every ten seconds announces one random number (code from examples/example_publisher.py):
import random
import time
from easypubsub.publisher import Publisher
PUBLISHERS_ADDRESS = "tcp://127.0.0.1:5555"
PUBLISH_INTERVAL = 10 # seconds.
publisher = Publisher("lottery", PUBLISHERS_ADDRESS, default_topic="winning_number")
try:
while True:
publisher.publish(message=random.randint(1, 100))
time.sleep(PUBLISH_INTERVAL)
except KeyboardInterrupt:
pass
Subscriber
Now we can create a subscriber that prints the winning number every time it receives one (code from examples/example_subscriber.py):
import time
from easypubsub.subscriber import Subscriber
SUBSCRIBERS_ADDRESS = "tcp://127.0.0.1:5556"
subscriber = Subscriber("lottery_player", SUBSCRIBERS_ADDRESS)
try:
while True:
result = subscriber.receive()
if len(result) > 0:
print("Received:")
for topic, message in result:
print(f"{topic}: {message}")
else:
# No message received.
time.sleep(1.0)
except KeyboardInterrupt:
pass
There can be many publishers and subscribers connected to the same proxy, try starting a few of them with different names!
For more detailed information, please visit the documentation.
Metadata
Release files for easypubsub 0.4.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| easypubsub-0.4.3.tar.gz | 9.1 kB | Without provenance | Details for easypubsub-0.4.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| easypubsub-0.4.3-py3-none-any.whl | Python 3 | none | any | Details for easypubsub-0.4.3-py3-none-any.whl |
Total release size: 17.5 kB
Release files / easypubsub-0.4.3.tar.gz
| Download URL | easypubsub-0.4.3.tar.gz |
|---|---|
| Size | 9.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f9928654d518403427a04cbc83a5a4d8f71f1f812a12b04d042d9214b8a8009d
|
|
BLAKE2b-256 checksum How to use checksums |
df5f0a6c457aae17163d7448528600725d5b87dc10de4f6b875fd69fcb2af813
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.16
|
Release files / easypubsub-0.4.3-py3-none-any.whl
| Download URL | easypubsub-0.4.3-py3-none-any.whl |
|---|---|
| Size | 8.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
870832620da711ea27f90410cd3fe4b5e88340161e6842f50cfd7bfebab6151e
|
|
BLAKE2b-256 checksum How to use checksums |
3f779ece155ccf87a60ad166695282e60d176c6fe3bdcbb8065cfaea064a16e6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.16
|
Security for easypubsub 0.4.3
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.