Flow

The Flow ties Executors together into a processing pipeline to perform a bigger task, like indexing or querying a dataset. Documents “flow” through the created pipeline and are processed by Executors. Flow also provides synchronization mechanisms to manage dependencies between executors and their order.

A Flow object has the following common methods:

Group Description
Construct Flow .add(), .needs()
Run Flow with context manager
Visualize Flow .plot()
Send Request .post()
Control .block()

Minimum working example

from jina import Flow, Document, Executor, requests


class MyExecutor(Executor):

    @requests(on='/bar')
    def foo(self, docs, **kwargs):
        print(docs)


f = Flow().add(name='myexec1', uses=MyExecutor)

with f:
    f.post(on='/bar', inputs=Document(), on_done=print)

Server:

from jina import Flow, Executor, requests


class MyExecutor(Executor):

    @requests(on='/bar')
    def foo(self, docs, **kwargs):
        print(docs)


f = Flow(port_expose=12345).add(name='myexec1', uses=MyExecutor)

with f:
    f.block()

Client:

from jina import Client, Document

c = Client(port=12345)
c.post(on='/bar', inputs=Document(), on_done=print)

my.yml:

jtype: Flow
executors:
  - name: myexec1
    uses: MyExecutor
from jina import Flow, Document

f = Flow.load_config('my.yml')

with f:
    f.post(on='/bar', inputs=Document(), on_done=print)

See Also

Document, Executor, and Flow are the three fundamental concepts in Jina.

  • Document is the basic data type in Jina;

  • Executor is how Jina processes Documents;

  • Flow is how Jina streamlines and scales Executors.