Basic PubSub for python app.
Project description
xpubsub
A basic pubsub module for communications within an app.
This project is an excercise to help me develop skills relating to:
You would probably be better off using PyPubSub
Interface
from xpubsub import PubSub
pub = PubSub()
HashOrList = Union[Hashable, list[Hashable]]
pub.add(topic_list: HashOrList, callback: Callable):
pub.remove(topic_list: HashOrList, callback: Callable):
pub.send(topic_list: HashOrList, message: Any):
Example: example.py
from xpubsub import PubSub
pub = PubSub()
def hello(topic, message):
print(topic, message)
def goodbye(topic, msg):
print("😭", topic, msg)
pub.add("hi", hello)
pub.add(["SHTF!", "go away"], goodbye)
pub.send("hi", "👋😍")
pub.send("SHTF!", "Head For The Hills!")
pub.send("go away", "its over")
pub.remove("go away", goodbye)
pub.send("go away", "nothing happens") # this does nothing!
Output
hi 👋😍
😭 SHTF! Head For The Hills!
😭 go away its over
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
xpubsub-0.2.0.tar.gz
(3.3 kB
view details)
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 xpubsub-0.2.0.tar.gz.
File metadata
- Download URL: xpubsub-0.2.0.tar.gz
- Upload date:
- Size: 3.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.2.2 CPython/3.11.0 Linux/5.15.0-53-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b672f26cfd9d2ca7f7d353b78702c50d07983c415db8c5fabdde87d17e3f2e7c
|
|
| MD5 |
d4a116f2843e284f61d3ada56fa98648
|
|
| BLAKE2b-256 |
9bb7643454b1324961d419283153bf95ae2994ed49d79836b4c9d343df99a188
|
File details
Details for the file xpubsub-0.2.0-py3-none-any.whl.
File metadata
- Download URL: xpubsub-0.2.0-py3-none-any.whl
- Upload date:
- Size: 3.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.2.2 CPython/3.11.0 Linux/5.15.0-53-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d6044ae1c91037c0a1a8f3a38b2f6a36c3109ac9cf15d3f428a6c666f1c5f003
|
|
| MD5 |
05b29d49d22e5f3d07dba18b54fa443f
|
|
| BLAKE2b-256 |
0fc646adfc1b390d196df9386490f1d77f2e001baf8b9677856cc7391c7b152c
|