Skip to content

Examples#

Index > SecretsManager > Examples

Auto-generated documentation for SecretsManager type annotations stubs module mypy-boto3-secretsmanager.

Client#

Implicit type annotations#

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

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

# SecretsManagerClient usage example

from boto3.session import Session


session = Session()

client = session.client("secretsmanager")  # (1)
result = client.batch_get_secret_value()  # (2)
  1. client: SecretsManagerClient
  2. result: BatchGetSecretValueResponseTypeDef
# ListSecretsPaginator usage example

from boto3.session import Session


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

paginator = client.get_paginator("list_secrets")  # (2)
for item in paginator.paginate(...):
    print(item)  # (3)
  1. client: SecretsManagerClient
  2. paginator: ListSecretsPaginator
  3. item: ListSecretsResponseTypeDef

Explicit type annotations#

With boto3-stubs-lite[secretsmanager] or a standalone mypy_boto3_secretsmanager package, you have to explicitly specify client: SecretsManagerClient 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.

# SecretsManagerClient usage example with type annotations

from boto3.session import Session

from mypy_boto3_secretsmanager.client import SecretsManagerClient
from mypy_boto3_secretsmanager.type_defs import BatchGetSecretValueResponseTypeDef
from mypy_boto3_secretsmanager.type_defs import BatchGetSecretValueRequestRequestTypeDef


session = Session()

client: SecretsManagerClient = session.client("secretsmanager")

kwargs: BatchGetSecretValueRequestRequestTypeDef = {...}
result: BatchGetSecretValueResponseTypeDef = client.batch_get_secret_value(**kwargs)
# ListSecretsPaginator usage example with type annotations

from boto3.session import Session

from mypy_boto3_secretsmanager.client import SecretsManagerClient
from mypy_boto3_secretsmanager.paginator import ListSecretsPaginator
from mypy_boto3_secretsmanager.type_defs import ListSecretsResponseTypeDef


session = Session()
client: SecretsManagerClient = session.client("secretsmanager")

paginator: ListSecretsPaginator = client.get_paginator("list_secrets")
for item in paginator.paginate(...):
    item: ListSecretsResponseTypeDef
    print(item)