Type Annotations for aiobotocore STS
This library provides type annotations for the `aiobotocore` STS (Security Token Service) client, currently at version 3.4.0. Generated by `mypy-boto3-builder 8.12.0`, it enables static type checking with tools like MyPy and PyRight, and offers enhanced IDE auto-completion for `aiobotocore`'s asynchronous AWS client, covering STS client methods, literals, and type definitions.
Warnings
- breaking Support for Python 3.8 was removed starting with `mypy-boto3-builder 8.12.0` (which generated `types-aiobotocore-sts 3.4.0`). Projects using Python 3.8 will need to upgrade to Python 3.9 or later.
- gotcha `types-aiobotocore-sts` is a 'stubs only' package. It provides type annotations but does not install `aiobotocore` itself or any other runtime dependencies. Your project must explicitly install `aiobotocore` (e.g., `pip install aiobotocore`) for the code to run.
- gotcha For optimal type checking, the version of `types-aiobotocore-sts` should ideally match or be compatible with your installed `aiobotocore` version. Mismatched versions might lead to incorrect or missing type hints, especially after significant AWS API changes.
- gotcha When using `Pylint` with type annotations imported under `typing.TYPE_CHECKING`, Pylint might report 'undefined variables'. The recommended workaround is to explicitly set the type-hinted variables to `object` in the `else` branch of the `TYPE_CHECKING` block.
Install
-
pip install types-aiobotocore-sts -
pip install 'types-aiobotocore[sts]'
Imports
- STSClient
from types_aiobotocore_sts.client import STSClient
- STSServiceName
from types_aiobotocore_sts.literals import STSServiceName
- AssumeRoleResponseTypeDef
from types_aiobotocore_sts.type_defs import AssumeRoleResponseTypeDef
Quickstart
import asyncio
from typing import TYPE_CHECKING
from aiobotocore.session import get_session
# Recommended: Import types only for type checking
if TYPE_CHECKING:
from types_aiobotocore_sts.client import STSClient
from types_aiobotocore_sts.type_defs import GetCallerIdentityResponseTypeDef
async def get_aws_caller_identity():
session = get_session()
async with session.create_client("sts") as client:
# Explicit type annotation for client for best IDE support
if TYPE_CHECKING:
client: STSClient
print("Getting caller identity...")
response: GetCallerIdentityResponseTypeDef = await client.get_caller_identity()
print(f"AWS Account: {response.get('Account')}")
print(f"AWS User ARN: {response.get('Arn')}")
if __name__ == "__main__":
# This example requires valid AWS credentials configured (e.g., via environment variables or ~/.aws/credentials)
# It does not explicitly use os.environ.get for credentials, assuming aiobotocore handles it.
asyncio.run(get_aws_caller_identity())