# jina.drivers¶

jina.drivers.store_init_kwargs(func)[source]

Mark the args and kwargs of __init__() later to be stored via save_config() in YAML

Return type

Callable

class jina.drivers.QuerySetReader[source]

Bases: object

QuerySetReader allows a driver to read arguments from the protobuf message. This allows a driver to override its behavior based on the message it receives. Extremely useful in production, for example, get top_k results, doing pagination, filtering.

To register the field you want to read from the message, simply register them in __init__(). For example, __init__(self, arg1, arg2, **kwargs) will allow the driver to read field arg1 and arg2 from the message. When they are not found in the message, the value _arg1 and _arg2 will be used. Note the underscore prefix.

Note

• To set default value of arg1, use self._arg1 =, note the underscore in the front.

• To access arg1, simply use self.arg1. It automatically switch between default _arg1 and arg1 from the request.

For successful value reading, the following condition must be met:

• the name in the proto must match with the current class name

• the disabled field in the proto should not be False

• the priority in the proto should be strictly greater than the driver’s priority (by default is 0)

• the field name must exist in proto’s parameters

Warning

For the sake of cooperative multiple inheritance, do NOT implement __init__() for this class

class jina.drivers.DriverType[source]

Bases: jina.jaml.JAMLCompatibleType, type

static register_class(cls)[source]
class jina.drivers.BaseDriver(priority=0, *args, **kwargs)[source]

A BaseDriver is a logic unit above the jina.peapods.runtimes.zmq.zed.ZEDRuntime. It reads the protobuf message, extracts/modifies the required information and then return the message back to jina.peapods.runtimes.zmq.zed.ZEDRuntime.

A BaseDriver needs to be attached to a jina.peapods.runtimes.zmq.zed.ZEDRuntime before using. This is done by attach(). Note that a deserialized BaseDriver from file is always unattached.

Parameters

priority (int) – the priority of its default arg values (hardcoded in Python). If the received QueryLang has a higher priority, it will override the hardcoded value

store_args_kwargs = False

set this to True to save args (in a list) and kwargs (in a map) in YAML config

attach(runtime, *args, **kwargs)[source]

Attach this driver to a jina.peapods.runtimes.zmq.zed.ZEDRuntime

Parameters

runtime (ZEDRuntime) – the pea to be attached.

Return type

None

property req

Get the current (typed) request, shortcut to self.runtime.request

Return type

Request

property partial_reqs

The collected partial requests under the current request_id

Return type

Sequence[ForwardRef]

property expect_parts

The expected number of partial messages

Return type

int

property msg

Get the current request, shortcut to self.runtime.message

Return type

Message

property queryset
Return type

QueryLangSet

property logger

Shortcut to self.runtime.logger

Return type

JinaLogger

class jina.drivers.BaseRecursiveDriver(traversal_paths=('c', 'r'), *args, **kwargs)[source]
Parameters

traversal_paths (Tuple[str]) – The describes the leaves of the document tree on which _apply_all are called

property docs
class jina.drivers.BaseExecutableDriver(executor=None, method=None, *args, **kwargs)[source]

A BaseExecutableDriver is an intermediate logic unit between the jina.peapods.runtimes.zmq.zed.ZEDRuntime and jina.executors.BaseExecutor It reads the protobuf message, extracts/modifies the required information and then sends to the jina.executors.BaseExecutor, finally it returns the message back to jina.peapods.runtimes.zmq.zed.ZEDRuntime.

A BaseExecutableDriver needs to be attached to a jina.peapods.runtimes.zmq.zed.ZEDRuntime and jina.executors.BaseExecutor before using. This is done by attach(). Note that a deserialized BaseDriver from file is always unattached.

Initialize a BaseExecutableDriver

Parameters
• executor (Optional[str]) – the name of the sub-executor, only necessary when jina.executors.compound.CompoundExecutor is used

• method (Optional[str]) – the function name of the executor that the driver feeds to

property exec

the executor that attached

Return type

AnyExecutor

property exec_fn

the function of jina.executors.BaseExecutor() to call

Return type

Callable

attach(executor, *args, **kwargs)[source]

Attach the driver to a jina.executors.BaseExecutor

Return type

None