Type annotations for aiobotocore IAM

3.4.0 · active · verified Thu Apr 16

types-aiobotocore-iam provides comprehensive type annotations for the `aiobotocore` AWS IAM service, enhancing static type checking with tools like MyPy, Pyright, and improving IDE auto-completion. This package, currently at version 3.4.0, is generated by `mypy-boto3-builder` and follows the `aiobotocore` release cycle, ensuring frequent updates to match new AWS service features and API changes. [7, 19]

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `types-aiobotocore-iam` to provide type hints for an `aiobotocore` IAM client. It shows importing the `IAMClient` and a response `TypeDef` within a `TYPE_CHECKING` block for static analysis, then uses it to list IAM users.

import asyncio
from typing import TYPE_CHECKING

from aiobotocore.session import get_session

# Import type stubs only during type checking to avoid runtime dependencies
if TYPE_CHECKING:
    from types_aiobotocore_iam.client import IAMClient
    from types_aiobotocore_iam.type_defs import ListUsersResponseTypeDef

async def list_iam_users():
    session = get_session()
    async with session.create_client("iam") as client:
        # Explicitly hint the client type for better IDE support
        client: IAMClient = client

        print("Listing IAM users...")
        try:
            # Type-hint the response for static analysis and auto-completion
            response: ListUsersResponseTypeDef = await client.list_users()
            for user in response.get("Users", []):
                print(f"  User: {user.get('UserName')} (ARN: {user.get('Arn')})")
        except Exception as e:
            print(f"Error listing users: {e}")

if __name__ == "__main__":
    # This example requires valid AWS credentials configured in the environment
    # or ~/.aws/credentials. Ensure your IAM user has 'iam:ListUsers' permission.
    asyncio.run(list_iam_users())

view raw JSON →