jina.clientsΒΆ

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 eventloop internally, so all interfaces are synchronous from the outside.

Parameters

args (Namespace) – args provided by the CLI

train(input_fn=None, on_done=None, on_error=None, on_always=None, **kwargs)[source]ΒΆ
Parameters
  • input_fn (Union[Iterator[Union[~DocumentContentType, ~DocumentSourceType, Tuple[~DocumentContentType, ~DocumentContentType], Tuple[~DocumentSourceType, ~DocumentSourceType]]], Callable[…, Iterator[Union[~DocumentContentType, ~DocumentSourceType, Tuple[~DocumentContentType, ~DocumentContentType], Tuple[~DocumentSourceType, ~DocumentSourceType]]]], None]) – the input function that generates the content

  • 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 –

Return type

None

Returns

search(input_fn=None, on_done=None, on_error=None, on_always=None, **kwargs)[source]ΒΆ
Parameters
  • input_fn (Union[Iterator[Union[~DocumentContentType, ~DocumentSourceType, Tuple[~DocumentContentType, ~DocumentContentType], Tuple[~DocumentSourceType, ~DocumentSourceType]]], Callable[…, Iterator[Union[~DocumentContentType, ~DocumentSourceType, Tuple[~DocumentContentType, ~DocumentContentType], Tuple[~DocumentSourceType, ~DocumentSourceType]]]], None]) – the input function that generates the content

  • 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 –

Return type

None

Returns

index(input_fn=None, on_done=None, on_error=None, on_always=None, **kwargs)[source]ΒΆ
Parameters
  • input_fn (Union[Iterator[Union[~DocumentContentType, ~DocumentSourceType, Tuple[~DocumentContentType, ~DocumentContentType], Tuple[~DocumentSourceType, ~DocumentSourceType]]], Callable[…, Iterator[Union[~DocumentContentType, ~DocumentSourceType, Tuple[~DocumentContentType, ~DocumentContentType], Tuple[~DocumentSourceType, ~DocumentSourceType]]]], None]) – the input function that generates the content

  • 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 –

Return type

None

Returns

update(input_fn=None, on_done=None, on_error=None, on_always=None, **kwargs)[source]ΒΆ
Parameters
  • input_fn (Union[Iterator[Union[~DocumentContentType, ~DocumentSourceType, Tuple[~DocumentContentType, ~DocumentContentType], Tuple[~DocumentSourceType, ~DocumentSourceType]]], Callable[…, Iterator[Union[~DocumentContentType, ~DocumentSourceType, Tuple[~DocumentContentType, ~DocumentContentType], Tuple[~DocumentSourceType, ~DocumentSourceType]]]], None]) – the input function that generates the content

  • 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 –

Return type

None

Returns

delete(input_fn=None, on_done=None, on_error=None, on_always=None, **kwargs)[source]ΒΆ
Parameters
  • input_fn (Union[Iterator[Union[~DocumentContentType, ~DocumentSourceType, Tuple[~DocumentContentType, ~DocumentContentType], Tuple[~DocumentSourceType, ~DocumentSourceType]]], Callable[…, Iterator[Union[~DocumentContentType, ~DocumentSourceType, Tuple[~DocumentContentType, ~DocumentContentType], Tuple[~DocumentSourceType, ~DocumentSourceType]]]], None]) – the input function that generates the content

  • 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 –

Return type

None

Returns

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

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

A Python Client to stream requests from a Flow with a RESTGateway 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.

Parameters

args (Namespace) – args provided by the CLI