jina.clients.base.helper module#

class jina.clients.base.helper.AioHttpClientlet(url, logger, max_attempts=1, initial_backoff=0.5, max_backoff=0.1, backoff_multiplier=1.5, tracer_provider=None, **kwargs)[source]#

Bases: ABC

aiohttp session manager

HTTP Client to be used with the streamer

Parameters:
  • url – url to send http/websocket request to

  • logger – jina logger

  • max_attempts – Number of sending attempts, including the original request.

  • initial_backoff – The first retry will happen with a delay of random(0, initial_backoff)

  • max_backoff – The maximum accepted backoff after the exponential incremental delay

  • backoff_multiplier – The n-th attempt will occur at random(0, min(initialBackoff*backoffMultiplier**(n-1), maxBackoff))

  • tracer_provider – Optional tracer_provider that will be used to configure aiohttp tracing.

  • kwargs – kwargs which will be forwarded to the aiohttp.Session instance. Used to pass headers to requests

abstract async send_message(**kwargs)[source]#

Send message to Gateway :param kwargs: kwargs which will be forwarded to the aiohttp.Session.post method. Used to pass headers to requests

abstract async send_dry_run(**kwargs)[source]#

Query the dry_run endpoint from Gateway :param kwargs: kwargs which will be forwarded to the aiohttp.Session.post method. Used to pass headers to requests

abstract async recv_message()[source]#

Receive message from Gateway

async recv_dry_run()[source]#

Receive dry run response from Gateway

async start()[source]#

Create ClientSession and enter context

Returns:

self

async close(*args, **kwargs)[source]#

Close ClientSession

Parameters:
  • args – positional args

  • kwargs – keyword args

class jina.clients.base.helper.HTTPClientlet(url, logger, max_attempts=1, initial_backoff=0.5, max_backoff=0.1, backoff_multiplier=1.5, tracer_provider=None, **kwargs)[source]#

Bases: AioHttpClientlet

HTTP Client to be used with the streamer

HTTP Client to be used with the streamer

Parameters:
  • url – url to send http/websocket request to

  • logger – jina logger

  • max_attempts – Number of sending attempts, including the original request.

  • initial_backoff – The first retry will happen with a delay of random(0, initial_backoff)

  • max_backoff – The maximum accepted backoff after the exponential incremental delay

  • backoff_multiplier – The n-th attempt will occur at random(0, min(initialBackoff*backoffMultiplier**(n-1), maxBackoff))

  • tracer_provider – Optional tracer_provider that will be used to configure aiohttp tracing.

  • kwargs – kwargs which will be forwarded to the aiohttp.Session instance. Used to pass headers to requests

async send_message(request)[source]#

Sends a POST request to the server

Parameters:

request (Request) – request as dict

Returns:

send post message

async send_dry_run(**kwargs)[source]#

Query the dry_run endpoint from Gateway :param kwargs: keyword arguments to make sure compatible API with other clients :return: send get message

async recv_message()[source]#

Receive message for HTTP (sleep)

Returns:

await sleep

async recv_dry_run()[source]#

Receive dry run response for HTTP (sleep)

Returns:

await sleep

async close(*args, **kwargs)#

Close ClientSession

Parameters:
  • args – positional args

  • kwargs – keyword args

async start()#

Create ClientSession and enter context

Returns:

self

class jina.clients.base.helper.WsResponseIter(websocket)[source]#

Bases: object

Iterates over all the responses that come in over the websocket connection. In contrast to the iterator built into AioHTTP, this also records the message that was sent at closing-time.

class jina.clients.base.helper.WebsocketClientlet(*args, **kwargs)[source]#

Bases: AioHttpClientlet

Websocket Client to be used with the streamer

HTTP Client to be used with the streamer

Parameters:
  • url – url to send http/websocket request to

  • logger – jina logger

  • max_attempts – Number of sending attempts, including the original request.

  • initial_backoff – The first retry will happen with a delay of random(0, initial_backoff)

  • max_backoff – The maximum accepted backoff after the exponential incremental delay

  • backoff_multiplier – The n-th attempt will occur at random(0, min(initialBackoff*backoffMultiplier**(n-1), maxBackoff))

  • tracer_provider – Optional tracer_provider that will be used to configure aiohttp tracing.

  • kwargs – kwargs which will be forwarded to the aiohttp.Session instance. Used to pass headers to requests

async send_message(request)[source]#

Send request in bytes to the server.

Parameters:

request (Request) – request object

Returns:

send request as bytes awaitable

async send_dry_run(**kwargs)[source]#

Query the dry_run endpoint from Gateway :param kwargs: keyword arguments to make sure compatible API with other clients :return: send dry_run as bytes awaitable

async send_eoi()[source]#

To confirm end of iteration, we send bytes(True) to the server.

Returns:

send bytes(True) awaitable

async recv_message()[source]#

Receive messages in bytes from server and convert to DataRequest

..note::

aiohttp allows only one task which can receive concurrently. we need to make sure we don’t create multiple tasks with recv_message

Yield:

response objects received from server

Return type:

DataRequest

async recv_dry_run()[source]#

Receive dry run response in bytes from server

..note::

aiohttp allows only one task which can receive concurrently. we need to make sure we don’t create multiple tasks with recv_message

Yield:

response objects received from server

property close_message#
Returns:

the close message (reason) of the ws closing response

async close(*args, **kwargs)#

Close ClientSession

Parameters:
  • args – positional args

  • kwargs – keyword args

property close_code#
Returns:

the close code of the ws closing response

async start()#

Create ClientSession and enter context

Returns:

self