jina.helper

jina.helper.deprecated_alias(**aliases)[source]
jina.helper.batch_iterator(data, batch_size, axis=0, yield_slice=False, yield_dict=False)[source]
Return type

Iterator[Any]

jina.helper.parse_arg(v)[source]
Return type

Union[bool, int, str, list, float, None]

jina.helper.random_port()[source]
Return type

Optional[int]

jina.helper.get_random_identity()[source]
Return type

str

jina.helper.expand_env_var(v)[source]
Return type

Union[bool, int, str, list, float, None]

jina.helper.is_url(text)[source]
jina.helper.colored(text, color=None, on_color=None, attrs=None)[source]
Return type

str

class jina.helper.ArgNamespace[source]

Bases: object

Helper function for argparse.Namespace object

static kwargs2list(kwargs)[source]

Convert dict to an argparse-friendly list

Parameters

kwargs (Dict) – dictionary of key-values to be converted

Return type

List[str]

static kwargs2namespace(kwargs, parser)[source]

Convert dict to a namespace

Parameters
  • kwargs (Dict[str, Union[str, int, bool]]) – dictionary of key-values to be converted

  • parser (ArgumentParser) – the parser for building kwargs into a namespace

Return type

Namespace

static get_parsed_args(kwargs, parser)[source]

Get all parsed args info in a dict

Parameters
  • kwargs (Dict[str, Union[str, int, bool]]) – dictionary of key-values to be converted

  • parser (ArgumentParser) – the parser for building kwargs into a namespace

Return type

Tuple[List[str], Namespace, List[Any]]

static get_non_defaults_args(args, parser, taboo=None)[source]

Get non-default args in a dict

Parameters
  • args (Namespace) – the namespace to parse

  • parser (ArgumentParser) – the parser for referring the default values

  • taboo (Optional[Set[Optional[str]]]) – exclude keys in the final result

Return type

Dict

static flatten_to_dict(args)[source]

A helper function to convert argparse.Namespace to dict to be uploaded via REST

Parameters

args (Union[Dict[str, Namespace], Namespace]) – namespace or dict or namespace to dict.

Return type

Dict[str, Any]

jina.helper.is_valid_local_config_source(path)[source]
Return type

bool

jina.helper.typename(obj)[source]
class jina.helper.cached_property(func)[source]

Bases: object

jina.helper.get_internal_ip()[source]
jina.helper.get_public_ip()[source]
jina.helper.convert_tuple_to_list(d)[source]
jina.helper.run_async(func, *args, **kwargs)[source]

Generalized asyncio.run for jupyter notebook.

When running inside jupyter, an eventloop is already exist, can’t be stopped, can’t be killed. Directly calling asyncio.run will fail, as This function cannot be called when another asyncio event loop is running in the same thread.

Parameters
  • func – function to run

  • args – parameters

  • kwargs – key-value parameters

Returns