{"id":1755,"library":"types-boto3","title":"Type annotations for boto3","description":"types-boto3 provides comprehensive type annotations (stubs) for the boto3 library, enabling static type checkers like MyPy to validate usage of AWS services. It is generated by the mypy-boto3-builder project and is currently at version 1.42.85. New versions are released frequently, typically mirroring boto3 updates or adding builder improvements.","status":"active","version":"1.42.85","language":"en","source_language":"en","source_url":"https://github.com/youtype/mypy_boto3_builder","tags":["python","types","boto3","aws","mypy","static-analysis","type-hinting"],"install":[{"cmd":"pip install types-boto3","lang":"bash","label":"Install all service stubs"},{"cmd":"pip install types-boto3-s3 types-boto3-ec2","lang":"bash","label":"Install specific service stubs (recommended)"}],"dependencies":[{"reason":"types-boto3 provides type hints for boto3, so boto3 is required for actual runtime functionality. It is not a direct runtime dependency of the stubs package itself.","package":"boto3","optional":false}],"imports":[{"note":"Import specific client types from the service stub package.","symbol":"S3Client","correct":"from types_boto3_s3.client import S3Client"},{"note":"The Session type is part of boto3 itself and not usually in types-boto3 (except for some specific cases like aioboto3 session stubs).","symbol":"Session","correct":"from boto3.session import Session"},{"note":"Import TypeDef dictionaries for specific service operations.","symbol":"BucketTypeDef","correct":"from types_boto3_s3.type_defs import BucketTypeDef"}],"quickstart":{"code":"import boto3\nfrom typing import TYPE_CHECKING\n\n# It's good practice to guard stub imports for runtime environments\nif TYPE_CHECKING:\n    from types_boto3_s3.client import S3Client\n    from types_boto3_s3.type_defs import BucketTypeDef\n\n\ndef list_s3_buckets(client: \"S3Client\") -> list[\"BucketTypeDef\"]:\n    response = client.list_buckets()\n    return response.get(\"Buckets\", [])\n\n\nif __name__ == \"__main__\":\n    # In a real application, you'd configure credentials/region\n    # via environment variables or ~/.aws/credentials\n    s3_client: S3Client = boto3.client(\"s3\")\n    buckets = list_s3_buckets(s3_client)\n    print(f\"Found {len(buckets)} S3 buckets.\")\n    for bucket in buckets:\n        print(f\"- {bucket['Name']}\")","lang":"python","description":"This example demonstrates how to type-hint a boto3 S3 client using `types-boto3-s3` stubs. The `TYPE_CHECKING` block ensures that stub imports are only processed by type checkers and don't introduce runtime dependencies."},"warnings":[{"fix":"Upgrade to Python 3.9 or higher. For older Python versions, use an earlier version of `mypy-boto3-builder` (e.g., <8.12.0) or `types-boto3`.","message":"Python 3.8 support was removed for all `mypy-boto3-builder` generated packages, including `types-boto3`.","severity":"breaking","affected_versions":"8.12.0+"},{"fix":"Update your type annotations to use the new TypeDef names. Consult the `mypy-boto3-builder` release notes or generated stubs for specific changes.","message":"Some TypeDef names were changed for brevity or to resolve conflicts (e.g., `CreateDistributionRequestRequestTypeDef` to `CreateDistributionRequestTypeDef`, `CreateDistributionExtraRequestTypeDef` to `CreateDistributionRequestExtraTypeDef`).","severity":"breaking","affected_versions":"8.9.0+"},{"fix":"Migrate your code and type annotations to use the `pinpoint-sms-voice` service instead. Install `types-boto3-pinpoint-sms-voice`.","message":"The `sms-voice` service stubs were removed and are no longer generated. Users should migrate to `pinpoint-sms-voice`.","severity":"breaking","affected_versions":"8.11.0+"},{"fix":"Prefer installing specific service stubs (e.g., `pip install types-boto3-s3 types-boto3-ec2`) for better performance, smaller dependency trees, and faster type-checking.","message":"Installing `types-boto3` will install stubs for *all* AWS services, leading to a larger installation size and more dependencies than often necessary.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always install `boto3` (`pip install boto3`) in addition to the type stubs.","message":"Ensure `boto3` is installed alongside `types-boto3`. `types-boto3` only provides type hints and does not include the runtime library itself.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}