Type Annotations for Boto3 IAM
types-boto3-iam provides comprehensive type annotations for the AWS Identity and Access Management (IAM) service client within the `boto3` library. This package is generated by `mypy-boto3-builder` and aims to enhance static analysis, autocompletion, and error detection in IDEs and linters like MyPy and Pyright, ensuring type safety for `boto3` IAM operations. It is actively maintained with frequent updates reflecting `boto3` versions.
Warnings
- breaking Starting with `mypy-boto3-builder` version 8.12.0 (which generates these stubs), Python 3.8 is no longer supported. Users on Python 3.8 should upgrade their Python version or use an older stub version.
- breaking Version 8.9.0 of `mypy-boto3-builder` introduced breaking changes in TypeDef naming conventions, potentially affecting explicit imports of generated type definitions (e.g., `CreateDistributionRequestRequestTypeDef` became `CreateDistributionRequestTypeDef`).
- gotcha These are separate stub packages; `boto3` itself does not include these type annotations. You must install `types-boto3-iam` alongside `boto3` for type checking to function correctly.
- gotcha When using Pylint, it might complain about undefined variables if types-boto3-iam is imported only for type checking. A common workaround is to use a `if TYPE_CHECKING:` guard.
- gotcha PyCharm users might experience slow performance with Literal overloads. For better IDE performance, consider using `types-boto3-lite` variants (e.g., `types-boto3-lite-iam`) if explicit type annotations are acceptable.
Install
-
pip install types-boto3-iam -
pip install 'types-boto3[iam]'
Imports
- IAMClient
from types_boto3_iam import IAMClient
- IAMServiceResource
from types_boto3_iam import IAMServiceResource
- CreateUserRequestRequestTypeDef
from types_boto3_iam.type_defs import CreateUserRequestRequestTypeDef
Quickstart
import boto3
from boto3.session import Session
from types_boto3_iam import IAMClient
# Instantiate a boto3 session and client
session: Session = boto3.session.Session()
iam_client: IAMClient = session.client("iam")
# Example usage with type-hinted client
# (Note: In a real scenario, use proper error handling and credential management)
try:
response = iam_client.list_users(MaxItems=1)
for user in response.get('Users', []):
print(f"IAM User: {user['UserName']} (ARN: {user['Arn']})")
except Exception as e:
print(f"Error listing users: {e}")