Skip to main content

A lightweight third-party broadcast 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

Setup

pip install broadcast-service

Usage

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

from broadcast_service import broadcast_service

def handle_msg(params):
    print(params)

if __name__ == '__main__':
    info = 'This is very important msg'

    # listen topic
    broadcast_service.subscribe('Test', handle_msg)

    # publish broadcast
    broadcast_service.publish('Test', info)

You can also add more params or no params when you publish thr broadcast.

from broadcast_service import broadcast_service

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

    # listen topic
    broadcast_service.subscribe('Test', handle_msg)

    # publish broadcast
    broadcast_service.publish('Test', info, info2)
from broadcast_service import broadcast_service

def handle_msg():
    print('handle_msg callback')

if __name__ == '__main__':
    # listen topic
    broadcast_service.subscribe('Test', handle_msg)

    # publish broadcast
    broadcast_service.publish('Test')

Actually, you can see more example in example and tests.

TODO

  • optimize documents and show more examples.
  • optimize the syntax expression of broadcast-service
  • provide more test cases

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.1.7.tar.gz (8.0 kB view hashes)

Uploaded Source

Supported by

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