Skip to content

Examples#

Index > IAM > Examples

Auto-generated documentation for IAM type annotations stubs module mypy-boto3-iam.

Client#

Implicit type annotations#

Can be used with boto3-stubs[iam] package installed.

Write your IAM code as usual, type checking and code completion should work out of the box.

Client method usage example#

# IAMClient usage example

from boto3.session import Session


session = Session()

client = session.client("iam")  # (1)
result = client.add_client_id_to_open_id_connect_provider()  # (2)
  1. client: IAMClient
  2. result: EmptyResponseMetadataTypeDef

Paginator usage example#

# GetAccountAuthorizationDetailsPaginator usage example

from boto3.session import Session


session = Session()
client = session.client("iam")  # (1)

paginator = client.get_paginator("get_account_authorization_details")  # (2)
for item in paginator.paginate(...):
    print(item)  # (3)
  1. client: IAMClient
  2. paginator: GetAccountAuthorizationDetailsPaginator
  3. item: GetAccountAuthorizationDetailsResponseTypeDef

Waiter usage example#

# InstanceProfileExistsWaiter usage example

from boto3.session import Session


session = Session()
client = session.client("iam")  # (1)

waiter = client.get_waiter("instance_profile_exists")  # (2)
waiter.wait(...)
  1. client: IAMClient
  2. waiter: InstanceProfileExistsWaiter

Explicit type annotations#

With boto3-stubs-lite[iam] or a standalone mypy_boto3_iam package, you have to explicitly specify client: IAMClient type annotation.

All other type annotations are optional, as types should be discovered automatically. However, these type annotations can be helpful in your functions and methods.

Client method usage example#

# IAMClient usage example with type annotations

from boto3.session import Session

from mypy_boto3_iam.client import IAMClient
from mypy_boto3_iam.type_defs import EmptyResponseMetadataTypeDef
from mypy_boto3_iam.type_defs import AddClientIDToOpenIDConnectProviderRequestTypeDef


session = Session()

client: IAMClient = session.client("iam")

kwargs: AddClientIDToOpenIDConnectProviderRequestTypeDef = {...}
result: EmptyResponseMetadataTypeDef = client.add_client_id_to_open_id_connect_provider(**kwargs)

Paginator usage example#

# GetAccountAuthorizationDetailsPaginator usage example with type annotations

from boto3.session import Session

from mypy_boto3_iam.client import IAMClient
from mypy_boto3_iam.paginator import GetAccountAuthorizationDetailsPaginator
from mypy_boto3_iam.type_defs import GetAccountAuthorizationDetailsResponseTypeDef


session = Session()
client: IAMClient = session.client("iam")

paginator: GetAccountAuthorizationDetailsPaginator = client.get_paginator("get_account_authorization_details")
for item in paginator.paginate(...):
    item: GetAccountAuthorizationDetailsResponseTypeDef
    print(item)

Waiter usage example#

# InstanceProfileExistsWaiter usage example with type annotations

from boto3.session import Session

from mypy_boto3_iam.client import IAMClient
from mypy_boto3_iam.waiter import InstanceProfileExistsWaiter

session = Session()
client: IAMClient = session.client("iam")

waiter: InstanceProfileExistsWaiter = client.get_waiter("instance_profile_exists")
waiter.wait(...)

Service Resource#

Implicit type annotations#

Can be used with boto3-stubs[iam] package installed.

ServiceResource method usage example#

# IAMServiceResource usage example

from boto3.session import Session


session = Session()

resource = session.resource("iam")  # (1)
result = resource.create_account_password_policy(...)  # (2)
  1. resource: IAMServiceResource
  2. result: AccountPasswordPolicy

Collection usage example#

# ServiceResourceGroupsCollection usage example

from boto3.session import Session


session = Session()
resource = session.resource("iam")  # (1)

collection = resource.groups  # (2)
for item in collection:
    print(item)  # (3)
  1. resource: IAMServiceResource
  2. collection: ServiceResourceGroupsCollection
  3. item: Group

Explicit type annotations#

With boto3-stubs-lite[iam] or a standalone mypy_boto3_iam package, you have to explicitly specify resource: IAMServiceResource type annotation.

All other type annotations are optional, as types should be discovered automatically. However, these type annotations can be helpful in your functions and methods.

ServiceResource method usage example#

# IAMServiceResource usage example with type annotations

from boto3.session import Session

from mypy_boto3_iam.service_resource import IAMServiceResource
from mypy_boto3_iam.service_resource import AccountPasswordPolicy
from mypy_boto3_iam.type_defs import UpdateAccountPasswordPolicyRequestServiceResourceCreateAccountPasswordPolicyTypeDef


session = Session()

resource: IAMServiceResource = session.resource("iam")
kwargs: UpdateAccountPasswordPolicyRequestServiceResourceCreateAccountPasswordPolicyTypeDef = {...}  # (2)
result: AccountPasswordPolicy = resource.create_account_password_policy(**kwargs)
  1. resource: IAMServiceResource
  2. kwargs: UpdateAccountPasswordPolicyRequestServiceResourceCreateAccountPasswordPolicyTypeDef
  3. result: AccountPasswordPolicy

Collection usage example#

# ServiceResourceGroupsCollection usage example with type annotations

from boto3.session import Session

from mypy_boto3_iam.service_resource import IAMServiceResource
from mypy_boto3_iam.service_resource import ServiceResourceGroupsCollection
from mypy_boto3_iam.service_resource import Group


session = Session()

resource: IAMServiceResource = session.resource("iam")  # (1)

collection: ServiceResourceGroupsCollection = resource.groups  # (2)
for item in collection:
    item: Group
    print(item)  # (3)
  1. resource: IAMServiceResource
  2. collection: IAMServiceResource
  3. item: Group