{"id":1023,"library":"sagemaker-studio","title":"SageMaker Studio Python Library","description":"The sagemaker-studio Python library is an open-source tool designed to interact with Amazon SageMaker Unified Studio resources. It provides a simplified interface to programmatically access and manage entities such as domains, projects, connections, and databases. The library also includes utility modules for common data operations, including SQL execution, DataFrame manipulation, and Spark session management. The current version is 1.1.11, and it maintains an active development and release cadence, with updates often reflecting the evolution of the broader SageMaker Unified Studio platform.","status":"active","version":"1.1.11","language":"python","source_language":"en","source_url":"https://github.com/aws-samples/amazon-sagemaker-studio-package-management","tags":["AWS","SageMaker","MLOps","Data Science","Cloud","Notebooks","Unified Studio"],"install":[{"cmd":"pip install sagemaker-studio","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Required for interacting with AWS services programmatically, which is fundamental to this library's functionality.","package":"boto3","optional":false}],"imports":[{"note":"Used for configuring AWS credentials and region when not running within a SageMaker Unified Studio JupyterLab environment.","symbol":"ClientConfig","correct":"from sagemaker_studio import ClientConfig"},{"note":"Represents an Amazon SageMaker Domain, which is an administrative boundary for Studio resources.","symbol":"Domain","correct":"from sagemaker_studio import Domain"},{"note":"Represents a SageMaker Studio Project, used to organize ML workflows and resources.","symbol":"Project","correct":"from sagemaker_studio import Project"},{"note":"Provides utilities for SQL execution against various data sources.","symbol":"sqlutils","correct":"from sagemaker_studio import sqlutils"},{"note":"Offers utilities for DataFrame operations, including reading from and writing to catalog tables.","symbol":"dataframeutils","correct":"from sagemaker_studio import dataframeutils"}],"quickstart":{"code":"import os\nfrom sagemaker_studio import ClientConfig, Domain, Project\n\n# --- Configure ClientConfig if not in SageMaker Studio JupyterLab ---\n# In a SageMaker Studio JupyterLab environment, credentials are automatically pulled.\n# Otherwise, provide AWS credentials and region.\n# Replace 'us-east-1' and 'your-aws-profile' as needed.\n# For demonstration, we use os.environ.get for robustness.\naws_region = os.environ.get('AWS_REGION', 'us-east-1')\naws_profile = os.environ.get('AWS_PROFILE', 'default')\n\n# Instantiate ClientConfig (optional, if running outside of Studio or with specific profile)\ntry:\n    client_config = ClientConfig(region_name=aws_region, profile_name=aws_profile)\nexcept Exception as e:\n    print(f\"Could not initialize ClientConfig, proceeding assuming environment provides credentials: {e}\")\n    client_config = None # Or handle more robustly\n\n# --- Interact with a SageMaker Domain and Project ---\n# To interact with a Domain or Project, you typically need its ID.\n# Replace 'your-domain-id' and 'your-project-id' with actual values.\n# If running in Studio, these might be discoverable from the environment.\ndomain_id = os.environ.get('SAGEMAKER_DOMAIN_ID', 'd-xxxxxxxxxxxx') # Placeholder\nproject_id = os.environ.get('SAGEMAKER_PROJECT_ID', 'p-yyyyyyyyyyyy') # Placeholder\n\nprint(f\"Attempting to interact with Domain ID: {domain_id}\")\nprint(f\"Attempting to interact with Project ID: {project_id}\")\n\nif client_config:\n    # Initialize Domain with client_config\n    domain = Domain(id=domain_id, client_config=client_config)\n    project = Project(id=project_id, domain_id=domain_id, client_config=client_config)\nelse:\n    # Initialize Domain without client_config (assumes environment provides)\n    domain = Domain(id=domain_id)\n    project = Project(id=project_id, domain_id=domain_id)\n\n# Accessing some properties (these calls might fail if IDs are invalid or permissions are insufficient)\ntry:\n    print(f\"Domain ID: {domain.id}\")\n    print(f\"Project Name: {project.name}\")\n    print(f\"Project S3 Path: {project.s3_path}\")\nexcept Exception as e:\n    print(f\"Error accessing domain/project properties: {e}\")\n    print(\"Please ensure the provided Domain/Project IDs are valid and your AWS credentials/permissions are correctly configured.\")\n\n# Example of using a utility module (requires an actual connection and query context)\n# from sagemaker_studio import sqlutils\n# try:\n#     result = sqlutils.sql(\"SELECT 1\", connection_name=\"your-connection-name\")\n#     print(f\"SQL Query Result: {result}\")\n# except Exception as e:\n#     print(f\"Error executing SQL query: {e}\")","lang":"python","description":"This quickstart demonstrates how to initialize `ClientConfig`, `Domain`, and `Project` objects using the `sagemaker-studio` library. It highlights the importance of credential configuration, either automatically within SageMaker Studio JupyterLab or explicitly via `ClientConfig` with an AWS profile. It then shows how to retrieve basic properties of a SageMaker Domain and Project. Note that running this code successfully requires valid AWS credentials and existing SageMaker Domain and Project IDs, and appropriate IAM permissions."},"warnings":[{"fix":"Use environment variables (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION), configure an AWS named profile, or initialize `ClientConfig(region_name='...', profile_name='...')` and pass it to object constructors.","message":"When using `sagemaker-studio` outside of an Amazon SageMaker Unified Studio JupyterLab environment, you must explicitly provide AWS credentials and region. This can be done by storing them in an AWS named profile or by passing a `ClientConfig` object during initialization of library components.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure your SageMaker Studio Space is running a compatible Space Distribution Image version (2.11+ or 3.6+). Upgrade your image if necessary via the SageMaker Studio console.","message":"The `sagemaker-studio` library (specifically for IAM-based domains) is supported only when using Space Distribution Image versions 2.11+ or 3.6+ in JupyterLab Notebooks or the Code Editor. Older image versions will not support the library.","severity":"gotcha","affected_versions":"All 1.x.x versions"},{"fix":"Always shut down inactive JupyterLab applications, kernel sessions, and other compute resources in the SageMaker Studio console when no longer in use. Consider implementing lifecycle configurations for automatic shutdown.","message":"Forgetting to shut down compute instances or applications within SageMaker Studio can lead to unexpected AWS costs. This is an operational consideration for the platform, but directly impacts users leveraging this library for resource management.","severity":"gotcha","affected_versions":"All versions"},{"fix":"When importing local modules, use `sys.path.insert(0, os.path.abspath('path/to/module'))` or ensure your modules are placed in a location discoverable by Python's path, considering the `/root` mapping.","message":"Custom Python modules or local files within your SageMaker Studio environment might require careful path handling. The Studio home folder is typically mapped to `/root` inside the notebook container, so direct relative paths may not work as expected.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure the `SAGEMAKER_PROJECT_ID` environment variable is set with the appropriate Project ID. Alternatively, if the library components support it, pass the project ID directly as an argument to constructors, e.g., `Domain(id='your-domain-id', project_id='your-project-id')`.","message":"When interacting with SageMaker Studio resources that are scoped to a project, the `sagemaker-studio` library requires a Project ID to be available. This ID must be provided explicitly or be discoverable within the execution environment. Failure to provide it will result in a `ValueError: Project ID not found in environment`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure your environment has the necessary build tools and development headers installed. For `alpine`-based images, run `apk add build-base python3-dev cmake` before attempting to install such libraries. For Debian/Ubuntu-based images, use `apt-get install build-essential python3-dev cmake`.","message":"Some Python libraries require compilation of C/C++ extensions during installation. When using minimalist base images (like `alpine`) or custom environments that do not include essential build tools and development headers, these installations will fail. This frequently affects data-related libraries like `duckdb` and `snowflake-connector-python` which depend on native code.","severity":"breaking","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-05-12T22:45:12.065Z","next_check":"2026-06-27T00:00:00.000Z","problems":[{"fix":"Change your import statement to use underscores: `import sagemaker_studio` or `from sagemaker_studio import Project`.","cause":"The Python package is installed using a hyphen (`sagemaker-studio`), but import statements in Python require underscores (`sagemaker_studio`).","error":"ModuleNotFoundError: No module named 'sagemaker_studio'"},{"fix":"Attach the required IAM policies (e.g., `AmazonRDSDataFullAccess`, `AWSGlueConsoleFullAccess`, `AmazonRedshiftDataFullAccess`, or more granular policies) to your SageMaker Studio execution role.","cause":"The IAM execution role associated with your SageMaker Studio environment lacks the necessary permissions to access the underlying AWS resource (e.g., RDS, Redshift, Glue) or perform the requested operation.","error":"botocore.exceptions.ClientError: An error occurred (AccessDeniedException) when calling the GetConnection operation: User: arn:aws:sts::... is not authorized to perform: rds-data:GetConnection on resource: arn:aws:rds:..."},{"fix":"Verify that the name of the Project or Connection is spelled correctly and that it exists in your AWS account and region. Also, ensure your IAM role has `sagemaker:DescribeProject` and `sagemaker:DescribeConnection` permissions.","cause":"The specified SageMaker Studio Project or Connection resource does not exist in the current AWS account and region, or your IAM role does not have permission to describe it.","error":"botocore.exceptions.ClientError: An error occurred (ResourceNotFoundException) when calling the DescribeProject operation: Project my-non-existent-project not found."}],"ecosystem":"pypi","meta_description":null,"install_score":48,"install_tag":"draft","quickstart_score":null,"quickstart_tag":null,"pypi_latest":"1.1.17","cli_name":"","install_checks":{"last_tested":"2026-05-12","tag":"draft","tag_description":"notable install failures or slow imports","results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":"build_error","install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":37.7,"import_time_s":2.64,"mem_mb":66,"disk_size":"727M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":2.5,"mem_mb":65.5,"disk_size":"704M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":"build_error","install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":32.7,"import_time_s":4.03,"mem_mb":75.2,"disk_size":"773M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":3.92,"mem_mb":74.7,"disk_size":"749M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":"build_error","install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":29.7,"import_time_s":4.37,"mem_mb":73.7,"disk_size":"763M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":4.67,"mem_mb":73.2,"disk_size":"739M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":"build_error","install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":28.3,"import_time_s":4.02,"mem_mb":74,"disk_size":"762M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":4.33,"mem_mb":73.6,"disk_size":"738M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":1.06,"mem_mb":18.6,"disk_size":"57.2M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.04,"mem_mb":18.6,"disk_size":"57.0M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":5.6,"import_time_s":0.93,"mem_mb":18.6,"disk_size":"58M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.91,"mem_mb":18.6,"disk_size":"58M"}]},"quickstart_checks":{"last_tested":"2026-04-24","tag":null,"tag_description":null,"results":[{"runtime":"python:3.10-alpine","exit_code":-1},{"runtime":"python:3.10-slim","exit_code":-1},{"runtime":"python:3.11-alpine","exit_code":-1},{"runtime":"python:3.11-slim","exit_code":-1},{"runtime":"python:3.12-alpine","exit_code":-1},{"runtime":"python:3.12-slim","exit_code":-1},{"runtime":"python:3.13-alpine","exit_code":-1},{"runtime":"python:3.13-slim","exit_code":-1},{"runtime":"python:3.9-alpine","exit_code":1},{"runtime":"python:3.9-slim","exit_code":1}]}}