jina.types.request

class jina.types.request.Request(request=None, envelope=None, copy=False)[source]

Bases: jina.types.mixin.ProtoTypeMixin

Request is one of the primitive data type in Jina.

It offers a Pythonic interface to allow users access and manipulate jina.jina_pb2.RequestProto object without working with Protobuf itself.

A container for serialized jina_pb2.RequestProto that only triggers deserialization and decompression when receives the first read access to its member.

It overrides __getattr__() to provide the same get/set interface as an jina_pb2.RequestProto object.

Parameters
  • request (Union[bytes, dict, str, RequestProto, None]) – The request.

  • envelope (Optional[EnvelopeProto]) – EnvelopeProto object.

  • copy (bool) – Copy the request if copy is True.

Set constructor method.

Parameters
  • request (Union[bytes, dict, str, RequestProto, None]) – request object as bytes, dictionary, string or protobuf instance

  • envelope (Optional[EnvelopeProto]) – envelope of the request

  • copy (bool) – if true, request is copied

is_used

Return True when request has been r/w at least once

property body

Return the request type, raise ValueError if request_type not set.

Returns

body property

as_typed_request(request_type)[source]

Change the request class according to the one_of value in body.

Parameters

request_type (str) – string representation of the request type

Returns

self

property request_type

Return the request body type, when not set yet, return None.

Return type

Optional[str]

Returns

request type

property proto

Cast self to a jina_pb2.RequestProto. This will trigger is_used. Laziness will be broken and serialization will be recomputed when calling SerializeToString().

Return type

RequestProto

Returns

protobuf instance

SerializeToString()[source]

Convert serialized data to string.

Return type

bytes

Returns

serialized request

property queryset

Get the queryset in QueryLangSet type.

Return type

QueryLangSet

Returns

query lang set

as_response()[source]

Return a weak reference of this object but as Response object. It gives a more consistent semantics on the client.

class jina.types.request.Response[source]

Bases: object

Response is the Request object returns from the flow. Right now it shares the same representation as Request. At 0.8.12, Response is a simple alias. But it does give a more consistent semantic on the client API: send a Request and receive a Response.