pyspoke
A python library supporting pubsub and remote procedure calls on Linux.
Overview
This package provides a python library for passing JSON messages between processes. Clients publish messages to named channels and subscribe to channels to receive those messages. Each client connects to a single server that acts as the message broker. Features include:
- Hierarchical channel names with support for wildcard subscriptions
- Remote procedure calls built on top of the publish/subscribe capability
- Persistent messages that are recorded by the server and sent to clients that later subscribe to the channel
- Bridging servers so that they and their clients behave like a single network
- Customizable transport protocol - default is TCP sockets
- Asynchronous client/server code using standard asyncio module
- Synchronous wrapper functions for publish and rpc calls
Installation
Requires Python 3.7 or greater
From PyPI
Install using pip:
python3 -m pip install pyspoke
From latest source
First install build dependencies:
python3 -m pip install build
Building the distribution:
git clone https://gitlab.com/samflam/pyspoke.git
cd pyspoke
make
To install, you can pip install the built wheel in dist or simply run
make install
Testing
From the top level, do:
make test
Examples
Basic publisher and subscriber
First we run the server that acts as a message broker, receiving published messages and sending them to subscribed clients:
"Server code"
import asyncio
import spoke
server = spoke.pubsub.server.Server()
try:
asyncio.run(server.run())
except KeyboardInterrupt:
pass
Next we need a subscriber that will listen for messages on the given channel(s) and execute a callback function when a message is received. In this case we listen for messages on the foo channel and just print them out:
"Subscriber"
import asyncio
import spoke
async def handle_foo(msg):
print(f"Got message on foo channel: {msg.body}")
async def main():
client = spoke.pubsub.client.Client()
await client.run()
await client.subscribe("foo", handle_foo)
await spoke.wait()
asyncio.run(main())
Finally we publish a message on the foo channel. This example uses the synchonous wrapper function, which is simpler to use, but must establish a new connection each time it is called:
"Publisher (using simple synchronous call)"
import spoke
spoke.publish("foo", 5)
Connection options
By default, clients assume the server is at localhost:7181; the server binds to 0.0.0.0:7181.
The defaults may be changed:
# server and client-subscriber are configured inside a map, the named argument conn_opts:
server = spoke.pubsub.server.Server(conn_opts = {"host": "localhost", "port": 4444, "reuse": True})
server = spoke.pubsub.server.Server(conn_opts = {"reuse": True})
client = spoke.pubsub.client.Client(conn_opts = {"host": "spoke", "port": 8888})
client = spoke.pubsub.client.Client(conn_opts = {"host": "spoke"})
# the publisher is different; it takes host and port themselves as named arguments:
spoke.publish('world', 'Hello!', host="spoke", port=8888)
spoke.publish('dazai', 'BSD', port=8888)
Command line interface
This package provides serveral command line scripts for common tasks. For help on any of them, run with the flag -h:
spoke-server- runs a server that acts as the message brokerspoke-echo- subscribes to the given channels and prints any messages that it receivesspoke-publish- publish a message on the given channelspoke-call- do a remote procedure call on the given channel and print the resultspoke-bridge- connect two spoke servers so that they and their clients transparently behave like a single network
Metadata
Release files for pyspoke 1.1.2
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 |
|---|---|---|---|---|
| pyspoke-1.1.2.tar.gz | 11.6 kB | Without provenance | Details for pyspoke-1.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyspoke-1.1.2-py3-none-any.whl | Python 3 | none | any | Details for pyspoke-1.1.2-py3-none-any.whl |
Total release size: 27.4 kB
Release files / pyspoke-1.1.2.tar.gz
| Download URL | pyspoke-1.1.2.tar.gz |
|---|---|
| Size | 11.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
120d980b304a12dd10ca662d9dd2f3f7a02b668456f1de57ed853d35d35bdd75
|
|
BLAKE2b-256 checksum How to use checksums |
8fda1bd10f73c10ea8c4d01619691ae447d9db5ad09332d6df4289159650ee9b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.0
|
Release files / pyspoke-1.1.2-py3-none-any.whl
| Download URL | pyspoke-1.1.2-py3-none-any.whl |
|---|---|
| Size | 15.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
45e3c2eb190aba8368067127db2fdf7e87b17df8352856bdeb2abae09971b7ec
|
|
BLAKE2b-256 checksum How to use checksums |
984d4e7aac85746333ba84e048d69ee182ffa9cad2311230b9c35eebca0f7edb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.0
|
Security for pyspoke 1.1.2
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.