mypy-boto3-identitystore Type Annotations
mypy-boto3-identitystore provides type annotations for the boto3 IdentityStore service, currently at version 1.42.20. It is part of the larger `boto3-stubs` ecosystem, generated with `mypy-boto3-builder`. This active project releases frequently, often aligning with `boto3` and `botocore` updates, offering enhanced type checking capabilities for tools like MyPy and Pyright, and improved auto-completion in IDEs such as VSCode and PyCharm.
Warnings
- breaking Removed support for Python 3.8. All `mypy-boto3` packages generated by `mypy-boto3-builder` version 8.12.0 and later (which includes this package version) no longer support Python 3.8.
- breaking Breaking changes to generated TypeDef names occurred in `mypy-boto3-builder` 8.9.0. If you explicitly import and use generated TypeDefs, their names might have changed (e.g., shorter names for packed method arguments, or `Extra` postfix moved).
- gotcha Version compatibility with `boto3`. `mypy-boto3-identitystore` versions are typically tied to specific `boto3` versions. Mismatching the stub package version with your installed `boto3` version can lead to incorrect type hints or missing attributes during type checking, even if the runtime code works.
- gotcha This is a stub-only package (PEP 561). It provides type hints for `boto3` but contains no runtime code. Installing it without `boto3` (the actual AWS SDK) or a type checker will not provide any functional benefits or runtime changes.
- gotcha Explicit type annotations might be required for full IDE support, especially with `boto3-stubs-lite` or older PyCharm versions. While modern type checkers and IDEs often auto-discover types, some setups may require explicit `client: IdentityStoreClient = boto3.client(...)` annotations.
Install
-
pip install mypy-boto3-identitystore -
pip install 'boto3-stubs[identitystore]'
Imports
- IdentityStoreClient
from mypy_boto3_identitystore.client import IdentityStoreClient
Quickstart
import boto3
from mypy_boto3_identitystore.client import IdentityStoreClient
from os import environ
# Configure AWS credentials and region (e.g., via environment variables or ~/.aws/credentials)
# For a runnable example, we'll use os.environ.get for safe execution.
# Explicitly type the client for mypy/IDE assistance
def get_identitystore_client() -> IdentityStoreClient:
client: IdentityStoreClient = boto3.client(
"identitystore",
region_name=environ.get('AWS_REGION', 'us-east-1')
)
return client
# Example usage
if __name__ == "__main__":
try:
identitystore_client = get_identitystore_client()
# Replace with a real IdentityStore ID from your AWS account
identity_store_id = environ.get('IDENTITY_STORE_ID', 'd-xxxxxxxxxx')
# Example: List users (requires appropriate permissions)
# Note: This operation might require an actual IdentityStore ID to succeed.
response = identitystore_client.list_users(IdentityStoreId=identity_store_id)
print("Successfully listed IdentityStore users (first page).")
for user in response.get('Users', []):
print(f" User ID: {user.get('UserId')}, UserName: {user.get('UserName')}")
# Demonstrating a method that doesn't exist on BaseClient but does on IdentityStoreClient
# This would be flagged by a type checker without the stub.
# identitystore_client.non_existent_method() # Mypy error: "IdentityStoreClient" has no attribute "non_existent_method"
except Exception as e:
print(f"An error occurred: {e}")
print("Please ensure 'boto3' is installed, AWS credentials are configured, and IDENTITY_STORE_ID is set if needed.")