This module allows you to distribute heavy-workload functions to the Golem Network. This is a sister project to gfaas.
Currently, the only supported version of Python is version 3.8. Additionally, since this package is
not yet released on pypi, you will need to manually install its dependencies
pip3 install yapapi
The usage is pretty straightforward. In your main Python module, e.g. main.py, import pfaas and
annotate some heavy-workload function to be distributed on the Golem Network like so
from pfaas import remote_fn
import asyncio
@remote_fn()
def hello(msg: str) -> str:
return msg.upper()
async def main(msg: str):
resp = await hello(msg)
print(f"in={msg}, out={resp}")
if __name__ == '__main__':
loop = asyncio.get_event_loop()
task = loop.create_task(main("hey there, yagna!"))
try:
asyncio.get_event_loop().run_until_complete(task)
except (Exception, KeyboardInterrupt) as e:
print(e)
task.cancel()
asyncio.get_event_loop().run_until_complete(asyncio.sleep(0.3))Now simply run as usual
python3 main.py
When you annotate a function with pfaas.remote_fn attribute, it gets expanded into a
full-fledged async function. So for instance, the following function
from pfaas import remote_fn
@remote_fn()
def hello(input: str) -> strexpands into
async def hello(input: str) -> strTherefore, it is important to remember that you need to run the function in an async block.
You can currently set the following configuration parameters directly via pfaas.remote_fn
decorator:
- (maximum) budget in NGNT (defaults to 100):
@remote_fn(budget=100.0)
def hello(input: str) -> str- timeout as
timedelta(defaults to 10 minutes):
@remote_fn(timeout=timedelta(minutes=10))
def hello(input: str) -> str- subnet tag (defaults to "devnet-alpha.2"):
@remote_fn(subnet="devnet-alpha.2")
def hello(input: str) -> strOf course, nobody stops you from setting any number of parameters at once
@remote_fn(budget=10.0, subnet="my_subnet")
def hello(input: str) -> strIt is well known that prior to launching our app on some distributed network of nodes, it
is convenient to first test the app locally in search of bugs and errors. This is also
possible with pfaas. In order to force your app to run locally, simply pass run_local = True
as argument to pfaas.remote_fn decorator
from pfaas import remote_fn
@remote_fn(run_local=True)
def hello(msg: str) -> strA couple illustrative examples of how to use this module can be found in the examples/
directory.