mypy-boto3-glacier Type Stubs
mypy-boto3-glacier provides a complete set of type annotations (stubs) for the AWS Boto3 Glacier service. These stubs enhance developer experience by enabling static type checking with tools like mypy, and providing improved autocomplete in IDEs for Glacier client, resource, paginator, waiter, and type definitions. It is generated by the `mypy-boto3-builder` project and is currently at version 1.42.30, reflecting a close alignment with `boto3`'s release cycle, ensuring frequent updates for new AWS features and API changes.
Warnings
- breaking Support for Python 3.8 was removed in `mypy-boto3-builder` version 8.12.0. Projects using Python 3.8 will need to upgrade their Python version or pin `mypy-boto3-glacier` to a version prior to 8.12.0.
- breaking The project migrated to PEP 561 packages in `mypy-boto3-builder` version 8.12.0. This change improves how type checkers like mypy discover and utilize stub files, but might require updates to custom build scripts or environments not adhering to standard package installation practices.
- breaking Starting with `mypy-boto3-builder` 8.9.0, there were breaking changes in how TypeDefs for packed method arguments are named, e.g., `CreateDistributionRequestRequestTypeDef` was shortened to `CreateDistributionRequestTypeDef`. While the example is for another service, this change affects all generated `TypeDef`s across services.
- gotcha When using `mypy-boto3-glacier` or `boto3-stubs`, it is often necessary to explicitly annotate the return type of `boto3.client()` calls (e.g., `client: GlacierClient = boto3.client(...)`) for optimal IDE autocomplete and static analysis, especially in VSCode.
- gotcha The `mypy-boto3` project (the original name) was moved to a separate product and is no longer generated alongside `boto3-stubs` since `mypy-boto3-builder` 8.9.0. Users upgrading from very old `mypy-boto3` installations might need to switch to `boto3-stubs` or `mypy-boto3-glacier` directly.
Install
-
pip install mypy-boto3-glacier -
pip install 'boto3-stubs[glacier]'
Imports
- GlacierClient
from mypy_boto3_glacier.client import GlacierClient
- GlacierServiceResource
from mypy_boto3_glacier.service_resource import GlacierServiceResource
- ArchiveInformationTypeDef
from mypy_boto3_glacier.type_defs import ArchiveInformationTypeDef
Quickstart
import boto3
from mypy_boto3_glacier.client import GlacierClient
from mypy_boto3_glacier.type_defs import CreateVaultOutputTypeDef
import os
def get_glacier_client() -> GlacierClient:
# Using explicit type annotation for better IDE support and static analysis
client: GlacierClient = boto3.client(
"glacier",
region_name=os.environ.get('AWS_REGION', 'us-east-1'),
aws_access_key_id=os.environ.get('AWS_ACCESS_KEY_ID', ''),
aws_secret_access_key=os.environ.get('AWS_SECRET_ACCESS_KEY', '')
)
return client
def create_glacier_vault(client: GlacierClient, vault_name: str) -> CreateVaultOutputTypeDef:
response: CreateVaultOutputTypeDef = client.create_vault(vaultName=vault_name)
return response
if __name__ == '__main__':
glacier_client = get_glacier_client()
# Example of type-hinted usage
try:
vault_info = create_glacier_vault(glacier_client, "my-typed-vault")
print(f"Vault created: {vault_info.get('location')}")
except glacier_client.exceptions.ResourceAlreadyExistsException:
print("Vault already exists.")
except Exception as e:
print(f"An error occurred: {e}")