Package: daffi
DaffiDaffi facilitates remote computing and enables remote procedure calls between multiple endpoints.
It supports many-to-many relationships between endpoints, allowing for seamless communication between distributed systems.
The library abstracts the complexities of remote computing and provides a user-friendly interface for initiating and managing remote procedure calls.
It also offers various features such as fault tolerance, load balancing, streaming and security, to ensure reliable and secure communication between endpoints.Daffi comprises three primary classes:Global- Initialization entrypoint. OnceGlobalobject is initialized application can respond on remote requests and trigger remote callbacks itself.Callback- Represents a collection of methods encapsulated in a class inherited fromCallbackor a standalone function decorated with thecallbackdecorator. These functions/methods can be triggered from another process.Fetcher- Represents a collection of methods encapsulated in a class inherited fromFetcheror a standalone function decorated with thefetcherdecorator. These functions/methods serve as triggers for the corresponding callbacks defined in another process.DocumentationView full documentation at:https://600apples.github.io/dafi/Basic exampleYou need to create two filesshopping_service.pyandshopper.pyshopping_service.py- represents a set of remote callbacks that can be triggered by a client application.shopper.py- represents shopping_service client (fetcher)Class based approachshopping_service.py:importloggingfromdaffiimportGlobalfromdaffi.registryimportCallbacklogging.basicConfig(level=logging.INFO)classShoppingService(Callback):auto_init=True# class is automatically initialized, eliminating the need to manually create an object.def__post_init__(self):self.shopping_list=[]defget_items(self):"""Return all items that are currently present in shopping list"""returnself.shopping_listdefadd_item(self,item):"""Add new item to shopping list"""self.shopping_list.append(item)defclear_items(self):"""Clear shopping list"""self.shopping_list.clear()if__name__=='__main__':Global(init_controller=True,host="localhost",port=8888).join()(This script is complete, it should run "as is")shopper.py:importloggingfromdaffiimportGlobalfromdaffi.decoratorsimportaliasfromdaffi.registryimportFetcherlogging.basicConfig(level=logging.INFO)classShopper(Fetcher):"""Note: Functions without a body are treated as proxies for remote callbacks.All arguments provided to this function will be sent to the remote service as-is."""defget_items(self):"""Return all items that are currently present in shopping list."""passdefadd_item(self,item):"""Add new item to shopping list."""passdefclear_items(self):"""Clear shopping list"""pass@alias("add_item")defadd_many_items(self,*items):"""Alias for `add_item` callback.This function shows streaming capabilities for transferring data from one service to another."""foriteminitems:yielditemif__name__=='__main__':g=Global(host="localhost",port=8888)shopper=Shopper()items=shopper.get_items()print(items)shopper.add_item("orange")items=shopper.get_items()print(items)shopper.add_many_items("bread","cheese")items=shopper.get_items()print(items)shopper.clear_items()items=shopper.get_items()print(items)g.stop()(This script is complete, it should run "as is")To check the full example, you need to execute two scripts in separate terminalspython3shopping_service.py

...
INFO2023-03-2719:49:45|controller[0x91adb83e]|Controllerhasbeenstartedsuccessfully.Processidentificator:'0x91adb83e'.Connectioninfo:tcp:[host'[::]',port:8888]INFO2023-03-2719:49:45|node[0x91adb83e]|Nodehasbeenstartedsuccessfully.Processidentificator:'0x91adb83e'.Connectioninfo:tcp:[host'[::]',port:8888]python3shopper.py

...
INFO2023-03-2719:53:15|node[0xd7e5d488]|Nodehasbeenstartedsuccessfully.Processidentificator:'0xd7e5d488'.Connectioninfo:tcp:[host'[::]',port:8888][]['orange']['orange','bread','cheese'][]INFO2023-03-2719:53:15|node[0xd7e5d488]|Nodestopped.Decorators base approachshopping_service.py:importloggingfromdaffiimportGlobalfromdaffi.decoratorsimportcallbacklogging.basicConfig(level=logging.INFO)shopping_list=[]@callbackdefget_items():"""Return all items that are currently present in shopping list"""returnshopping_list@callbackdefadd_item(item):"""Add new item to shopping list"""shopping_list.append(item)@callbackdefclear_items():"""Clear shopping list"""shopping_list.clear()if__name__=='__main__':Global(init_controller=True,host="localhost",port=8888).join()(This script is complete, it should run "as is")shopper.py:"""Note: Functions without a body are treated as proxies for remote callbacks.All arguments provided to this function will be sent to the remote service as-is."""importloggingfromdaffiimportGlobalfromdaffi.decoratorsimportalias,fetcherlogging.basicConfig(level=logging.INFO)@fetcherdefget_items():"""Return all items that are currently present in shopping list."""pass@fetcherdefadd_item(item):"""Add new item to shopping list."""pass@fetcherdefclear_items():"""Add new item to shopping list."""pass@alias("add_item")@fetcherdefadd_many_items(*items):"""Alias for `add_item` callback.This function shows streaming capabilities for transferring data from one service to another."""foriteminitems:yielditemif__name__=='__main__':g=Global(host="localhost",port=8888)items=get_items()print(items)add_item("orange")items=get_items()print(items)add_many_items("bread","cheese")items=get_items()print(items)clear_items()items=get_items()print(items)g.stop()(This script is complete, it should run "as is")To check the full example, you need to execute two scripts in separate terminalspython3shopping_service.py

...
INFO2023-03-2720:31:27|controller[0xbac16ef4]|Controllerhasbeenstartedsuccessfully.Processidentificator:'0xbac16ef4'.Connectioninfo:tcp:[host'[::]',port:8888]INFO2023-03-2720:31:27|node[0xbac16ef4]|Nodehasbeenstartedsuccessfully.Processidentificator:'0xbac16ef4'.Connectioninfo:tcp:[host'[::]',port:8888]python3shopper.py

...
INFO2023-03-2720:31:43|node[0xb9e10444]|Nodehasbeenstartedsuccessfully.Processidentificator:'0xb9e10444'.Connectioninfo:tcp:[host'[::]',port:8888][]['orange']['orange','bread','cheese'][]INFO2023-03-2720:31:44|node[0xb9e10444]|Nodestopped.