Quick Start

This tutorial assumes you are starting fresh. You are to read the User Guide to learn how to do more complicated and useful things.

Tethys is created to manage the data flow among your systems. How to start your first data stream is provided below.

Let’s start with “Hello World”!

  1. Install Tethys

# installing from PyPI
pip install tethys
  1. Create network

# network.py

from tethys.core.networks import ZeroNetwork
from tethys.core.nodes import ZeroNode
from tethys.core.pipes import ZeroPipe

CACHE = []


def hello_world_op(data_packet):

    CACHE.append(data_packet)

    if len(CACHE) == 2:
        return ' '.join(CACHE)


def get_network():

    hello_world_node = ZeroNode(
        hello_world_op,
        _id="hello_world_id"
    )

    print_node = ZeroNode(print)

    return ZeroNetwork(
        [
            ZeroPipe(
                ZeroNode.IN, hello_world_node
            ),
            ZeroPipe(
                hello_world_node, print_node
            ),
            ZeroPipe(
                "hello_world_id", ZeroNode.OUT
            ),
        ]
    )
  1. Process data

# run in python terminal
python3
from network import get_network
from tethys.core.stations import ZeroStation
from tethys.core.sessions import ZeroSession

net = get_network()

with ZeroSession(net) as session:
    session.send(["Hello", "World", "Something else"], many=True)

ZeroStation(
    sessions=[session],
    stream_waiting_timeout=0,
    monitor_checks_delay=0.5,
).start()
  1. Check results

out_pipe = next(net.output_pipes)
out_stream = out_pipe.get_stream(session)

with out_stream:
    out_stream_gen = out_stream.read()
    key, message = next(out_stream_gen)
    print(message)

Full example is here: gs0_hello_world.py.

You can visit Github for further examples.