Type Annotations for aiobotocore STS

3.4.0 · active · verified Tue Apr 14

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

Install

Imports

Quickstart

This example demonstrates how to use `types-aiobotocore-sts` to add static type checking to your `aiobotocore` STS client. The `STSClient` and `GetCallerIdentityResponseTypeDef` are imported under `TYPE_CHECKING` to ensure they are only used during type analysis, avoiding a runtime dependency if desired. When running, `aiobotocore` will automatically pick up AWS credentials from standard locations (environment variables, `~/.aws/credentials`).

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())

view raw JSON →