sagemaker.core.utils.install_requirements#

CodeArtifact-aware pip requirements installer.

Reads CA_REPOSITORY_ARN from the environment and authenticates with CodeArtifact before installing packages. Tries boto3 first (matching sagemaker-training-toolkit), falls back to AWS CLI, and hard-fails when the env var is set but neither mechanism is available.

Can be used as:
  • An importable module:

    • configure_pip() — returns an authenticated pip index URL (or None). Use when you need to build your own pip command with custom flags.

    • install_requirements(path) — configures pip and runs pip install -r. Use when you just want requirements installed.

    from sagemaker.core.utils.install_requirements import configure_pip, install_requirements
    
  • A standalone script: python install_requirements.py requirements.txt

Functions

configure_pip([auth_method])

Configure pip for CodeArtifact if CA_REPOSITORY_ARN is set.

install_requirements([requirements_file, ...])

Install pip requirements with optional CodeArtifact authentication.

main()

CLI entry point.

Classes

CodeArtifactAuthMethod(value)

Authentication method for CodeArtifact pip configuration.

class sagemaker.core.utils.install_requirements.CodeArtifactAuthMethod(value)[source]#

Bases: Enum

Authentication method for CodeArtifact pip configuration.

AUTO = 'auto'#

Try boto3 first, fall back to AWS CLI, hard-fail if neither is available.

AWS_CLI = 'aws_cli'#

Use AWS CLI only. Fails if AWS CLI is not available.

BOTO3 = 'boto3'#

Use boto3 only. Fails if boto3 is not available.

sagemaker.core.utils.install_requirements.configure_pip(auth_method=CodeArtifactAuthMethod.AUTO)[source]#

Configure pip for CodeArtifact if CA_REPOSITORY_ARN is set.

Parameters:

auth_method – Authentication mechanism to use. Defaults to CodeArtifactAuthMethod.AUTO (try boto3 first, fall back to AWS CLI).

Returns:

An authenticated pip index URL (str) when boto3 succeeds, None when AWS CLI was used (pip config modified globally), or None when CA_REPOSITORY_ARN is not set.

Raises:
  • SystemExit – When CA_REPOSITORY_ARN is set but the requested auth method is not available.

  • ValueError – When the ARN format is invalid.

sagemaker.core.utils.install_requirements.install_requirements(requirements_file='requirements.txt', python_executable=None, auth_method=CodeArtifactAuthMethod.AUTO)[source]#

Install pip requirements with optional CodeArtifact authentication.

Parameters:
  • requirements_file – Path to the requirements file.

  • python_executable – Python executable to use for pip. Defaults to sys.executable.

  • auth_method – Authentication mechanism for CodeArtifact. Defaults to CodeArtifactAuthMethod.AUTO.

sagemaker.core.utils.install_requirements.main()[source]#

CLI entry point.