skip to Main Content

In Java, for instance, we have a class that represents the SageMaker client class: AmazonSageMakerClient, but I couldn’t find the equivalent for Python.

I was hoping to be able to do something like:

from sagemaker import SageMakerClient
client: SageMakerClient = boto3.client("sagemaker")

I looked into the library code and docs but I couldn’t find any references to such class containing the defined methods for that client. In fact, I couldn’t find any classes for AWS clients like s3, sqs, etc. Are those hidden somewhere or am I missing something obvious?

4

Answers


  1. In boto3, there is basically 2 levels of objects avaialble:

    1. A client
    2. Actual objects like you are asking about

    Take a look at S3, and you will see that in addition to the Client object there are also other rich object types like Bucket.

    It would seem that Sagemaker doesn’t (yet) have this second level of abstraction available.

    Login or Signup to reply.
  2. To be more productive, and work with Python classes rather than Json, try to use the SageMaker Python SDK whenever possible rather than Boto3 clients.

    With Boto3 you have several SageMaker clients (As @anon said correctly):

    • SageMaker – Most of SageMaker features
    • SageMakerRuntime – Invoking endpoints
    • SageMaker* – Other misc SageMaker features like feature store, edge manager, …
    Login or Signup to reply.
  3. The boto3-stubs library can help with this.

    Install using the instructions for your IDE on the package page, and then install the specific type annotations for SageMaker.

    pip install 'boto3-stubs[sagemaker]'
    

    You should be able to see type hints for the client object (type: SageMakerClient).

    import boto3
    
    client = boto3.client('sagemaker')
    

    If you need to add hints yourself:

    from mypy_boto3_sagemaker import SageMakerClient
    
    def my_func(client: SageMakerClient):
        client.create_algorithm(...)
    
    Login or Signup to reply.
  4. You may not need to do that. Here’s some tricks I have used for a while:

    from boto_session_manager import BotoSesManager
    
    bsm = BotoSesManager()
    bsm. # <--- now it show you list of available client and it can do auto complete
    
    bsm.s3_client # this is an Client object with explicit type hint
    
    bsm.s3_client. # <--- now it show you list of available method
    
    bsm.s3_client.put_object( # <--- now it show you list of available argument and their type)
    
    bsm.s3_client # select the s3_client part and jump to source code, you can one click to jump to the official document
    
    bsm.s3_client.put_object # select the put_object part and jump to source code, you can one click to jump to the official document
    

    I checked the source code, it use boto_stub under the hood and enumerate all available client and explicitly give them type hint.

    Hope this is helpful

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search