Skip to main content

A Non-Blocking Event Driven Applications Framework

Project description

The Python Banyan Framework

The Python Banyan Framework is a lightweight, reactive framework used to create flexible, non-blocking, event driven, asynchronous applications.

Python Banyan comes with full documentation that includes a User's Guide with hands-on examples, as well documentation for the OneGPIO Project that allows you to quickly and easily build reusable GPIO projects for the Arduino, ESP-8266, and Raspberry Pi.

It is being used by Palace Games to concurrently monitor hundreds of real-time sensors and actuators.

  • Based on a network connected Publish/Subscribe model, Banyan components publish user defined protocol messages in the form of Python dictionaries.
  • A Banyan protocol message may contain Numpy data.
  • Applications may reside on a single computer or be distributed across multiple computers without having to change source code.
  • Compatible Banyan Frameworks are available for JavaScript, Ruby, and Java. Components written in any of these languages can interact with components of a differing language without modification.
  • Runs on Python 2 or Python 3 (recommended).

To install, view the full installation instructions.

A Simple Banyan Echo Server:

import sys
from python_banyan.banyan_base import BanyanBase


class EchoServer(BanyanBase):
    """
    This class is a simple Banyan echo server
    """
    def __init__(self, ):

        # initialize the parent
        super(EchoServer, self).__init__(process_name='EchoServer')

        # subscribe to receive 'echo' messages from the client
        self.set_subscriber_topic('echo')

        # wait for messages to arrive
        try:
            self.receive_loop()
        except KeyboardInterrupt:
            self.clean_up()
            sys.exit(0)

    def incoming_message_processing(self, topic, payload):
        """
        Process incoming messages from the client
        :param topic: message topic
        :param payload: message payload
        """
        # republish the message with a topic of reply
        self.publish_payload(payload, 'reply')
        
        # extract the message number from the payload
        print('Message number:', payload['message_number'])

A Simple Banyan Echo Client:

import sys
from python_banyan.banyan_base import BanyanBase


class EchoClient(BanyanBase):
    """
    This is a simple echo client derived from the BanyanBase class. 
    It sends out a series of messages and expects an
    echo reply from the server.
    """

    def __init__(self):

        # initialize the parent
        super(EchoClient, self).__init__(process_name='EchoClient')

        # accept banyan messages with the topic of reply
        self.set_subscriber_topic('reply')

        # sequence number of messages and total number of messages to send
        self.message_number = self.number_of_messages = 10

        # send the first message - make sure that the server is already started
        self.publish_payload({'message_number': self.message_number}, 'echo')

        # get the reply messages
        try:
            self.receive_loop()
        except KeyboardInterrupt:
            self.clean_up()
            sys.exit(0)

    def incoming_message_processing(self, topic, payload):
        """
        Process incoming messages received from the echo client
        :param topic: Message Topic string
        :param payload: Message Data
        """

        # When a message is received and its number is zero, finish up.
        if payload['message_number'] == 0:
            print(str(self.number_of_messages) + ' messages sent and received. ')
            input('Press enter to exit.')
            self.clean_up()
            sys.exit(0)
        # bump the message number and send the message out
        else:
            self.message_number -= 1
            if self.message_number >= 0:
                self.publish_payload({'message_number': self.message_number}, 'echo')


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

python-banyan-3.14.tar.gz (41.8 kB view details)

Uploaded Source

Built Distribution

python_banyan-3.14-py2.py3-none-any.whl (62.9 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file python-banyan-3.14.tar.gz.

File metadata

  • Download URL: python-banyan-3.14.tar.gz
  • Upload date:
  • Size: 41.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.7

File hashes

Hashes for python-banyan-3.14.tar.gz
Algorithm Hash digest
SHA256 fa3e45af4a20ffa0221ac1f583cccccc76d1a3c802518ca0c31e2e54937800bd
MD5 134ddf95a2457680c0dc2740285744b2
BLAKE2b-256 71e9aa4b5d77e03fe7156c202782cd883e92c00949f8c751904f32b359a2cac2

See more details on using hashes here.

File details

Details for the file python_banyan-3.14-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for python_banyan-3.14-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 c8040a5ea6bebf2b530d78996ca6a259299c0d769d6c9cb42c904fdde096383a
MD5 6d40b4b6f0a7a2a739e09b9ba9ff1137
BLAKE2b-256 218a548a601e77bd66ddeaf4917a5661c9ff2c37e0637094a74b2ae9b937f993

See more details on using hashes here.

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