mypy-boto3-sso Type Stubs for AWS SSO Service
mypy-boto3-sso provides type annotations for the AWS Single Sign-On (SSO) service client in `boto3`. It enhances development with static type checking for `boto3` resources, clients, and responses, catching potential errors at development time. The current version is 1.42.3, and it follows a frequent release cadence, often aligning with `boto3`/`botocore` updates and `mypy-boto3-builder` releases.
Warnings
- breaking Starting with `mypy-boto3-builder` version 8.12.0 (which generates `mypy-boto3-sso` and other service packages), support for Python 3.8 was removed. This means `mypy-boto3-sso` versions generated by builder 8.12.0 or later (including the current 1.42.3) require Python 3.9 or newer.
- gotcha `mypy-boto3-sso` provides only type stubs; it does not include the `boto3` library itself. You must install `boto3` separately for your application to function.
- gotcha For optimal type checking, the version of `mypy-boto3-sso` should ideally match the version of `boto3` you are using. Significant mismatches can lead to incorrect type hints or undetected issues.
- gotcha The `mypy-boto3-builder` (which generates this package) migrated to PEP 561-compliant packaging in version 8.12.0. While largely internal, this change might affect specific build systems or tools that interact directly with Python packaging metadata, potentially requiring updates to those systems.
Install
-
pip install mypy-boto3-sso
Imports
- SSOClient
from mypy_boto3_sso.client import SSOClient
- GetRoleCredentialsResponseTypeDef
from mypy_boto3_sso.type_defs import GetRoleCredentialsResponseTypeDef
Quickstart
import boto3
import os
from mypy_boto3_sso.client import SSOClient
from mypy_boto3_sso.type_defs import GetRoleCredentialsResponseTypeDef
# Ensure boto3 is installed and configured (e.g., via AWS CLI or env vars)
# You might need to set AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION
# or use SSO login methods. For this example, we assume SSO token is available.
# Explicitly type the SSO client
sso_client: SSOClient = boto3.client("sso", region_name="us-east-1")
# Replace with your actual SSO details
ROLE_NAME = os.environ.get("SSO_ROLE_NAME", "YourSSORole")
ACCOUNT_ID = os.environ.get("SSO_ACCOUNT_ID", "123456789012")
ACCESS_TOKEN = os.environ.get("SSO_ACCESS_TOKEN", "your_sso_access_token_here") # Typically obtained from AWS CLI sso login
try:
# Call a method and type hint its response
response: GetRoleCredentialsResponseTypeDef = sso_client.get_role_credentials(
roleName=ROLE_NAME,
accountId=ACCOUNT_ID,
accessToken=ACCESS_TOKEN
)
print(f"Successfully retrieved role credentials for {ROLE_NAME} in account {ACCOUNT_ID}:")
print(f" Access Key ID: {response['roleCredentials']['accessKeyId']}")
# Note: sensitive information like secretKey and sessionToken should be handled securely
# print(f" Secret Key: {response['roleCredentials']['secretAccessKey']}")
# print(f" Session Token: {response['roleCredentials']['sessionToken']}")
print(f" Expiration: {response['roleCredentials']['expirationDate']}")
except sso_client.exceptions.InvalidRequestException as e:
print(f"Error: Invalid request - {e}")
except Exception as e:
print(f"An unexpected error occurred: {e}")