docarray.base module

class docarray.base.BaseProtoView(obj=None, copy=False)[source]

Bases: object

The base mixin class of all Jina types.

Note

  • All Jina types should inherit from this class.

  • All subclass should have self._pb_body

  • All subclass should implement __init__ with the possibility of initializing from None, e.g.:

    class MyJinaType(ProtoTypeMixin):
    
        def __init__(self, proto: Optional[docarray_pb2.SomePbMsg] = None):
            self._pb_body = proto or docarray_pb2.SomePbMsg()
    
to_json()[source]

Return the object in JSON string

Return type

str

Returns

JSON string of the object

to_dict()[source]

Return the object in Python dictionary.

Note

Array like object such as numpy.ndarray (i.e. anything described as docarray_pb2.NdArrayProto) will be converted to Python list.

Return type

Dict

Returns

dict representation of the object

property proto

Return the underlying Protobuf object

Returns

Protobuf representation of the object

to_bytes()[source]

Return the serialized the message to a string.

For more Pythonic code, please use bytes(...).

Return type

bytes

Returns

binary string representation of the object

property nbytes: int

Return total bytes consumed by protobuf.

Return type

int

Returns

number of bytes

property non_empty_fields: Tuple[str, ...]

Return the set fields of the current Protobuf message that are not empty

Return type

Tuple[str, …]

Returns

the tuple of non-empty fields

MergeFrom(other)[source]

Merge the content of target

Parameters

other (~T) – the document to merge from

Return type

None

CopyFrom(other)[source]

Copy the content of target

Parameters

other (~T) – the document to copy from

Return type

None

clear()[source]

Remove all values from all fields of this Document.

Return type

None

pop(*fields)[source]

Remove the values from the given fields of this Document.

Parameters

fields – field names

Return type

None

classmethod attributes(include_proto_fields=True, include_proto_fields_camelcase=False, include_properties=False)[source]

Return all attributes supported by the Document, which can be accessed by doc.attribute

Parameters
  • include_proto_fields (bool) – if set, then include all protobuf fields

  • include_proto_fields_camelcase (bool) – if set, then include all protobuf fields in CamelCase

  • include_properties (bool) – if set, then include all properties defined for Document class

Return type

List[str]

Returns

a list of attributes in string.

dict(**kwargs)
json(**kwargs)
binary_str(**kwargs)