Giter Site home page Giter Site logo

rill's Introduction

rill

Build Status

rill is a lightweight python framework for Flow-based Programming built on gevent. With it, you can create networks of worker components, each operating on their own green thread, which push and pull streams of data packets through named ports.

The internals are heavily inspired by JavaFBP, which is maintained by the author of the seminal book on the subject, while the public API draws from concise and expressive frameworks like click and flask.

Installing

git clone https://github.com/chadrik/rill
cd rill
pip install .

Example

The following example takes the string 'Hello Goodbye World', splits it into words, then filters out words that start with 'G' and joins the words back into a line.

from rill import inport, outport, component
from rill.engine.network import Network

@component
@inport("IN")
@outport("OUT")
def Output(IN, OUT):
    for p in IN:
        print(repr(p.get_contents()))
        OUT.send(p)


@component
@inport("IN", type=str)
@inport("TEST", type=str)
@outport("ACC", type=str)
@outport("REJ", type=str)
def StartsWith(IN, TEST, ACC, REJ):
    test_str = TEST.receive_once()

    for p in IN.iter_packets():
        s = p.get_contents()
        if s.startswith(test_str):
            ACC.send(p)
        else:
            REJ.send(p)

@component
@inport("IN", type=str)
@inport("MEASURE", type=int)
@outport("OUT", type=str)
def WordsToLine(IN, MEASURE, OUT):
    measure = MEASURE.receive_once()

    line = ""
    for word in IN.iter_contents():
        if measure and (len(line) + 1 + len(word)) > measure:
            OUT.send(line)
            # restart line
            line = word
        else:
            if line:
                line += " "
            line += word
    if line:
        # remainder
        OUT.send(line)

@component
@outport("OUT", type=str)
@inport("IN", type=str)
def LineToWords(IN, OUT):
    for line in IN.iter_contents():
        words = line.split()
        for word in words:
            OUT.send(word)


net = Network()
net.add_component("LineToWords", LineToWords, IN="HeLLo Goodbye World")
net.add_component("StartsWith", StartsWith, TEST='G')
net.add_component("WordsToLine", WordsToLine)
dis = net.add_component("Output", Output)

net.connect("LineToWords.OUT", "StartsWith.IN")
net.connect("StartsWith.REJ", "WordsToLine.IN")
net.connect("WordsToLine.OUT", "Output.IN")
net.go()

Using the UI

rill can be started as a server, known as a runtime, that can communicate with clients such as UIs and other runtimes using the FBP Network Protocol. Currently, the primary UI that supports this open protocol is noflo-ui. There are still some incompatibilities between rill and noflo-ui that are being worked out, but if you want to give it a try, read on.

Installing

npm install -g n
npm install -g bower
npm install -g grunt-cli
sudo n 4.1

mkdir noflo
cd noflo

git clone https://github.com/noflo/noflo-ui
cd noflo-ui
git checkout 40acbb4d92f178837f161b7c15f2dde2a5bfa4bc
npm install
# running bower before grunt prompts to resolve a dependency conflict which otherwise causes grunt to fail
bower install
grunt build
python -m SimpleHTTPServer 8000

Running

  1. Open your browser to http://localhost:8000/
  2. Log in using your github account. Go to "Settings" and copy your "User Identifier"
  3. In a fresh shell, cd into the root of the rill repo.
  4. Start the rill runtime.
    python -m rill.runtime --user-id <USER_ID>
    
  5. Back in the browser, create a new project in NoFlo selecting the rill runtime
  6. Green arrows should appear on the top-right menu, right before ws:\\localhost:3569

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.