broadcast-service
A powerful python broadcast library. You can easily construct a Broadcast pattern/Publish subscriber pattern through this library.
Features
- A publishing subscriber pattern can be built with a very simple syntax
- Support different application scenarios, such as asynchronous and synchronous
- Provide different syntax writing modes for lambda, callback functions, decorators, etc
- A callback function listens on multiple subscriptions
- Provide publisher dispatch callback manage
Quick Start
Setup
pip install broadcast-service
Usage
There is an easy demo to show how to use broadcast-service.
from broadcast_service import broadcast_service
# callback of decorator
@broadcast_service.on_listen('my_topic')
def handle_decorator_msg(params):
print(f"handle_decorator_msg receive params: {params}")
if __name__ == '__main__':
info = 'This is very important msg'
# publish broadcast
broadcast_service.publish('my_topic', info)
-
You can use
publish, emit, broadcastto send your topic msg and uselisten, on, subscribeto listen your topic msg. -
You can also add more arguments or no argument when you publish thr broadcast.
from broadcast_service import broadcast_service
# subscribe topic
@broadcast_service.on_listen(['my_topic'])
def handle_msg(info, info2):
print(info)
print(info2)
if __name__ == '__main__':
info = 'This is very important msg'
info2 = 'This is also a very important msg.'
# publish broadcast
broadcast_service.publish('my_topic', info, info2)
from broadcast_service import broadcast_service
# subscribe topic
@broadcast_service.on_listen(['my_topic'])
def handle_msg():
print('handle_msg callback')
if __name__ == '__main__':
# publish broadcast
broadcast_service.publish('Test')
You can use config to make publisher callback If you want.
from broadcast_service import broadcast_service
@broadcast_service.on_listen("topic")
def handle_subscriber_callback():
print("handle_subscriber_callback")
def handle_publisher_callback(*args):
print("handle_publisher_callback")
if __name__ == '__main__':
broadcast_service.config(
num_of_executions=5,
callback=handle_publisher_callback,
enable_final_return=True,
interval=0.1
).publish("topic")
Moreover, you can see more example in document.
TODO
- optimize documents and show more examples.
optimize the syntax expression of broadcast-service- provide more test cases
- provide the ability to subscribe the topic and callback once
- support for fuzzy subscriptions
the publisher of the topic can provide a return value- optimize usage in class ('self' params problem)
- build observer mode
provide publisher callback when all subscriber have completed callback
Contribution
If you want to contribute to this project, you can submit pr or issue. I am glad to see more people involved and optimize it.
Metadata
Release files for broadcast-service 2.1.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 | Provenance | Actions |
|---|---|---|---|---|
| broadcast_service-2.1.0.tar.gz | 12.9 kB | Without provenance | Details for broadcast_service-2.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| broadcast_service-2.1.0-py3-none-any.whl | Python 3 | none | any | Details for broadcast_service-2.1.0-py3-none-any.whl |
Total release size: 30.0 kB
Release files / broadcast_service-2.1.0.tar.gz
| Download URL | broadcast_service-2.1.0.tar.gz |
|---|---|
| Size | 12.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7210f6fe17a9cb206d13cba7a11e443f95fb1904b7001f10a0273d61f1cd9eca
|
|
BLAKE2b-256 checksum How to use checksums |
1617c267994135cfd26dd460c93105ffe37592f59c33c872787d4acf1bc1760c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.17
|
Release files / broadcast_service-2.1.0-py3-none-any.whl
| Download URL | broadcast_service-2.1.0-py3-none-any.whl |
|---|---|
| Size | 17.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
72810f45b01afccd46f1a373d1c580bc79e862c924de23af20e9eda863d16c27
|
|
BLAKE2b-256 checksum How to use checksums |
bb13d9683802227a2f396988146cb7aa7ccd12d226b20a5ba4c6f570e9b482c8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.17
|
Security for broadcast-service 2.1.0
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.