Files
harmoney/README.md
2026-02-22 06:54:06 +00:00

82 lines
1.9 KiB
Markdown

# harmoney [![DOI](https://zenodo.org/badge/942561957.svg)](https://doi.org/10.5281/zenodo.14965939)
Distributed Function Caller Framework for Python
## Installation:
`pip install harmoney`
Dependencies:
- websockets
- fastapi
- uvicorn
- pydantic
## Usage:
Requires 3 scripts: Client, Router and Runner
### 1. Router
The Router will mediate load balancing and connection handling between the function runners and callers, so this should start first. One port must to facilitate the communication.
This example starts the router on IP `192.168.0.110` and port `7732`.
```python
from harmoney.router import startRouter
startRouter("0.0.0.0", 7732)
```
### 2. Runner
Runner exposes the function calls and contains all the heavy compute logic. Below code connects one instance of runner to the router.
```python
from harmoney.runner import startRunner
def customFunction(arg1: int, arg2: str) -> str:
return arg2*arg1
funcs = {"custFn": customFunction}
startRunner(funcs, "192.168.0.110", 7732)
```
Functions must return objects that are pickleable. `None` or no return statement is valid.
### 3. Client
Client requests the function - argument combinations to run on runners.
```python
from harmoney.client import Client
cli = Client("192.168.0.110", 7732)
retVal = cli.runSingle("custFn", arg1=10, arg2="arst") # run only this combination
print(retVal)
cli.addCall("custFn", arg1=123, arg2="qwf") # add this combination to queue
cli.addCall("custFn", arg1=321, arg2="ars") # add this combination to queue
res = cli.runAllCalls() # send queued combs at a time.
print(res) # Print all the results
```
Return values from `runALlCalls` are in the order of their function combination in the queue.
TODO:
- [ ] Error catching, keeping the connection to the broker
- [ ] Error info should return to the client
- [ ] Remove dependency on fastapi and requests, move to completely to websockets
---
~ A Grammer Society Project.