jina.types.request package

Submodules

Module contents

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

Bases: jina.types.mixin.ProtoTypeMixin, jina.types.request.mixin.DocsPropertyMixin, jina.types.request.mixin.GroundtruthPropertyMixin

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, Request, None]) – The request.

  • compression_algorithm (Optional[CompressAlgo]) – The compression algorithm to use.

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

property is_decompressed

Return a boolean indicating if the proto is decompressed

Returns

a boolean indicating if the proto is decompressed

property body

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

Returns

body property

property request_type: Optional[str]

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

Return type

Optional[str]

Returns

request type

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 proto: jina_pb2.RequestProto

Cast self to a jina_pb2.RequestProto. 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

as_response()[source]

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

Returns

self as an instance of Response

property parameters: jina.types.struct.StructView

Return the tags field of this Document as a Python dict

Return type

StructView

Returns

a Python dict view of the tags.

class jina.types.request.Response(request=None, compression_algorithm=None, copy=False)[source]

Bases: jina.types.request.Request, jina.types.request.mixin.DocsPropertyMixin, jina.types.request.mixin.GroundtruthPropertyMixin

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.

Note

For now it only exposes Docs and GroundTruth. Users should very rarely access Control commands, so preferably not confuse the user by adding CommandMixin.