{"id":3369,"library":"mypy-boto3-lightsail","title":"mypy-boto3-lightsail Type Stubs for AWS Lightsail","description":"mypy-boto3-lightsail provides type annotations (stubs) for the AWS Lightsail service within the `boto3` library. It enables static type checking with tools like MyPy, enhancing code quality, readability, and error detection for `boto3` interactions before runtime. The library is actively maintained, with frequent releases often synchronized with `boto3` updates, and is currently at version 1.42.84.","status":"active","version":"1.42.84","language":"en","source_language":"en","source_url":"https://github.com/youtype/mypy_boto3_builder","tags":["aws","boto3","mypy","type-hints","lightsail","stubs","static analysis","cloud"],"install":[{"cmd":"pip install mypy-boto3-lightsail boto3 mypy","lang":"bash","label":"Install with pip"}],"dependencies":[{"reason":"Provides the actual AWS SDK runtime functionality; mypy-boto3-lightsail only provides type stubs.","package":"boto3","optional":false},{"reason":"The static type checker that utilizes these type stubs.","package":"mypy","optional":false},{"reason":"Required for some type features on older Python versions (pre-3.9), though typically auto-managed.","package":"typing-extensions","optional":true}],"imports":[{"symbol":"LightsailClient","correct":"from mypy_boto3_lightsail.client import LightsailClient"},{"symbol":"CreateDistributionRequestTypeDef","correct":"from mypy_boto3_lightsail.type_defs import CreateDistributionRequestTypeDef"},{"note":"Without explicit type annotation, static type checkers cannot infer the specific LightsailClient type, limiting autocompletion and error checking. Always add a type hint: `client: LightsailClient = boto3.client('lightsail')`.","wrong":"client = boto3.client('lightsail')","symbol":"boto3.client('lightsail')"}],"quickstart":{"code":"import boto3\nfrom typing import TYPE_CHECKING\nfrom mypy_boto3_lightsail.client import LightsailClient\nfrom mypy_boto3_lightsail.type_defs import GetDistributionsResultTypeDef\nimport os\n\n# Ensure boto3 is installed: pip install boto3 mypy-boto3-lightsail\n\nif TYPE_CHECKING:\n    # This block is only processed by type checkers\n    client: LightsailClient = boto3.client(\"lightsail\")\nelse:\n    # This block runs at runtime\n    client = boto3.client(\"lightsail\")\n\ndef get_lightsail_distributions() -> GetDistributionsResultTypeDef:\n    try:\n        response = client.get_distributions()\n        print(f\"Successfully retrieved {len(response.get('distributions', []))} distributions.\")\n        return response\n    except Exception as e:\n        print(f\"Error retrieving Lightsail distributions: {e}\")\n        raise\n\nif __name__ == \"__main__\":\n    # Make sure your AWS credentials are configured (e.g., via AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION_NAME env vars)\n    # For a quick local test without actual AWS interaction, you can mock boto3 or ensure credentials are set.\n    # Example of calling the function:\n    # distributions = get_lightsail_distributions()\n    # if distributions:\n    #     for dist in distributions.get('distributions', []):\n    #         print(f\"  Distribution: {dist.get('name')}, Status: {dist.get('status')}\")\n    print(\"Quickstart example set up. Run `mypy <filename>.py` for type checking.\")\n    print(\"To execute, uncomment `get_lightsail_distributions()` call and ensure AWS credentials are set.\")","lang":"python","description":"This quickstart demonstrates how to use `mypy-boto3-lightsail` to add type hints for the Lightsail client and its response types. It includes a `TYPE_CHECKING` guard for runtime compatibility and shows how to retrieve Lightsail distributions with type safety. Remember to have AWS credentials configured for actual execution."},"warnings":[{"fix":"Upgrade your Python environment to version 3.9 or higher.","message":"Python 3.8 support has been removed for `mypy-boto3-builder` (which generates `mypy-boto3-lightsail`) and its generated packages.","severity":"breaking","affected_versions":"mypy-boto3-builder 8.12.0+ and subsequently generated mypy-boto3-* packages."},{"fix":"Review and update `TypeDef` imports and names in your code. For example, `CreateDistributionRequestRequestTypeDef` became `CreateDistributionRequestTypeDef`.","message":"The naming convention for `TypeDef` objects was changed, potentially leading to import or name resolution errors if you explicitly imported them.","severity":"breaking","affected_versions":"mypy-boto3-builder 8.9.0+ and subsequently generated mypy-boto3-* packages."},{"fix":"Ensure `pip install boto3` is part of your project's dependencies.","message":"Installing `mypy-boto3-lightsail` only provides type stubs. The actual `boto3` library is still required at runtime to interact with AWS services.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Assess your type checking needs: use `pip install boto3-stubs[full]` for all services or `pip install 'boto3-stubs[lightsail]'` for service-specific coverage with integrated overloads.","message":"For comprehensive type checking across multiple AWS services, consider installing `boto3-stubs[full]` or specific `boto3-stubs` extras (e.g., `boto3-stubs[lightsail]`) instead of individual `mypy-boto3-*` packages, as `mypy-boto3-lightsail` only covers the Lightsail service.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Implement a runtime fallback: `if TYPE_CHECKING: from mypy_boto3_lightsail.client import LightsailClient else: LightsailClient = object`","message":"When using Pylint with type hints inside `if TYPE_CHECKING:` blocks, Pylint might report `undefined variable` errors at runtime. This is due to Pylint not always correctly interpreting the `TYPE_CHECKING` guard.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}