{"id":3362,"library":"mypy-boto3-greengrass","title":"mypy-boto3-greengrass Type Stubs","description":"mypy-boto3-greengrass provides comprehensive type annotations for the boto3 Greengrass client, service resource, paginators, and waiters. It enables static type checking for AWS Greengrass operations using mypy, enhancing code reliability and developer experience. The library is currently at version 1.42.3, generated with mypy-boto3-builder 8.12.0, and follows the boto3 release cadence for updates.","status":"active","version":"1.42.3","language":"en","source_language":"en","source_url":"https://github.com/youtype/mypy_boto3_builder","tags":["type-stubs","aws","boto3","greengrass","mypy","static-analysis","developer-tools","aws-sdk"],"install":[{"cmd":"pip install boto3 mypy mypy-boto3-greengrass","lang":"bash","label":"Install Boto3, Mypy, and Greengrass Stubs"},{"cmd":"pip install 'boto3-stubs[greengrass]' mypy","lang":"bash","label":"Alternative: Install Boto3 Stubs with Greengrass Extra"}],"dependencies":[{"reason":"Runtime dependency for actual AWS SDK functionality. `mypy-boto3-greengrass` provides only type stubs, not the implementation.","package":"boto3"},{"reason":"Required for static type checking. The stubs are consumed by the Mypy checker.","package":"mypy"},{"reason":"May be required for Python versions < 3.9 to support certain type features, though often handled automatically.","package":"typing-extensions","optional":true}],"imports":[{"note":"Type hint for the Greengrass service client.","symbol":"GreengrassClient","correct":"from mypy_boto3_greengrass.client import GreengrassClient"},{"note":"Type hint for the response dictionary of Greengrass operations. Full list of TypeDefs available in documentation.","symbol":"GetCoreDefinitionResponseTypeDef","correct":"from mypy_boto3_greengrass.type_defs import GetCoreDefinitionResponseTypeDef"},{"note":"Type hint for the Greengrass service resource (if applicable for the service).","symbol":"GreengrassServiceResource","correct":"from mypy_boto3_greengrass.service_resource import GreengrassServiceResource"}],"quickstart":{"code":"import boto3\nimport os\nfrom typing import TYPE_CHECKING, Dict, Any\n\n# Conditional import for type checking only to avoid runtime dependency\n# if mypy-boto3-greengrass is not installed in production environments.\nif TYPE_CHECKING:\n    from mypy_boto3_greengrass.client import GreengrassClient\n    from mypy_boto3_greengrass.type_defs import GetCoreDefinitionResponseTypeDef\n\ndef get_core_definition_name(core_definition_id: str) -> str:\n    \"\"\"\n    Retrieves the name of a Greengrass core definition using type-hinted boto3.\n    Type annotations ensure static analysis correctness.\n    \"\"\"\n    # Initialize boto3 client. mypy-boto3 provides stubs for its methods.\n    client = boto3.client(\"greengrass\", region_name=os.environ.get(\"AWS_REGION\", \"us-east-1\"))\n\n    # Asserting the client type for static analysis with mypy.\n    # At runtime, 'client' is a regular boto3 client.\n    if TYPE_CHECKING:\n        greengrass_client: GreengrassClient = client\n        response: GetCoreDefinitionResponseTypeDef = greengrass_client.get_core_definition(\n            CoreDefinitionId=core_definition_id\n        )\n    else:\n        # Runtime execution uses the actual boto3 client without explicit type assertion.\n        # This branch is taken if TYPE_CHECKING is False (e.g., in production).\n        response = client.get_core_definition(CoreDefinitionId=core_definition_id)\n    \n    # Mypy will now correctly check access to 'Name' and its type\n    return response['Name']\n\nif __name__ == \"__main__\":\n    # For this to make actual AWS calls, ensure AWS_ACCESS_KEY_ID,\n    # AWS_SECRET_ACCESS_KEY (and optionally AWS_REGION) are set in your environment.\n    # Otherwise, it will attempt a call that might fail with an AWS error.\n\n    print(\"Note: This example requires AWS credentials for live execution.\")\n    print(\"   To run 'mypy' on this file, ensure 'mypy boto3 mypy-boto3-greengrass' are installed.\")\n    print(\"   Example: 'mypy your_script_name.py'\")\n\n    example_core_id = \"your-greengrass-core-definition-id\"\n\n    if os.environ.get(\"AWS_ACCESS_KEY_ID\") and os.environ.get(\"AWS_SECRET_ACCESS_KEY\"):\n        print(f\"\\nAttempting to get Greengrass Core Definition name for ID: {example_core_id}\")\n        try:\n            core_name = get_core_definition_name(example_core_id)\n            print(f\"Retrieved Core Definition Name: {core_name}\")\n        except Exception as e:\n            print(f\"An error occurred during AWS call: {e}\")\n            print(\"Please ensure the Core Definition ID is valid and credentials are correct.\")\n    else:\n        print(\"\\nAWS credentials not found. Skipping live AWS call.\")\n        print(\"To test type-checking, you can run 'mypy' on this file without credentials.\")\n","lang":"python","description":"This quickstart demonstrates how to use `mypy-boto3-greengrass` for type hinting your `boto3` Greengrass client. It highlights the use of `TYPE_CHECKING` for conditional imports, ensuring the stubs are only used during static analysis. When `mypy` processes this code, it uses `GreengrassClient` and `GetCoreDefinitionResponseTypeDef` to validate client methods and response structures. At runtime, the standard `boto3` client is used."},"warnings":[{"fix":"Upgrade your Python environment to 3.9 or newer.","message":"Support for Python 3.8 has been removed in `mypy-boto3-builder` version 8.12.0, affecting all generated `mypy-boto3-*` packages, including `mypy-boto3-greengrass`.","severity":"breaking","affected_versions":"mypy-boto3-builder >= 8.12.0, mypy-boto3-greengrass >= 1.42.3"},{"fix":"Review your code for explicit imports or uses of `TypeDef` names and adjust them according to the new conventions.","message":"TypeDef naming conventions changed in `mypy-boto3-builder` 8.9.0. Specifically, packed method arguments use shorter names (e.g., `CreateDistributionRequestRequestTypeDef` -> `CreateDistributionRequestTypeDef`), and conflicting `Extra` postfixes are moved to the end.","severity":"breaking","affected_versions":"mypy-boto3-builder >= 8.9.0, mypy-boto3-greengrass >= 1.42.0 (approx)"},{"fix":"Ensure `pip install boto3` is executed in your environment.","message":"`mypy-boto3-greengrass` provides only type annotations; `boto3` itself is a separate runtime dependency and must be installed alongside these stubs for your application to function.","severity":"gotcha","affected_versions":"All"},{"fix":"Install `mypy` (`pip install mypy`) and integrate it into your CI/CD pipeline or IDE.","message":"To benefit from these type stubs, a static type checker like `mypy` or `pyright` must be installed and configured in your development environment.","severity":"gotcha","affected_versions":"All"},{"fix":"When updating `boto3`, also update `mypy-boto3-greengrass` to a compatible version.","message":"It is generally recommended that the major.minor version of `mypy-boto3-greengrass` matches the major.minor version of your installed `boto3` library for optimal compatibility and accuracy of type hints.","severity":"gotcha","affected_versions":"All"},{"fix":"Wrap type stub imports in `if TYPE_CHECKING:` blocks and, if using `pylint`, add `else` branches assigning `object` to client types.","message":"For production deployments, consider using `if TYPE_CHECKING:` blocks for importing `mypy-boto3-*` modules to avoid adding `mypy-boto3-greengrass` as a runtime dependency. Some linters like `pylint` might complain about undefined variables without additional `else: ClientType = object` blocks.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}