types-aiobotocore-lite
types-aiobotocore-lite provides lite type annotations for the `aiobotocore` library, version 3.4.0. It offers Mypy-compatible stubs for a common subset of AWS services, generated by `mypy-boto3-builder`. The project maintains a frequent release cadence, often aligning with `aiobotocore` and `mypy-boto3-builder` updates.
Common errors
-
error: Missing type parameters for generic type "Client" [type-arg]
cause The type stubs for aiobotocore are not installed or are not being picked up by Mypy.fixEnsure `types-aiobotocore-lite` (or `types-aiobotocore`) is installed and that its version is compatible with your `aiobotocore` version. Mypy should then automatically find the stubs. -
error: "Client" has no attribute "non_existent_method" [attr-defined]
cause Attempting to call a method on an aiobotocore client that does not exist for that specific service, or a typo in the method name. This error indicates that the type stubs are correctly catching potential runtime issues.fixConsult the `aiobotocore` (or Boto3) documentation for the correct method names and parameters for the AWS service you are interacting with. -
ModuleNotFoundError: No module named 'types_aiobotocore_s3_lite'
cause You are trying to import directly from a `types-aiobotocore-lite` specific module at runtime. Type stub packages are not meant for direct runtime imports; they provide `.pyi` files for type checkers.fixYour runtime imports should always come from `aiobotocore` (e.g., `from aiobotocore.session import get_session`). If you need specific type definitions (like `S3Client` for type-checking annotations), wrap them in a `if TYPE_CHECKING:` block, as shown in the quickstart, to prevent runtime import errors.
Warnings
- breaking Python 3.8 support has been removed in versions generated by mypy-boto3-builder 8.12.0 and newer. Ensure your project uses Python 3.9 or newer.
- breaking The `sms-voice` service is no longer supported and has been removed from generated packages. Use `pinpoint-sms-voice` instead.
- breaking TypeDef naming conventions changed in builder 8.9.0, leading to shorter names for packed method arguments and reordered postfixes for conflicting TypeDefs (e.g., `CreateDistributionRequestRequestTypeDef` -> `CreateDistributionRequestTypeDef`).
- gotcha It is crucial to keep the `types-aiobotocore-lite` version aligned with the `aiobotocore` version you are using. Mismatched versions can lead to incorrect type hints or `mypy` errors.
- gotcha `types-aiobotocore-lite` provides type stubs for a *subset* of commonly used AWS services. If you require type hints for a less common service not included in the 'lite' package, you may need to install the full `types-aiobotocore` package or the individual service stub package (e.g., `types-aiobotocore-rekognition`).
Install
-
pip install types-aiobotocore-lite
Imports
- get_session
from aiobotocore.session import get_session
Quickstart
import asyncio
from aiobotocore.session import get_session
from typing import TYPE_CHECKING, Dict, Any
# These imports are for type checking only and won't be executed at runtime
if TYPE_CHECKING:
# Example: S3Client is made available by types-aiobotocore-lite for common services
from types_aiobotocore_s3.client import S3Client
from types_aiobotocore_s3.type_defs import CreateBucketRequestRequestTypeDef, CreateBucketOutputTypeDef
async def create_s3_bucket(bucket_name: str) -> Dict[str, Any]:
session = get_session()
async with session.create_client("s3") as client: # type: S3Client
# Now 'client' is type-checked as S3Client
request_params: CreateBucketRequestRequestTypeDef = {
"Bucket": bucket_name
}
response: CreateBucketOutputTypeDef = await client.create_bucket(**request_params)
print(f"Bucket '{bucket_name}' created: {response}")
return response
async def main():
# Replace with a unique bucket name, AWS credentials must be configured
await create_s3_bucket("my-unique-test-bucket-12345")
if __name__ == "__main__":
# Make sure AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY are set in your environment
# or ~/.aws/credentials is configured.
asyncio.run(main())