Skip to content

Commit b774aad

Browse files
evakravibencrabtree
authored andcommitted
feat: hub service sm session (aws#4422)
1 parent c799d1a commit b774aad

File tree

2 files changed

+428
-1
lines changed

2 files changed

+428
-1
lines changed

src/sagemaker/session.py

+264-1
Original file line numberDiff line numberDiff line change
@@ -6213,7 +6213,7 @@ def _intercept_create_request(
62136213
self,
62146214
request: typing.Dict,
62156215
create,
6216-
func_name: str = None
6216+
func_name: str = None,
62176217
# pylint: disable=unused-argument
62186218
):
62196219
"""This function intercepts the create job request.
@@ -6476,6 +6476,269 @@ def wait_for_inference_recommendations_job(
64766476
_check_job_status(job_name, desc, "Status")
64776477
return desc
64786478

6479+
def create_hub(
6480+
self,
6481+
hub_name: str,
6482+
hub_description: str,
6483+
hub_display_name: str = None,
6484+
hub_search_keywords: List[str] = None,
6485+
s3_storage_config: Dict[str, Any] = None,
6486+
tags: List[Dict[str, Any]] = None,
6487+
) -> Dict[str, str]:
6488+
"""Creates a SageMaker Hub
6489+
6490+
Args:
6491+
hub_name (str): The name of the Hub to create.
6492+
hub_description (str): A description of the Hub.
6493+
hub_display_name (str): The display name of the Hub.
6494+
hub_search_keywords (list): The searchable keywords for the Hub.
6495+
s3_storage_config (S3StorageConfig): The Amazon S3 storage configuration for the Hub.
6496+
tags (list): Any tags to associate with the Hub.
6497+
6498+
Returns:
6499+
(dict): Return value from the ``CreateHub`` API.
6500+
"""
6501+
request = {"HubName": hub_name, "HubDescription": hub_description}
6502+
if hub_display_name:
6503+
request["HubDisplayName"] = hub_display_name
6504+
if hub_search_keywords:
6505+
request["HubSearchKeywords"] = hub_search_keywords
6506+
if s3_storage_config:
6507+
request["S3StorageConfig"] = s3_storage_config
6508+
if tags:
6509+
request["Tags"] = tags
6510+
6511+
return self.sagemaker_client.create_hub(**request)
6512+
6513+
def describe_hub(self, hub_name: str) -> Dict[str, Any]:
6514+
"""Describes a SageMaker Hub
6515+
6516+
Args:
6517+
hub_name (str): The name of the hub to describe.
6518+
6519+
Returns:
6520+
(dict): Return value for ``DescribeHub`` API
6521+
"""
6522+
request = {"HubName": hub_name}
6523+
6524+
return self.sagemaker_client.describe_hub(**request)
6525+
6526+
def list_hubs(
6527+
self,
6528+
creation_time_after: str = None,
6529+
creation_time_before: str = None,
6530+
max_results: int = None,
6531+
max_schema_version: str = None,
6532+
name_contains: str = None,
6533+
next_token: str = None,
6534+
sort_by: str = None,
6535+
sort_order: str = None,
6536+
) -> Dict[str, Any]:
6537+
"""Lists all existing SageMaker Hubs
6538+
6539+
Args:
6540+
creation_time_after (str): Only list HubContent that was created after
6541+
the time specified.
6542+
creation_time_before (str): Only list HubContent that was created
6543+
before the time specified.
6544+
max_results (int): The maximum amount of HubContent to list.
6545+
max_schema_version (str): The upper bound of the HubContentSchemaVersion.
6546+
name_contains (str): Only list HubContent if the name contains the specified string.
6547+
next_token (str): If the response to a previous ``ListHubContents`` request was
6548+
truncated, the response includes a ``NextToken``. To retrieve the next set of
6549+
hub content, use the token in the next request.
6550+
sort_by (str): Sort HubContent versions by either name or creation time.
6551+
sort_order (str): Sort Hubs by ascending or descending order.
6552+
Returns:
6553+
(dict): Return value for ``ListHubs`` API
6554+
"""
6555+
request = {}
6556+
if creation_time_after:
6557+
request["CreationTimeAfter"] = creation_time_after
6558+
if creation_time_before:
6559+
request["CreationTimeBefore"] = creation_time_before
6560+
if max_results:
6561+
request["MaxResults"] = max_results
6562+
if max_schema_version:
6563+
request["MaxSchemaVersion"] = max_schema_version
6564+
if name_contains:
6565+
request["NameContains"] = name_contains
6566+
if next_token:
6567+
request["NextToken"] = next_token
6568+
if sort_by:
6569+
request["SortBy"] = sort_by
6570+
if sort_order:
6571+
request["SortOrder"] = sort_order
6572+
6573+
return self.sagemaker_client.list_hubs(**request)
6574+
6575+
def list_hub_contents(
6576+
self,
6577+
hub_name: str,
6578+
hub_content_type: str,
6579+
creation_time_after: str = None,
6580+
creation_time_before: str = None,
6581+
max_results: int = None,
6582+
max_schema_version: str = None,
6583+
name_contains: str = None,
6584+
next_token: str = None,
6585+
sort_by: str = None,
6586+
sort_order: str = None,
6587+
) -> Dict[str, Any]:
6588+
"""Lists the HubContents in a SageMaker Hub
6589+
6590+
Args:
6591+
hub_name (str): The name of the Hub to list the contents of.
6592+
hub_content_type (str): The type of the HubContent to list.
6593+
creation_time_after (str): Only list HubContent that was created after the
6594+
time specified.
6595+
creation_time_before (str): Only list HubContent that was created before the
6596+
time specified.
6597+
max_results (int): The maximum amount of HubContent to list.
6598+
max_schema_version (str): The upper bound of the HubContentSchemaVersion.
6599+
name_contains (str): Only list HubContent if the name contains the specified string.
6600+
next_token (str): If the response to a previous ``ListHubContents`` request was
6601+
truncated, the response includes a ``NextToken``. To retrieve the next set of
6602+
hub content, use the token in the next request.
6603+
sort_by (str): Sort HubContent versions by either name or creation time.
6604+
sort_order (str): Sort Hubs by ascending or descending order.
6605+
Returns:
6606+
(dict): Return value for ``ListHubContents`` API
6607+
"""
6608+
request = {"HubName": hub_name, "HubContentType": hub_content_type}
6609+
if creation_time_after:
6610+
request["CreationTimeAfter"] = creation_time_after
6611+
if creation_time_before:
6612+
request["CreationTimeBefore"] = creation_time_before
6613+
if max_results:
6614+
request["MaxResults"] = max_results
6615+
if max_schema_version:
6616+
request["MaxSchemaVersion"] = max_schema_version
6617+
if name_contains:
6618+
request["NameContains"] = name_contains
6619+
if next_token:
6620+
request["NextToken"] = next_token
6621+
if sort_by:
6622+
request["SortBy"] = sort_by
6623+
if sort_order:
6624+
request["SortOrder"] = sort_order
6625+
6626+
return self.sagemaker_client.list_hub_contents(**request)
6627+
6628+
def delete_hub(self, hub_name: str) -> None:
6629+
"""Deletes a SageMaker Hub
6630+
6631+
Args:
6632+
hub_name (str): The name of the hub to delete.
6633+
"""
6634+
request = {"HubName": hub_name}
6635+
6636+
return self.sagemaker_client.delete_hub(**request)
6637+
6638+
def import_hub_content(
6639+
self,
6640+
document_schema_version: str,
6641+
hub_content_name: str,
6642+
hub_content_type: str,
6643+
hub_name: str,
6644+
hub_content_document: str,
6645+
hub_content_display_name: str = None,
6646+
hub_content_description: str = None,
6647+
hub_content_version: str = None,
6648+
hub_content_markdown: str = None,
6649+
hub_content_search_keywords: List[str] = None,
6650+
tags: List[Dict[str, Any]] = None,
6651+
) -> Dict[str, str]:
6652+
"""Imports a new HubContent into a SageMaker Hub
6653+
6654+
Args:
6655+
document_schema_version (str): The version of the HubContent schema to import.
6656+
hub_content_name (str): The name of the HubContent to import.
6657+
hub_content_version (str): The version of the HubContent to import.
6658+
hub_content_type (str): The type of HubContent to import.
6659+
hub_name (str): The name of the Hub to import content to.
6660+
hub_content_document (str): The hub content document that describes information
6661+
about the hub content such as type, associated containers, scripts, and more.
6662+
hub_content_display_name (str): The display name of the HubContent to import.
6663+
hub_content_description (str): The description of the HubContent to import.
6664+
hub_content_markdown (str): A string that provides a description of the HubContent.
6665+
This string can include links, tables, and standard markdown formatting.
6666+
hub_content_search_keywords (list): The searchable keywords of the HubContent.
6667+
tags (list): Any tags associated with the HubContent.
6668+
Returns:
6669+
(dict): Return value for ``ImportHubContent`` API
6670+
"""
6671+
request = {
6672+
"DocumentSchemaVersion": document_schema_version,
6673+
"HubContentName": hub_content_name,
6674+
"HubContentType": hub_content_type,
6675+
"HubName": hub_name,
6676+
"HubContentDocument": hub_content_document,
6677+
}
6678+
if hub_content_display_name:
6679+
request["HubContentDisplayName"] = hub_content_display_name
6680+
if hub_content_description:
6681+
request["HubContentDescription"] = hub_content_description
6682+
if hub_content_version:
6683+
request["HubContentVersion"] = hub_content_version
6684+
if hub_content_markdown:
6685+
request["HubContentMarkdown"] = hub_content_markdown
6686+
if hub_content_search_keywords:
6687+
request["HubContentSearchKeywords"] = hub_content_search_keywords
6688+
if tags:
6689+
request["Tags"] = tags
6690+
6691+
return self.sagemaker_client.import_hub_content(**request)
6692+
6693+
def describe_hub_content(
6694+
self,
6695+
hub_content_name: str,
6696+
hub_content_type: str,
6697+
hub_name: str,
6698+
hub_content_version: str = None,
6699+
) -> Dict[str, Any]:
6700+
"""Describes a HubContent in a SageMaker Hub
6701+
6702+
Args:
6703+
hub_content_name (str): The name of the HubContent to describe.
6704+
hub_content_type (str): The type of HubContent in the Hub.
6705+
hub_name (str): The name of the Hub that contains the HubContent to describe.
6706+
hub_content_version (str): The version of the HubContent to describe
6707+
6708+
Returns:
6709+
(dict): Return value for ``DescribeHubContent`` API
6710+
"""
6711+
request = {
6712+
"HubContentName": hub_content_name,
6713+
"HubContentType": hub_content_type,
6714+
"HubName": hub_name,
6715+
}
6716+
if hub_content_version:
6717+
request["HubContentVersion"] = hub_content_version
6718+
6719+
return self.sagemaker_client.describe_hub_content(**request)
6720+
6721+
def delete_hub_content(
6722+
self, hub_content_name: str, hub_content_version: str, hub_content_type: str, hub_name: str
6723+
) -> None:
6724+
"""Deletes a given HubContent in a SageMaker Hub
6725+
6726+
Args:
6727+
hub_content_name (str): The name of the content thatyou want to delete from a Hub.
6728+
hub_content_version (str): The version of the content that you want to delete from
6729+
a Hub.
6730+
hub_content_type (str): The type of the content that you want to delete from a Hub.
6731+
hub_name (str): The name of the Hub that you want to delete content in.
6732+
"""
6733+
request = {
6734+
"HubContentName": hub_content_name,
6735+
"HubContentType": hub_content_type,
6736+
"HubName": hub_name,
6737+
"HubContentVersion": hub_content_version,
6738+
}
6739+
6740+
return self.sagemaker_client.delete_hub_content(**request)
6741+
64796742

64806743
def get_model_package_args(
64816744
content_types=None,

0 commit comments

Comments
 (0)