jina.clients

Module wrapping the Client of Jina.

class jina.clients.Client(args)[source]

Bases: jina.clients.base.BaseClient

A simple Python client for connecting to the gRPC gateway.

It manages the asyncio event loop internally, so all interfaces are synchronous from the outside.

train(inputs, on_done=None, on_error=None, on_always=None, **kwargs)[source]

Issue ‘train’ request to the Flow.

Parameters
  • inputs (Union[Document, Iterable[Union[~DocumentContentType, ~DocumentSourceType, Document, Tuple[~DocumentContentType, ~DocumentContentType], Tuple[~DocumentSourceType, ~DocumentSourceType]]], AsyncIterable[Union[~DocumentContentType, ~DocumentSourceType, Document, Tuple[~DocumentContentType, ~DocumentContentType], Tuple[~DocumentSourceType, ~DocumentSourceType]]], Callable[…, Union[Document, Iterable[Union[~DocumentContentType, ~DocumentSourceType, Document, Tuple[~DocumentContentType, ~DocumentContentType], Tuple[~DocumentSourceType, ~DocumentSourceType]]], AsyncIterable[Union[~DocumentContentType, ~DocumentSourceType, Document, Tuple[~DocumentContentType, ~DocumentContentType], Tuple[~DocumentSourceType, ~DocumentSourceType]]]]]]) – input data which can be an Iterable, a function which returns an Iterable, or a single Document

  • on_done (Optional[Callable[…, None]]) – the function to be called when the Request object is resolved.

  • on_error (Optional[Callable[…, None]]) – the function to be called when the Request object is rejected.

  • on_always (Optional[Callable[…, None]]) – the function to be called when the Request object is is either resolved or rejected.

  • kwargs – additional parameters

Return type

None

Returns

None

search(inputs, on_done=None, on_error=None, on_always=None, **kwargs)[source]

Issue ‘search’ request to the Flow.

Parameters
  • inputs (Union[Document, Iterable[Union[~DocumentContentType, ~DocumentSourceType, Document, Tuple[~DocumentContentType, ~DocumentContentType], Tuple[~DocumentSourceType, ~DocumentSourceType]]], AsyncIterable[Union[~DocumentContentType, ~DocumentSourceType, Document, Tuple[~DocumentContentType, ~DocumentContentType], Tuple[~DocumentSourceType, ~DocumentSourceType]]], Callable[…, Union[Document, Iterable[Union[~DocumentContentType, ~DocumentSourceType, Document, Tuple[~DocumentContentType, ~DocumentContentType], Tuple[~DocumentSourceType, ~DocumentSourceType]]], AsyncIterable[Union[~DocumentContentType, ~DocumentSourceType, Document, Tuple[~DocumentContentType, ~DocumentContentType], Tuple[~DocumentSourceType, ~DocumentSourceType]]]]]]) – input data which can be an Iterable, a function which returns an Iterable, or a single Document

  • on_done (Optional[Callable[…, None]]) – the function to be called when the Request object is resolved.

  • on_error (Optional[Callable[…, None]]) – the function to be called when the Request object is rejected.

  • on_always (Optional[Callable[…, None]]) – the function to be called when the Request object is is either resolved or rejected.

  • kwargs – additional parameters

Return type

None

Returns

None

index(inputs, on_done=None, on_error=None, on_always=None, **kwargs)[source]

Issue ‘index’ request to the Flow.

Parameters
  • inputs (Union[Document, Iterable[Union[~DocumentContentType, ~DocumentSourceType, Document, Tuple[~DocumentContentType, ~DocumentContentType], Tuple[~DocumentSourceType, ~DocumentSourceType]]], AsyncIterable[Union[~DocumentContentType, ~DocumentSourceType, Document, Tuple[~DocumentContentType, ~DocumentContentType], Tuple[~DocumentSourceType, ~DocumentSourceType]]], Callable[…, Union[Document, Iterable[Union[~DocumentContentType, ~DocumentSourceType, Document, Tuple[~DocumentContentType, ~DocumentContentType], Tuple[~DocumentSourceType, ~DocumentSourceType]]], AsyncIterable[Union[~DocumentContentType, ~DocumentSourceType, Document, Tuple[~DocumentContentType, ~DocumentContentType], Tuple[~DocumentSourceType, ~DocumentSourceType]]]]]]) – input data which can be an Iterable, a function which returns an Iterable, or a single Document

  • on_done (Optional[Callable[…, None]]) – the function to be called when the Request object is resolved.

  • on_error (Optional[Callable[…, None]]) – the function to be called when the Request object is rejected.

  • on_always (Optional[Callable[…, None]]) – the function to be called when the Request object is is either resolved or rejected.

  • kwargs – additional parameters

