Create Flow

An empty Flow can be created via:

from jina import Flow

f = Flow()

Use a Flow

To use f, always open it as a context manager, just like you open a file. This is considered the best practice in Jina:

with f:


Flow follows a lazy construction pattern: it won’t actually run until you use with to open it.


Once a Flow is open via with, you can send data requests to it. However, you cannot change its construction via .add() any more until it leaves the with context.


The context exits when its inner code is finished. A Flow’s context without inner code will immediately exit. To prevent that, use .block() to suspend the current process.

with f:
    f.block()  # block the current process

Visualize a Flow

from jina import Flow

f = Flow().add().plot('f.svg')

In Jupyter Lab/Notebook, the Flow object is rendered automatically without needing to call plot().