dlhub_sdk.utils package

Submodules

dlhub_sdk.utils.schemas module

Utilities for validating against DLHub schemas

dlhub_sdk.utils.schemas.validate_against_dlhub_schema(document: Union[dict, dlhub_sdk.models.BaseMetadataModel], schema_name: str)

Validate a metadata document against one of the DLHub schemas

Note: Requires an internet connection

Parameters:
Raises:

(jsonschema.SchemaError) If the schema fails to validate

dlhub_sdk.utils.types module

Utilities for generating descriptions of data types

dlhub_sdk.utils.types.compose_argument_block(data_type, description, shape=None, item_type=None, python_type=None, properties=None, element_types=None, **kwargs)

Compile a list of argument descriptions into an argument_type block

Parameters:
  • data_type (string) – Type of the input data
  • description (string) – Human-friendly description of the data
  • shape (list) – Required for data_type = ndarray. Use None for dimensions that can have any numbers of values
  • item_type (string/dict) – Description of the item type. Required for data_type = list. Can either be a string type, or a dict that is a valid type for an argument type block
  • python_type (string) – Full path of a Python object type (e.g., pymatgen.core.Compostion)
  • properties (dict) – Descriptions of the types in a dictionary
  • element_types ([dict] or [str]) – Types of elements in a tuple. List of type definition dictionaries or types as strings.

Keyword Arguments: Any other details particular to this kind of data :returns: (dict) Description of method in a form compatible with DLHub

dlhub_sdk.utils.types.simplify_numpy_dtype(dtype)

Given a numpy dtype, write out the type as string

Parameters:dtype (numpy.dtype) – Type
Returns:(string) name as a simple string

dlhub_sdk.utils.search module

Tools for interacting with the DLHub Search Index

class dlhub_sdk.utils.search.DLHubSearchHelper(search_client: globus_sdk.services.search.client.SearchClient, **kwargs)

Bases: mdf_toolbox.globus_search.search_helper.SearchHelper

Helper class for building queries with DLHub

match_authors(authors, match_all=True)

Add authors to the query.

Parameters:
  • authors (str or list of str) – The authors to match.
  • 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.
Returns:

Self

Return type:

DLHubSearchHelper

match_doi(doi)

Add a DOI to the query.

Parameters:doi (str) – The DOI to match.
Returns:Self
Return type:DLHubSearchHelper
match_domains(domains, match_all=True)

Add domains to the query.

Parameters:
  • domains (str or list of str) – The domains to match.
  • match_all (bool) – If True, will require all domains be on any results. If False, will only require one domain to be in results. Default: True.
Returns:

Self

Return type:

DLHubSearchHelper

match_owner(owner)

Add a model owner to the query.

Parameters:owner (str) – The name of the owner of the model.
Returns:Self
Return type:DLHubSearchHelper
match_servable(servable_name=None, owner=None, publication_date=None)

Add identifying model information to the query. If this method is called without any valid arguments, it will do nothing.

Parameters:
  • servable_name (str) – The name of the model. Default: None, to match all model names.
  • owner (str) – The name of the owner of the model. Default: None, to match all owners.
  • publication_date (int) – The UNIX timestamp for when the model was published. Default: None, to match all versions.
Returns:

Self

Return type:

DLHubSearchHelper

dlhub_sdk.utils.search.filter_latest(results)

Get only the models with the most recent publication date

Parameters:results ([dict]) – List of results to filter
Returns:Only the most recent results
Return type:[dict]
dlhub_sdk.utils.search.get_method_details(metadata, method_name=None)

Get the method details for use by humans

Gets only the method fields out of the metadata record for an objecvt, removes the “method_details” field, which is used only during construction of the object.

Will either return the data for all methods or, if method_name is provided, only a single function

Parameters:
  • metadata (dict) – Metadata record for a servable
  • method_name (str) – Optional: Name of the function to retrieve
Returns:

Metadata for the servable method, or a single method of method_name is used

Return type:

dict

Module contents

dlhub_sdk.utils.unserialize_object(data)

Given a metadata dictionary object, form a MetadataModel class

Parameters:data (dict) – Metadata to unserialize
Returns:(BaseMetadataModel) Unserialized object