Return type

None

Returns

None

update(inputs, on_done=None, on_error=None, on_always=None, **kwargs)[source]

Issue ‘update’ request to the Flow.

Parameters
  • inputs (Union[Document, Iterable[Union[~DocumentContentType, ~DocumentSourceType, Document, Tuple[~DocumentContentType, ~DocumentContentType], Tuple[~DocumentSourceType, ~DocumentSourceType]]], AsyncIterable[Union[~DocumentContentType, ~DocumentSourceType, Document, Tuple[~DocumentContentType, ~DocumentContentType], Tuple[~DocumentSourceType, ~DocumentSourceType]]], Callable[…, Union[Document, Iterable[Union[~DocumentContentType, ~DocumentSourceType, Document, Tuple[~DocumentContentType, ~DocumentContentType], Tuple[~DocumentSourceType, ~DocumentSourceType]]], AsyncIterable[Union[~DocumentContentType, ~DocumentSourceType, Document, Tuple[~DocumentContentType, ~DocumentContentType], Tuple[~DocumentSourceType, ~DocumentSourceType]]]]]]) – input data which can be an Iterable, a function which returns an Iterable, or a single Document

  • on_done (Optional[Callable[…, None]]) – the function to be called when the Request object is resolved.

  • on_error (Optional[Callable[…, None]]) – the function to be called when the Request object is rejected.

  • on_always (Optional[Callable[…, None]]) – the function to be called when the Request object is is either resolved or rejected.

  • kwargs – additional parameters

Return type

None

Returns

None

delete(inputs, on_done=None, on_error=None, on_always=None, **kwargs)[source]

Issue ‘update’ request to the Flow.

Parameters
  • inputs (Union[str, Iterable[str], Callable[…, Iterable[str]]]) – input data which can be an Iterable, a function which returns an Iterable, or a single Document id.

  • on_done (Optional[Callable[…, None]]) – the function to be called when the Request object is resolved.

  • on_error (Optional[Callable[…, None]]) – the function to be called when the Request object is rejected.

  • on_always (Optional[Callable[…, None]]) – the function to be called when the Request object is is either resolved or rejected.

  • kwargs – additional parameters

Return type

None

Returns

None

reload(targets, on_done=None, on_error=None, on_always=None, **kwargs)[source]

Send ‘reload’ request to the Flow.

Parameters
  • targets (Union[str, List[str]]) – the regex string or list of regex strings to match the pea/pod names.

  • on_done (Optional[Callable[…, None]]) – the function to be called when the Request object is resolved.

  • on_error (Optional[Callable[…, None]]) – the function to be called when the Request object is rejected.

  • on_always (Optional[Callable[…, None]]) – the function to be called when the Request object is is either resolved or rejected.

  • kwargs – additional parameters

Returns

None

class jina.clients.WebSocketClient(args)[source]

Bases: jina.clients.Client, jina.clients.websocket.WebSocketClientMixin

A Python Client to stream requests from a Flow with a REST Gateway.

WebSocketClient shares the same interface as Client and provides methods like index(), “meth:search, train(), update() & delete().

It is used by default while running operations when we create a Flow with rest_api=True

from jina.flow import Flow
f = Flow(rest_api=True).add().add()

with f:
    f.index(['abc'])

WebSocketClient can also be used to run operations for a remote Flow

# A Flow running on remote
from jina.flow import Flow
f = Flow(rest_api=True, port_expose=34567).add().add()

with f:
    f.block()

# Local WebSocketClient running index & search
from jina.clients import WebSocketClient

client = WebSocketClient(...)
client.index(...)
client.search(...)

WebSocketClient internally handles an event loop to run operations asynchronously.