dlhub_sdk package

Submodules

dlhub_sdk.client module

class dlhub_sdk.client.DLHubClient(dlh_authorizer=None, search_client=None, http_timeout=None, force_login=False, fx_authorizer=None, **kwargs)

Bases: globus_sdk.base.BaseClient

Main class for interacting with the DLHub service

Holds helper operations for performing common tasks with the DLHub service. For example, get_servables produces a list of all servables registered with DLHub.

For most cases, we recommend creating a new DLHubClient by calling DLHubClient.login. This operation will check if you have saved any credentials to disk before using the CLI or SDK and, if not, get new credentials and save them for later use. For cases where disk access is unacceptable, you can create the client by creating an authorizer following the tutorial for the Globus SDK and providing that authorizer to the initializer (e.g., DLHubClient(auth))

clear_funcx_cache(servable=None)

Remove functions from the cache. Either remove a specific servable or wipe the whole cache.

Parameters

Servable – str The name of the servable to remove. Default None

describe_methods(name, method=None)

Get the description for the method(s) of a certain servable

Parameters
  • name (string) – DLHub name of the servable of the form <user>/<servable_name>

  • method (string) – Optional: Name of the method

Returns

Description of a certain method if method provided, all methods

if the method name was not provided.

Return type

dict

describe_servable(name)

Get the description for a certain servable

Parameters

name (string) – DLHub name of the servable of the form <user>/<servable_name>

Returns

Summary of the servable

Return type

dict

get_result(task_id, verbose=False)

Get the result of a task_id

Parameters
  • str (task_id) – The task’s uuid

  • bool (verbose) – whether or not to return the full dlhub response

Returns

Reult of running the servable

get_servables(only_latest_version=True)

Get all of the servables available in the service

Parameters

only_latest_version (bool) – Whether to only return the latest version of each servable

Returns

([list]) Complete metadata for all servables found in DLHub

get_task_status(task_id)

Get the status of a DLHub task.

Parameters

task_id (string) – UUID of the task

Returns

status block containing “status” key.

Return type

dict

get_username()

Get the username associated with the current credentials

list_servables()

Get a list of the servables available in the service

Returns

List of all servable names in username/servable_name format

Return type

[string]

logout()

Remove credentials from your local system

publish_repository(repository)

Submit a repository to DLHub for publication

Parameters

repository (string) – Repository to publish

Returns

Task ID of this submission, used for checking for success

Return type

(string)

publish_servable(model)

Submit a servable to DLHub

If this servable has not been published before, it will be assigned a unique identifier.

If it has been published before (DLHub detects if it has an identifier), then DLHub will update the servable to the new version.

Parameters

model (BaseMetadataModel) – Servable to be submitted

Returns

Task ID of this submission, used for checking for success

Return type

(string)

property query

Access a query of the DLHub Search repository

run(name, inputs, asynchronous=False, async_wait=5, timeout: Optional[float] = None) → Union[Any, dlhub_sdk.utils.futures.DLHubFuture]

Invoke a DLHub servable

Parameters
  • name (string) – DLHub name of the servable of the form <user>/<servable_name>

  • inputs – Data to be used as input to the function. Can be a string of file paths or URLs

  • asynchronous (bool) – Whether to return from the function immediately or wait for the execution to finish.

  • async_wait (float) – How many seconds to wait between checking async status

  • timeout (float) – How long to wait for a result to return. Only used for synchronous calls

Returns

Results of running the servable. If asynchronous, then a DLHubFuture holding the result

run_serial(servables, inputs, async_wait=5)

Invoke each servable in a serial pipeline. This function accepts a list of servables and will run each one, passing the output of one as the input to the next.

Parameters
  • servables (list) – A list of servable strings

  • inputs – Data to pass to the first servable

  • asycn_wait (float) – Seconds to wait between status checks

Returns

Results of running the servable

search(query, advanced=False, limit=None, only_latest=True)

Query the DLHub servable library

By default, the query is used as a simple plaintext search of all model metadata. Optionally, you can provided an advanced query on any of the indexed fields in the DLHub model metadata by setting advanced=True and following the guide for constructing advanced queries found in the Globus Search documentation.

Parameters
  • query (string) – Query to be performed

  • advanced (bool) – Whether to perform an advanced query

  • limit (int) – Maximum number of entries to return

  • only_latest (bool) – Whether to return only the latest version of the model

Returns

All records matching the search query

Return type

([dict])

search_by_authors(authors, match_all=True, limit=None, only_latest=True)

Execute a search for servables from certain authors.

Authors in DLHub may be different than the owners of the servable and generally are the people who developed functionality of a certain servable (e.g., the creators of the machine learning model used in a servable).

If you want to search by ownership, see search_by_servable()

Parameters
  • authors (str or list of str) – The authors to match. Names must be in “Family Name, Given Name” format

  • match_all (bool) – If True, will require all authors be on any results. If False, will only require one author to be in results. Default: True.

  • limit (int) – The maximum number of results to return. Default: None, for no limit.

  • only_latest (bool) – When True, will only return the latest version of each servable. When False, will return all matching versions. Default: True.

Returns

List of servables from the desired authors

Return type

[dict]

Get all of the servables associated with a certain publication

Parameters
  • doi (string) – DOI of related paper

  • limit (int) – Maximum number of results to return

  • only_latest (bool) – Whether to return only the most recent version of the model

Returns

List of servables from the requested paper

Return type

[dict]

search_by_servable(servable_name=None, owner=None, version=None, only_latest=True, limit=None, get_info=False)

Search by the ownership, name, or version of a servable

Parameters
  • servable_name (str) – The name of the servable. Default: None, to match all servable names.

  • owner (str) – The name of the owner of the servable. Default: None, to match all owners.

  • version (int) – Model version, which corresponds to the date when the servable was published. Default: None, to match all versions.

  • only_latest (bool) – When True, will only return the latest version of each servable. When False, will return all matching versions. Default: True.

  • limit (int) – The maximum number of results to return. Default: None, for no limit.

  • get_info (bool) – If False, search will return a list of the results. If True, search will return a tuple containing the results list and other information about the query. Default: False.

Returns

The search results. If info is True, tuple: The search results, and a dictionary of query information.

Return type

If info is False, list

Module contents