jina.hubble.helper module#

Module for helper functions for Hub API.

jina.hubble.helper.get_hub_packages_dir()[source]#

Get the path of folder where the hub packages are stored

Return type

Path

Returns

the path of folder where the hub packages are stored

jina.hubble.helper.get_cache_db()[source]#

Get the path of cache db of hub Executors

Return type

Path

Returns

the path of cache db of hub Executors

jina.hubble.helper.get_download_cache_dir()[source]#

Get the path of cache folder where the downloading cache is stored

Return type

Path

Returns

the path of cache folder where the downloading cache is stored

jina.hubble.helper.get_request_header()[source]#

Return the header of request with an authorization token.

Return type

Dict

Returns

request header

jina.hubble.helper.get_hubble_url_v1()[source]#

Get v1 Hubble Url

Return type

str

Returns

v1 Hubble url

jina.hubble.helper.get_hubble_url_v2()[source]#

Get v2 Hubble Url

Return type

str

Returns

v2 Hubble url

jina.hubble.helper.parse_hub_uri(uri_path)[source]#

Parse the uri of the Jina Hub executor.

Parameters

uri_path (str) – the uri of Jina Hub executor

Return type

Tuple[str, str, str, str]

Returns

a tuple of schema, id, tag, and secret

jina.hubble.helper.replace_secret_of_hub_uri(uri_path, txt='<secret>')[source]#

Replace the secret of the Jina Hub URI.

Parameters
  • uri_path (str) – the uri of Jina Hub URI

  • txt (str) – text to replace

Return type

str

Returns

the new URI

jina.hubble.helper.is_valid_huburi(uri)[source]#

Return True if it is a valid Hubble URI

Parameters

uri (str) – the uri to test

Return type

bool

Returns

True or False

jina.hubble.helper.md5file(file_path)[source]#

Retrun the MD5 checksum of the file

Parameters

file_path (Path) – the file to check md5sum

Return type

str

Returns

the MD5 checksum

jina.hubble.helper.unpack_package(filepath, target_dir)[source]#

Unpack the file to the target_dir.

Parameters
  • filepath (Path) – the path of given file

  • target_dir (Path) – the path of target folder

jina.hubble.helper.archive_package(package_folder)[source]#

Archives the given folder in zip format and return a data stream. :type package_folder: Path :param package_folder: the folder path of the package :rtype: BytesIO :return: the data stream of zip content

jina.hubble.helper.download_with_resume(url, target_dir, filename=None, md5sum=None)[source]#

Download file from url to target_dir, and check md5sum. Performs a HTTP(S) download that can be restarted if prematurely terminated. The HTTP server must support byte ranges.

Parameters
  • url (str) – the URL to download

  • target_dir (Path) – the target path for the file

  • filename (Optional[str]) – the filename of the downloaded file

  • md5sum (Optional[str]) – the MD5 checksum to match

Return type

Path

Returns

the filepath of the downloaded file

jina.hubble.helper.upload_file(url, file_name, buffer_data, dict_data, headers, stream=False, method='post')[source]#

Upload file to target url

Parameters
  • url (str) – target url

  • file_name (str) – the file name

  • buffer_data (bytes) – the data to upload

  • dict_data (Dict) – the dict-style data to upload

  • headers (Dict) – the request header

  • stream (bool) – receive stream response

  • method (str) – the request method

Returns

the response of request

jina.hubble.helper.disk_cache_offline(cache_file='disk_cache.db', message='Calling {func_name} failed, using cached results')[source]#

Decorator which caches a function in disk and uses cache when a urllib.error.URLError exception is raised If the function was called with a kwarg force=True, then this decorator will always attempt to call it, otherwise, will always default to local cache.

Parameters
  • cache_file (str) – the cache file

  • message (str) – the warning message shown when defaulting to cache. Use “{func_name}” if you want to print the function name

Returns

function decorator

jina.hubble.helper.is_requirements_installed(requirements_file, show_warning=False)[source]#

Return True if requirements.txt is installed locally :type requirements_file: Path :param requirements_file: the requirements.txt file :type show_warning: bool :param show_warning: if to show a warning when a dependency is not satisfied :rtype: bool :return: True or False if not satisfied

jina.hubble.helper.install_requirements(requirements_file, timeout=1000)[source]#

Install modules included in requirments file :type requirements_file: Path :param requirements_file: the requirements.txt file :type timeout: int :param timeout: the socket timeout (default = 1000s)

class jina.hubble.helper.HubbleReturnStatus(value)[source]#

Bases: jina.enums.BetterEnum

Type of hubble return status enum

UNKNOWN_ERROR = -1#
OK = 20000#
PARAM_VALIDATION_ERROR = 40001#
SQL_CREATION_ERROR = 40002#
DATA_STREAM_BROKEN_ERROR = 40003#
UNEXPECTED_MIME_TYPE_ERROR = 40004#
SSO_LOGIN_REQUIRED = 40101#
AUTHENTICATION_FAILED = 40102#
AUTHENTICATION_REQUIRED = 40103#
OPERATION_NOT_ALLOWED = 40301#
INTERNAL_RESOURCE_NOT_FOUND = 40401#
RPC_METHOD_NOT_FOUND = 40402#
REQUESTED_ENTITY_NOT_FOUND = 40403#
INTERNAL_RESOURCE_METHOD_NOT_ALLOWED = 40501#
INCOMPATIBLE_METHOD_ERROR = 40502#
INTERNAL_RESOURCE_ID_CONFLICT = 40901#
RESOURCE_POLICY_DENY = 40902#
TOO_LARGE_FILE = 41301#
INTERNAL_DATA_CORRUPTION = 42201#
IDENTIFIER_NAMESPACE_OCCUPIED = 42202#
SUBMITTED_DATA_MALFORMED = 42203#
EXTERNAL_SERVICE_FAILURE = 42204#
DOWNSTREAM_SERVICE_FAILURE = 42205#
SERVER_INTERNAL_ERROR = 50001#
DOWNSTREAM_SERVICE_ERROR = 50002#
SERVER_SUBPROCESS_ERROR = 50003#
SANDBOX_BUILD_NOT_FOUND = 50004#
NOT_IMPLEMENTED_ERROR = 50005#
RESPONSE_STREAM_CLOSED = 50006#
class jina.hubble.helper.NormalizerErrorCode(value)[source]#

Bases: jina.enums.BetterEnum

Type of executor-normalizer error code enum

ExecutorNotFound = 4000#
ExecutorExists = 4001#
IllegalExecutor = 4002#
BrokenDependency = 4003#
Others = 5000#
jina.hubble.helper.get_hubble_error_message(hubble_structured_error)[source]#

Override some of the hubble error messages to provide better user experience :type hubble_structured_error: dict :param hubble_structured_error: the hubble structured error response :rtype: Tuple[str, str] :returns: Tuple of overridden_msg and original_msg