docarray.helper module#

docarray.helper.typename(obj)[source]#

Get the typename of object.

Parameters:

obj – Target object.

Returns:

Typename of the obj.

docarray.helper.deprecate_by(new_fn, removed_at)[source]#

A helper function to label deprecated function

Usage: old_fn_name = deprecate_by(new_fn)

Parameters:
  • new_fn – the new function

  • removed_at (str) – removed at which version

Returns:

a wrapped function with old function name

docarray.helper.dunder_get(_dict, key)[source]#

Returns value for a specified dunderkey

A “dunderkey” is just a fieldname that may or may not contain double underscores (dunderscores!) for referencing nested keys in a dict. eg:

>>> data = {'a': {'b': 1}}
>>> dunder_get(data, 'a__b')

key ‘b’ can be referrenced as ‘a__b’

Parameters:
  • _dict (Any) – (dict, list, struct or object) which we want to index into

  • key (str) – (str) that represents a first level or nested key in the dict

Return type:

Any

Returns:

(mixed) value corresponding to the key

docarray.helper.random_identity(use_uuid1=False)[source]#

Generate random UUID.

..note::

A MAC address or time-based ordering (UUID1) can afford increased database performance, since it’s less work to sort numbers closer-together than those distributed randomly (UUID4) (see here).

A second related issue, is that using UUID1 can be useful in debugging, even if origin data is lost or not explicitly stored.

Parameters:

use_uuid1 (bool) – use UUID1 instead of UUID4. This is the default Document ID generator.

Return type:

str

Returns:

A random UUID.

docarray.helper.random_uuid(use_uuid1=False)[source]#

Get a random UUID.

Parameters:

use_uuid1 (bool) – Use UUID1 if True, else use UUID4.

Return type:

UUID

Returns:

A random UUID.

docarray.helper.download_mermaid_url(mermaid_url, output)[source]#

Download the jpg image from mermaid_url.

Parameters:
  • mermaid_url – The URL of the image.

  • output – A filename specifying the name of the image to be created, the suffix svg/jpg determines the file type of the output image.

Return type:

None

docarray.helper.get_full_version()[source]#

Get the version of libraries used in Jina and environment variables.

Return type:

Dict

Returns:

Version information and environment variables

docarray.helper.get_ci_vendor()[source]#
Return type:

str

docarray.helper.reset_ports()[source]#
docarray.helper.random_port()[source]#

Get a random available port number.

Return type:

Optional[int]

Returns:

A random port.

class docarray.helper.cached_property(func)[source]#

Bases: object

The decorator to cache property of a class.

Create the cached_property.

Parameters:

func – Cached function.

docarray.helper.compress_bytes(data, algorithm=None)[source]#
Return type:

bytes

docarray.helper.decompress_bytes(data, algorithm=None)[source]#
Return type:

bytes

docarray.helper.get_compress_ctx(algorithm=None, mode='wb')[source]#
docarray.helper.dataclass_from_dict(klass, dikt)[source]#
docarray.helper.protocol_and_compress_from_file_path(file_path, default_protocol=None, default_compress=None)[source]#

Extract protocol and compression algorithm from a string, use defaults if not found.

Parameters:
  • file_path (str) – path of a file.

  • default_protocol (Optional[str]) – default serialization protocol used in case not found.

  • default_compress (Optional[str]) – default compression method used in case not found.

Examples:

>>> protocol_and_compress_from_file_path('./docarray_fashion_mnist.protobuf.gzip')
('protobuf', 'gzip')
>>> protocol_and_compress_from_file_path('/Documents/docarray_fashion_mnist.protobuf')
('protobuf', None)
>>> protocol_and_compress_from_file_path('/Documents/docarray_fashion_mnist.gzip')
(None, gzip)
Return type:

Tuple[Optional[str], Optional[str]]

docarray.helper.add_protocol_and_compress_to_file_path(file_path, protocol=None, compress=None)[source]#

Creates a new file path with the protocol and compression methods as extensions.

Parameters:
  • file_path (str) – path of a file.

  • protocol (Optional[str]) – chosen protocol.

  • compress (Optional[str]) – compression algorithm.

Examples:

>>> add_protocol_and_compress_to_file_path('docarray_fashion_mnist.bin')
'docarray_fashion_mnist.bin'
>>> add_protocol_and_compress_to_file_path('docarray_fashion_mnist', 'protobuf', 'gzip')
'docarray_fashion_mnist.protobuf.gzip'
Return type:

str

docarray.helper.filter_dict(d)[source]#

Removes None values from dict d.

Parameters:

d (Dict) – input dict

Return type:

Dict

Returns:

filtered dict

docarray.helper.check_root_id(da, value)[source]#
docarray.helper.login(interactive=None, force=False, **kwargs)[source]#

Login to Jina AI Cloud account. :type interactive: Optional[bool] :param interactive: If set to true, login will support notebook environments, otherwise the enviroment will be inferred. :type force: bool :param force: If set to true, overwrite token and re-login.

docarray.helper.logout()[source]#

Log out of Hubble account.