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: - document – Document instance to be validated
- schema_name (string) – Name of schema (e.g., “dataset” for validating datasets). For full list, see: https://github.com/DLHub-Argonne/dlhub_schemas
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
Add authors to the query.
Parameters: Returns: Self
Return type:
-
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: Returns: Self
Return type:
-
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: Returns: Self
Return type:
-
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 functionParameters: Returns: Metadata for the servable method, or a single method of
method_name
is usedReturn type: