jina.hubble.helper module

Module for helper functions for Hub API.

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.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)