Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Daffi 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:
View full documentation at: https://600apples.github.io/dafi/
You need to create two files shopping_service.py
and shopper.py
shopping_service.py
- represents a set of remote callbacks that can be triggered by a client application.
shopper.py
- represents shopping_service client (fetcher)
shopping_service.py
:
import logging
from daffi import Global
from daffi.registry import Callback
logging.basicConfig(level=logging.INFO)
class ShoppingService(Callback):
auto_init = True # class is automatically initialized, eliminating the need to manually create an object.
def __post_init__(self):
self.shopping_list = []
def get_items(self):
"""Return all items that are currently present in shopping list"""
return self.shopping_list
def add_item(self, item):
"""Add new item to shopping list"""
self.shopping_list.append(item)
def clear_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
:
import logging
from daffi import Global
from daffi.decorators import alias
from daffi.registry import Fetcher
logging.basicConfig(level=logging.INFO)
class Shopper(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.
"""
def get_items(self):
"""Return all items that are currently present in shopping list."""
pass
def add_item(self, item):
"""Add new item to shopping list."""
pass
def clear_items(self):
"""Clear shopping list"""
pass
@alias("add_item")
def add_many_items(self, *items):
"""
Alias for `add_item` callback.
This function shows streaming capabilities for transferring data from one service to another.
"""
for item in items:
yield item
if __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 terminals
python3 shopping_service.py
...
INFO 2023-03-27 19:49:45 | controller[0x91adb83e] | Controller has been started successfully. Process identificator: '0x91adb83e'. Connection info: tcp: [ host '[::]', port: 8888 ]
INFO 2023-03-27 19:49:45 | node[0x91adb83e] | Node has been started successfully. Process identificator: '0x91adb83e'. Connection info: tcp: [ host '[::]', port: 8888 ]
python3 shopper.py
...
INFO 2023-03-27 19:53:15 | node[0xd7e5d488] | Node has been started successfully. Process identificator: '0xd7e5d488'. Connection info: tcp: [ host '[::]', port: 8888 ]
[]
['orange']
['orange', 'bread', 'cheese']
[]
INFO 2023-03-27 19:53:15 | node[0xd7e5d488] | Node stopped.
shopping_service.py
:
import logging
from daffi import Global
from daffi.decorators import callback
logging.basicConfig(level=logging.INFO)
shopping_list = []
@callback
def get_items():
"""Return all items that are currently present in shopping list"""
return shopping_list
@callback
def add_item(item):
"""Add new item to shopping list"""
shopping_list.append(item)
@callback
def clear_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.
"""
import logging
from daffi import Global
from daffi.decorators import alias, fetcher
logging.basicConfig(level=logging.INFO)
@fetcher
def get_items():
"""Return all items that are currently present in shopping list."""
pass
@fetcher
def add_item(item):
"""Add new item to shopping list."""
pass
@fetcher
def clear_items():
"""Add new item to shopping list."""
pass
@alias("add_item")
@fetcher
def add_many_items(*items):
"""
Alias for `add_item` callback.
This function shows streaming capabilities for transferring data from one service to another.
"""
for item in items:
yield item
if __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 terminals
python3 shopping_service.py
...
INFO 2023-03-27 20:31:27 | controller[0xbac16ef4] | Controller has been started successfully. Process identificator: '0xbac16ef4'. Connection info: tcp: [ host '[::]', port: 8888 ]
INFO 2023-03-27 20:31:27 | node[0xbac16ef4] | Node has been started successfully. Process identificator: '0xbac16ef4'. Connection info: tcp: [ host '[::]', port: 8888 ]
python3 shopper.py
...
INFO 2023-03-27 20:31:43 | node[0xb9e10444] | Node has been started successfully. Process identificator: '0xb9e10444'. Connection info: tcp: [ host '[::]', port: 8888 ]
[]
['orange']
['orange', 'bread', 'cheese']
[]
INFO 2023-03-27 20:31:44 | node[0xb9e10444] | Node stopped.
FAQs
Daffi is fast, simple and lightweight library for inter process communication
We found that daffi demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.