{"id":9289,"library":"sagemaker-experiments","title":"SageMaker Experiments SDK","description":"sagemaker-experiments is an open-source Python library from AWS for experiment tracking within Amazon SageMaker jobs and notebooks. It allows users to create, manage, and query machine learning experiments, trials, and trial components to track model parameters, metrics, and artifacts. The library maintains an active release cadence, with frequent minor updates.","status":"active","version":"0.1.45","language":"python","source_language":"en","source_url":"https://github.com/aws/sagemaker-experiment-tracking/","tags":["aws","sagemaker","mlops","experiment-tracking","machine-learning"],"install":[{"cmd":"pip install sagemaker-experiments","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Core SageMaker SDK for interacting with AWS SageMaker services.","package":"sagemaker","optional":false},{"reason":"AWS SDK for Python, underlying client for SageMaker API calls.","package":"boto3","optional":false},{"reason":"Optional dependency, required if logging scikit-learn specific artifacts/metrics (note: replaced 'sklearn' in v0.1.42).","package":"scikit-learn","optional":true}],"imports":[{"wrong":"from smexperiments import Experiment","symbol":"Experiment","correct":"from smexperiments import Experiment"}],"quickstart":{"code":"import os\nimport sagemaker\nfrom sagemaker.experiments import Experiment, Trial\nfrom sagemaker.experiments.tracker import Tracker\n\n# Ensure a SageMaker session is available. In a SageMaker Studio or Job,\n# a session is usually automatically configured.\n# For local execution, ensure AWS credentials and region are set up (e.g., via environment vars).\ntry:\n    sess = sagemaker.Session()\nexcept Exception:\n    # Fallback for local execution outside a SageMaker context if default fails\n    import boto3\n    print(\"Creating sagemaker.Session with boto3.Session for local execution.\")\n    sess = sagemaker.Session(boto3.Session(region_name=os.environ.get(\"AWS_REGION\", \"us-east-1\")))\n\nexperiment_name = f\"my-quickstart-experiment-{os.getpid()}\"\ntrial_name = f\"my-quickstart-trial-{os.getpid()}\"\n\n# 1. Create an Experiment\n# Using .create() ensures a new experiment; .load() would retrieve an existing one.\nmy_experiment = Experiment.create(\n    experiment_name=experiment_name,\n    description=\"A simple quickstart experiment for sagemaker-experiments\",\n    sagemaker_session=sess\n)\nprint(f\"Created Experiment: {my_experiment.experiment_name}\")\n\n# 2. Create a Trial within the Experiment\nmy_trial = Trial.create(\n    trial_name=trial_name,\n    experiment_name=experiment_name,\n    sagemaker_session=sess\n)\nprint(f\"Created Trial: {my_trial.trial_name}\")\n\n# 3. Use a Tracker to log parameters and metrics (e.g., simulating a training run)\nwith Tracker.create(display_name=\"TrainingJobComponent\", sagemaker_session=sess) as tracker:\n    tracker.log_parameters({\"learning_rate\": 0.01, \"epochs\": 10, \"optimizer\": \"Adam\"})\n    tracker.log_metrics({\"accuracy\": 0.85, \"loss\": 0.15, \"f1_score\": 0.82})\n    print(f\"Logged data to TrialComponent: {tracker.trial_component.trial_component_name}\")\n    \n    # Associate the tracker's automatically created trial component with our trial\n    my_trial.add_trial_component(tracker.trial_component)\n\nprint(\"Experiment, Trial, and TrialComponent created and data logged.\")\nprint(\"You can view these in SageMaker Studio under the Experiments tab.\")\n\n# Optional: Clean up created resources (uncomment to enable)\n# print(\"Cleaning up resources...\")\n# my_trial.delete_all_trial_components()\n# my_trial.delete()\n# my_experiment.delete()\n# print(\"Cleanup complete.\")","lang":"python","description":"This quickstart demonstrates how to initialize a SageMaker session, create an `Experiment` and `Trial`, and then use a `Tracker` to log parameters and metrics. It includes robust session handling for both SageMaker environments and local execution."},"warnings":[{"fix":"Ensure `scikit-learn` is installed in your environment: `pip install scikit-learn`. Update any direct `import sklearn` statements to `import scikit-learn` if applicable (though typically you import submodules like `from sklearn.ensemble import RandomForestClassifier`).","message":"The `sklearn` dependency was renamed to `scikit-learn` in `v0.1.42`. Projects directly depending on `sklearn` might experience `ModuleNotFoundError` if `scikit-learn` is not installed.","severity":"breaking","affected_versions":"v0.1.42 and later"},{"fix":"Upgrade your Python environment to 3.7 or newer. Recommended versions are Python 3.9, 3.10, or 3.11 for broader compatibility and active support.","message":"Support for Python 3.6 was officially dropped in `v0.1.42`. Users running `sagemaker-experiments` on Python 3.6 will encounter compatibility issues.","severity":"breaking","affected_versions":"v0.1.42 and later"},{"fix":"After creating your `Trial` and using `Tracker.create()`, explicitly associate the `TrialComponent`: `my_trial.add_trial_component(tracker.trial_component)`.","message":"When `Tracker.create()` is used outside of a SageMaker Training Job, it automatically creates a new `TrialComponent`. To associate this component with a specific `Trial` created manually (e.g., using `Trial.create()`), you must explicitly add it.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Upgrade to `sagemaker-experiments v0.1.44` or newer. If upgrading is not immediately possible, ensure that all SageMaker job names and trial component names use consistent casing, preferably lowercase, to avoid this specific issue.","message":"A bug prior to `v0.1.44` caused issues loading trial components for jobs with mixed-case names. This could lead to difficulties in retrieving or visualizing experiment data.","severity":"gotcha","affected_versions":"Prior to v0.1.44"}],"env_vars":null,"search_vec":"'activ':51 'allow':26 'amazon':20 'artifact':46 'aw':15,58 'cadenc':53 'compon':39 'creat':29 'experi':2,6,17,35,62 'experiment-track':61 'frequent':55 'job':22 'learn':34,66 'librari':13,48 'machin':33,65 'machine-learn':64 'maintain':49 'manag':30 'metric':44 'minor':56 'mlop':60 'model':42 'notebook':24 'open':10 'open-sourc':9 'paramet':43 'python':12 'queri':32 'releas':52 'sagemak':1,5,21,59 'sagemaker-experi':4 'sdk':3 'sourc':11 'track':18,41,63 'trial':36,38 'updat':57 'user':27 'within':19","created_at":"2026-04-16T18:49:26.869303+00:00","updated_at":"2026-04-16T18:49:26.869303+00:00","problems":{"verify_error":"Traceback (most recent call last):\n  File \"<string>\", line 1, in <module>\n  File \"/tmp/tmpwq7xirl_/venv/lib/python3.12/site-packages/smexperiments/__init__.py\", line 13, in <module>\n    import pkg_resources\nModuleNotFoundError: No module named 'pkg_resources'"},"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"0.1.45","cli_name":"","cli_version":null,"type":"library","homepage":"https://aws.amazon.com/sagemaker/","github":"https://github.com/aws/sagemaker-experiment-tracking","docs":null,"changelog":null,"pypi":"https://pypi.org/project/sagemaker-experiments/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["aws","ai-ml","data"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"import_fail","verified_at":"2026-07-03","last_verified":"2026-07-03","next_check":"2026-07-10","install_tag":null}}