Type annotations for aioboto3
types-aioboto3 provides comprehensive type annotations (stubs) for the aioboto3 library, enabling static type checking for asynchronous AWS client operations with tools like Mypy. It's generated by mypy-boto3-builder and aligns with aioboto3 and AWS service changes. The current version is 15.5.0, with frequent updates.
Warnings
- breaking As of mypy-boto3-builder 8.12.0 (which generates types-aioboto3), Python 3.8 is no longer supported for any generated packages. Users on Python 3.8 will encounter issues with newer versions.
- breaking Service-specific TypeDef names for method arguments and conflicting names were changed in mypy-boto3-builder 8.9.0. For example, `CreateDistributionRequestRequestTypeDef` became `CreateDistributionRequestTypeDef`, and `CreateDistributionExtraRequestTypeDef` became `CreateDistributionRequestExtraTypeDef`.
- deprecated The `sms-voice` service stubs were removed in mypy-boto3-builder 8.11.0. Users should migrate to `pinpoint-sms-voice` for related functionality.
- gotcha This library provides type stubs for `aioboto3` and does not include the `aioboto3` runtime itself. It's solely for static type checking; you must install `aioboto3` separately for your application to run.
- gotcha Even if you install the `types-aioboto3` metapackage (which includes all service stubs), the type hints (e.g., Client classes, TypeDefs) must be imported from their respective service-specific sub-packages (e.g., `types_aioboto3_s3`).
- gotcha It is recommended to keep the version of `types-aioboto3` (or its service-specific sub-packages) synchronized with your `aioboto3` runtime version to ensure accurate type hints, as stubs are generated for specific `aioboto3` versions and AWS API shapes.
Install
-
pip install types-aioboto3 -
pip install types-aioboto3-s3 types-aioboto3-ec2
Imports
- S3Client
from types_aioboto3_s3.client import S3Client
- BucketTypeDef
from types_aioboto3_s3.type_defs import BucketTypeDef
- Session
import aioboto3
Quickstart
import aioboto3
import asyncio
from types_aioboto3_s3.client import S3Client
from types_aioboto3_s3.type_defs import BucketTypeDef
async def list_s3_buckets_typed():
session = aioboto3.Session()
async with session.client("s3") as client:
# Type hint the client to enable autocompletion and static checks
client: S3Client
response = await client.list_buckets()
# Type hint the list of buckets for better type safety
buckets: list[BucketTypeDef] = response.get("Buckets", [])
if not buckets:
print("No S3 buckets found or access denied.")
return
print("S3 Buckets:")
for bucket in buckets:
print(f" - {bucket['Name']}")
async def main():
# aioboto3 uses standard AWS credential chain (e.g., environment variables,
# ~/.aws/credentials, IAM roles). No hardcoded keys are needed here.
await list_s3_buckets_typed()
if __name__ == "__main__":
asyncio.run(main())