Skip to main content

A lightweight third-party broadcast/pubsub library

Project description

broadcast-service

A lightweight python broadcast library. You can easily construct a Broadcast pattern/Publish subscriber pattern through this library.

github stars

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

Quick Start

Setup

pip install broadcast-service

Usage

There is a easy demo to show how to use broadcast-service.

from broadcast_service import broadcast_service


# callback of common method
def handle_msg(params):
    print(f"handle_msg receive params: {params}")


# 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'

    # subscribe topic
    broadcast_service.subscribe('my_topic', handle_msg)

    # publish broadcast
    broadcast_service.publish('my_topic', info)
  • You can use publish, emit, broadcast to send your topic msg and use listen, on, subscribe to 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 decorator to subscirbe your

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
  • privide the ability to subscribe the topic and callback once
  • Support for fuzzy subscriptions

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

broadcast_service-1.3.2.tar.gz (9.7 kB view details)

Uploaded Source

Built Distribution

broadcast_service-1.3.2-py3.10.egg (15.5 kB view details)

Uploaded Egg

File details

Details for the file broadcast_service-1.3.2.tar.gz.

File metadata

  • Download URL: broadcast_service-1.3.2.tar.gz
  • Upload date:
  • Size: 9.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.8

File hashes

Hashes for broadcast_service-1.3.2.tar.gz
Algorithm Hash digest
SHA256 69b3fbec5381853de6acfeab394a672d9ca6823fa7520e43595758b296b33eee
MD5 0f0a36f98decc812a1051175f1e97a2c
BLAKE2b-256 28d26b31969448b34bdf37e9d9be768a423a688825e86a487b57d331ef7f991d

See more details on using hashes here.

File details

Details for the file broadcast_service-1.3.2-py3.10.egg.

File metadata

  • Download URL: broadcast_service-1.3.2-py3.10.egg
  • Upload date:
  • Size: 15.5 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.8

File hashes

Hashes for broadcast_service-1.3.2-py3.10.egg
Algorithm Hash digest
SHA256 bfc788c19321b997986db43683666c14117b59a609b6fa7033bdb6325bffc1a0
MD5 93db840053562db891cacf9e7c231c12
BLAKE2b-256 78b66745c1a93c79858f42004ed3cc2a0efb90057a0c306da08d061a76305b2f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page