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.

# 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
# 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
# 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.

# 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 AddClientIDToOpenIDConnectProviderRequestRequestTypeDef


session = Session()

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

kwargs: AddClientIDToOpenIDConnectProviderRequestRequestTypeDef = {...}
result: EmptyResponseMetadataTypeDef = client.add_client_id_to_open_id_connect_provider(**kwargs)
# 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)
# 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.

# IAMServiceResource usage example

from boto3.session import Session


session = Session()

resource = session.resource("iam")  # (1)
result = resource.get_available_subresources()  # (2)
  1. resource: IAMServiceResource
  2. result:
# 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: IAMServiceResource
  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.

# 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 get_available_subresources


session = Session()

resource: IAMServiceResource = session.resource("iam")
result: get_available_subresources = resource.get_available_subresources()
# 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")

collection: ServiceResourceGroupsCollection = resource.groups
for item in collection:
    item: Group
    print(item)