Giter Club home page Giter Club logo

pfaas's Introduction

pfaas

Function-as-a-Service on top of Golem Network in Python

This module allows you to distribute heavy-workload functions to the Golem Network. This is a sister project to gfaas.

⚠️ Disclaimer: Use with extra care as this package is highly experimental. ⚠️

Quick start

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

Notes about pfaas.remote_fn

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) -> str

expands into

async def hello(input: str) -> str

Therefore, it is important to remember that you need to run the function in an async block.

Specifying Golem's configuration parameters

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) -> str

Of course, nobody stops you from setting any number of parameters at once

@remote_fn(budget=10.0, subnet="my_subnet")
def hello(input: str) -> str

Notes on running your app locally (for testing)

It 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) -> str

Examples

A couple illustrative examples of how to use this module can be found in the examples/ directory.

pfaas's People

Contributors

kubkon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.