{"id":902,"library":"mypy-boto3-sts","title":"Type annotations for boto3 STS","description":"mypy-boto3-sts provides PEP 561-compliant type annotations for the `boto3` STS (AWS Security Token Service) client, compatible with mypy, pyright, VSCode, PyCharm, and other type-checking tools. It ensures type safety and offers enhanced code completion for `boto3.client(\"sts\")` operations. The current version, 1.42.3, aligns with boto3 1.42.3 and is generated by mypy-boto3-builder 8.12.0. The library follows the release cadence of `boto3` and its builder.","status":"active","version":"1.42.3","language":"python","source_language":"en","source_url":"https://github.com/youtype/mypy_boto3_builder","tags":["type-hints","boto3","aws","sts","mypy"],"install":[{"cmd":"pip install mypy-boto3-sts boto3","lang":"bash","label":"Install with pip"}],"dependencies":[{"reason":"Provides the underlying AWS SDK for which type annotations are generated.","package":"boto3"},{"reason":"Required for certain type features on older Python versions, though less critical for Python 3.9+.","package":"typing-extensions","optional":true}],"imports":[{"note":"Imports the type for the STS client returned by `boto3.client(\"sts\")`.","symbol":"STSClient","correct":"from mypy_boto3_sts.client import STSClient"},{"note":"Imports a TypedDict representing the structure of the `assume_role` response for precise type checking.","symbol":"AssumeRoleResponseTypeDef","correct":"from mypy_boto3_sts.type_defs import AssumeRoleResponseTypeDef"}],"quickstart":{"code":"import boto3\nfrom mypy_boto3_sts.client import STSClient\nfrom mypy_boto3_sts.type_defs import AssumeRoleResponseTypeDef\nfrom os import environ\n\n# Instantiate a boto3 session and an STS client, with explicit type hinting.\n# In a real scenario, boto3 would pick up credentials from environment variables,\n# shared credential files, or IAM roles.\nsession = boto3.Session()\nclient: STSClient = session.client(\"sts\")\n\ntry:\n    # Example: Assume a role with type-hinted arguments and response.\n    # Replace 'YOUR_ROLE_ARN' with an actual AWS IAM Role ARN for testing.\n    role_arn = environ.get(\"AWS_STS_ROLE_ARN\", \"arn:aws:iam::123456789012:role/MyTestRole\")\n    \n    response: AssumeRoleResponseTypeDef = client.assume_role(\n        RoleArn=role_arn,\n        RoleSessionName=\"MySessionName\",\n        DurationSeconds=900  # Minimum duration is 900 seconds (15 minutes)\n    )\n\n    print(\"Successfully assumed role.\")\n    print(f\"Assumed Role User ARN: {response['AssumedRoleUser']['Arn']}\")\n    print(f\"Credentials Expiration: {response['Credentials']['Expiration']}\")\nexcept client.exceptions.ClientError as e:\n    print(f\"AWS Client Error: {e}\")\nexcept Exception as e:\n    print(f\"An unexpected error occurred: {e}\")","lang":"python","description":"This quickstart demonstrates how to apply `mypy-boto3-sts` type hints to a `boto3` STS client and an `assume_role` call. It shows importing the `STSClient` type for the client object and a `TypeDef` for the method's response, enabling static analysis and IDE auto-completion. Remember to configure AWS credentials for `boto3` to function."},"warnings":[{"fix":"Upgrade to Python 3.9 or newer.","message":"Starting with `mypy-boto3-builder` 8.12.0 (which generates this package), support for Python 3.8 has been removed. Users on Python 3.8 should update their Python version.","severity":"breaking","affected_versions":">=8.12.0 of mypy-boto3-builder (affecting mypy-boto3-sts 1.42.3 and newer)"},{"fix":"Update import paths and type references to the new, shorter TypedDict names.","message":"TypedDict names for 'packed' method arguments may have changed, becoming shorter (e.g., `CreateDistributionRequestRequestTypeDef` became `CreateDistributionRequestTypeDef`). This was part of `mypy-boto3-builder` 8.9.0.","severity":"breaking","affected_versions":">=8.9.0 of mypy-boto3-builder (affecting generated packages)"},{"fix":"Add explicit type annotations like `client: STSClient = session.client(\"sts\")`.","message":"For optimal IDE support (especially VSCode) and `mypy` accuracy, it is recommended to explicitly annotate `boto3.client()` calls with the `STSClient` type, even though auto-discovery works for basic cases in tools like PyCharm.","severity":"gotcha","affected_versions":"All"},{"fix":"Wrap type-only imports in `if TYPE_CHECKING:` blocks and define fallback `object` aliases for runtime compatibility (see `mypy-boto3` documentation for examples).","message":"When using `mypy-boto3-sts` with Pylint, you might encounter 'undefined variable' warnings if the type stubs are not installed in the production environment. A common workaround is to use `if TYPE_CHECKING:` blocks.","severity":"gotcha","affected_versions":"All"},{"fix":"Ensure AWS credentials are properly configured in the environment (e.g., environment variables like `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, shared credential files like `~/.aws/credentials`, or IAM roles/profiles for EC2/ECS/EKS). Refer to the `boto3` documentation for credential configuration methods.","message":"Runtime operations with `boto3` (and by extension, `mypy-boto3` usage) require valid AWS credentials to be configured. This error indicates that `boto3` could not find any credentials in the standard locations.","severity":"breaking","affected_versions":"All"},{"fix":"Ensure `boto3` is installed and properly configured with AWS credentials (e.g., via environment variables like `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, a shared credentials file, or IAM roles).","message":"Runtime errors related to missing AWS credentials can occur if `boto3` is not configured properly, as `mypy-boto3-sts` provides only type stubs and relies on `boto3` for actual runtime functionality.","severity":"breaking","affected_versions":"All"}],"env_vars":null,"search_vec":"'1.42.3':53,57 '561':12 '8.12.0':66 'align':54 'annot':2,15 'aw':20,82 'boto3':4,8,18,56,64,74,81 'boto3.client':47 'builder':65,77 'cadenc':72 'check':35 'client':24 'code':44 'compat':25 'complet':45 'compliant':13 'current':51 'enhanc':43 'ensur':38 'follow':69 'generat':60 'hint':80 'librari':68 'mypi':7,27,63,84 'mypy-boto3-builder':62 'mypy-boto3-sts':6 'offer':42 'oper':49 'pep':11 'provid':10 'pycharm':30 'pyright':28 'releas':71 'safeti':40 'secur':21 'servic':23 'sts':5,9,19,48,83 'token':22 'tool':36 'type':1,14,34,39,79 'type-check':33 'type-hint':78 'version':52 'vscode':29","created_at":"2026-03-29T06:06:57.391164+00:00","updated_at":"2026-04-16T17:15:16.536420+00:00","problems":{"verify_error":"error: Failed to parse: `mypy-boto3-sts boto3`\n  Caused by: Expected one of `@`, `(`, `<`, `=`, `>`, `~`, `!`, `;`, found `b`\nmypy-boto3-sts boto3\n               ^"},"ecosystem":"pypi","meta_description":null,"install_score":100,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"1.43.0","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/youtype/mypy_boto3_builder","docs":"https://youtype.github.io/boto3_stubs_docs/mypy_boto3_sts/","changelog":null,"pypi":"https://pypi.org/project/mypy-boto3-sts/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["type-stubs","aws"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"install_fail","verified_at":"2026-06-28","last_verified":"2026-06-28","next_check":"2026-07-05","install_tag":"verified"}}