SageMaker Core

2.7.1 · active · verified Thu Apr 09

SageMaker Core (`sagemaker-core`) is a foundational Python package providing core functionalities and utilities for interacting with AWS SageMaker services. It serves as a key dependency for the higher-level `sagemaker` Python SDK, abstracting away low-level AWS interactions and offering base classes for SageMaker components. It is currently at version 2.7.1 and typically updates alongside the main `sagemaker` SDK, though its versioning is distinct from the `sagemaker` SDK's major version. The project is actively maintained on GitHub within the larger `aws/sagemaker-python-sdk` monorepo.

Warnings

Install

Imports

Quickstart

Demonstrates initializing a `Session` directly from `sagemaker_core.session`, retrieving basic AWS configuration details like region, account ID, default S3 bucket, and the execution role. This illustrates direct interaction with core SageMaker components.

import sagemaker_core.session
import os

# Initialize a SageMaker Session directly from sagemaker_core.
# This session can then be used to interact with AWS SageMaker services.
# For full functionality, you would typically use `sagemaker.session.Session`
# which provides more high-level abstractions.

try:
    sagemaker_session = sagemaker_core.session.Session()
    region = sagemaker_session.boto_region_name
    account_id = sagemaker_session.account_id()
    print(f"Successfully initialized sagemaker_core.session.Session.")
    print(f"AWS Region: {region}")
    print(f"AWS Account ID: {account_id}")

    # Example: Get default S3 bucket for SageMaker artifacts
    default_bucket = sagemaker_session.default_bucket()
    print(f"Default S3 bucket: {default_bucket}")

    # Example: Attempt to get the IAM execution role.
    # This often works automatically in SageMaker Studio/Notebooks.
    try:
        role = sagemaker_session.get_execution_role()
        print(f"Execution Role: {role}")
    except Exception as e:
        print(f"Could not get execution role (expected if not in SM Studio/notebook or roles not configured): {e}")

except Exception as e:
    print(f"Error initializing sagemaker_core.session.Session: {e}")
    print("Ensure AWS credentials are configured (e.g., via environment variables, ~/.aws/credentials, or IAM roles).")

view raw JSON →